The smallest git tutorial you’ll ever need

Let me preface with this: this is over-simplified for someone just getting started with git, who does not have the time to learn all the intricacies of git, and covers the most common workflow I’ve encountered, that is:
– download code from a remote repository
– make changes
– commit and send the changes back
– get the latest from that remote repository

So, here goes:

First you’ll need to install git is it is not aleady installed.

Checkout a project

git clone http://github.com/psq/spider.git

Commit

Edit files as you see fit, then when time comes to commit your changes back in:

git status

will show you what files you’ve modified. Or added. If you added any files, add them to the files controlled by git (this also works with a new directory and will recursively add everything)

git add README.txt

Then commit all

git commit -a -m "added readme"

-m option adds a messages, -a adds all modified files to the commit

Upload your changes

Then push your changes back to the original repo

git push origin master

Download the latest version

And finally, to get any updates from the master repo (you may need to do this before doing the push above)

git pull origin master

This is overly simplified on purpose, but will give any beginner time to dive in deeper when time permits.

See this previous post for some helpful git shortcuts

Multiple targets with iscisitarget (ubuntu 9.04)

After trying for a (long) while to have multiple targets defined on the same host, and having my initiator to see both, the solution what in fact simple: Use different values for the LUN!

Here’s a snippet of /etc/ietd.conf

Target iqn.2010-01.com.test:storage.disk1.sys1.000
        Lun 0 Path=/media/usb/test0.img,Type=fileio,IOMode=rw
Target iqn.2010-01. com.test:storage.disk1.sys1.001
        Lun 1 Path=/home/psq/test1.img,Type=fileio,IOMode=rw

Then don’t forget to restart: “service iscsitarget restart”

rebuild the journal on an ext3 partition for CentOS 5.3

Heltech does not have it quite right for centos. The options are named slightly differently on newer versions.

Here’s the correct sequence for CentOS 5.3

  • Boot in single mode
  • umount the main partition
  • check the partition for errors
  • remove the journal
  • remount
  • recreate the journal
  • for good measure, check the partition for errors

or, in other words:

# fsck /dev/VolGroup00/LogVol00
# umount /dev/VolGroup00/LogVol00
# tune2fs -O ^has_journal /dev/VolGroup00/LogVol00
# mount -n -o remount,rw /dev/VolGroup00/LogVol00
# tune2fs -j /dev/VolGroup00/LogVol00
# umount /dev/VolGroup00/LogVol00
# fsck -f /dev/VolGroup00/LogVol00

Note: this should also work on CentOS 5.4

global git shortcuts

Here’s my ~/.gitconfig file for convenient shortcuts. This way, you can use “git st” instead of “git status”…

[user]
name = Pascal
[color]
status = auto
diff = auto
branch = auto
[alias]
st = status
ci = commit
co = checkout
[merge]
tool = opendiff

in git | 38 Words

closing comments

The spammers won (well not really), after getting tired of deleting spam en masse (by the thousands every other months or so), I decided to close comments on some older posts that happen to have a better page rank than most. If you really need to get to me, please feel free to use the Contact me page

Even though I’ve been considering this for a while, this was in part prompted by Jesper of Just add water

His comment policy is simple:

In the future we will probably mark all of the above comment types as spam. Yes, some of the comments actually add value, but most of the comments actually are just made to improve ranking.

We will continue to manually approve the comments we mean will add value.

We will continue to hold comments for manual moderation. (so if your valid comment does not show up within a few hours, please contact us).

Actually, mine is even simpler.

– you must pass the Akismet test.

– you must pass my own test: I review anything Akismet approves and will delete anything that looks, sounds or smells like spam. So even if your comment gets approved initially, I reserve the right to remove it. If that sounds arbitrary, so be it. Although I believe I have been quite fair in the past and will continue to be.

Disagree? Send me your feedback

Unrelated note: Did you check out Twitter Essentials ?

in News | 243 Words

merb 1.0

merb has reached 1.0. What a tremendous achievement from all all contributors, and Ezra more specifically and Wycats

If you can’t wait, use

 gem install merb --source http://edge.merbivore.com

Should be available by tomorrow on your regular gem mirror

gem install merb

Cheers!

Index your DataMapper Models with Xapian

Still pretty preliminary, but the basics seem to work. dm-xapian is a Merb plugin to index your DataMapper models with Xapian

At this point the details are still sketchy, and you first need to install xapian, then the xapian ruby bindings: Install Xapian and ruby bindings

Then it gets easier:

* build the gem with
rake install
* add the dependency
dependencies "dm-xapian"
* create the dm-xapian resource
rake dm:autoupgrade
* tell dm-xapian to index your models (Er, Resources) with something like:

is_indexed :texts => [ :name, :region, :country, :varietal ],
:values => [[:price, 0, "price", :float], [:ean, 1, "ean", :string]],
:terms => [ [ :winery, 'W', "winery" ] ]

* build the index with
rake xapian:rebuild_index models="Wine Winery"
* build the index with
rake xapian:update_index models="Wine Winery"
This will remove from the index any model destroyed or update any model since the last call to xapian:rebuild_index or xapian:update_index
* Run a query
rake xapian:query query="edited 6" models="Wine Winery" verbose=true limit=25

Of course, running a query via rake is not so useful, but that’s all I tried so far. But at least this proved that the index was built correctly, and integrated search to an app is next.

As you may have noticed already, a big thing lacking at this point are specs.

This is in collaboration with Joshaven and based on the awesome work by Francis Irving on act_as_xapian who created the Rails+ActiveRecord version.

EAN UPC Support

EAN/UPC/GTIN calculations for Ruby

To install the Ruby Gem

sudo gem install ean

What can it do?

– Validate UPC/EAN/GTIN identifiers

– Generate check number for UPC/EAN/GTIN identifiers

How to use

Load the gem:

require "rubygems"
require "ean"

Convert to a 14 digit GTIN:
"1234567890128".to_gtin

Check whether a number is a valid 8, 12, 13, 14 EAN/UPC/GTIN number

"1-234567-890128".ean?

You can also do

"1234567890128".to_gtin.ean?

Given a 7, 11, 12, of 13 digits number, generates the check digit (to be added at the end.

"784794001602".generate_check_digit

ANN: rails-undo-redo

To this day, very few web apps provide any undo/redo capabilities. This is really not such a good thing for usability. There are a few exceptions like gmail, but it does not go far enough to provide what every one is used on their desktop.

Ever since I read Assaf’s post on the subject, and left hungry for more, as Assaf only helps you on the UI side and leaves you all the heavy lifting, I have been thinking that there must be a way to make it a lot easier to implement undo/redo in a consistent manner, and in a way that is as easy as rails has gotten us used to.

After a few failed attempts, and building on the work of Brian Durand and his Acts As Revisionable and ActsAsTrashable plugins, that I’ve reused (and probably abused as well), I have come to realize a few (obvious?) things, namely that:

for Undo/Redo to work, it needs to

  • Work across all models
  • Capture the list of changed objects (UndoRecords)
  • Group these UndoRecords per User Action (UndoActions)

Then undo and redo are just a simple matter of replaying the UndoRecords in the right order.

All my previous attempts, and most other plugins I got inspiration from focused on one model, and even though you need this as a building block, for any real application, you need to be able to undo changes across multiple models (even beyond belongs_to, has_many type changes).

When you look at the types of changes to a model in details, you really have 3 types of changes Create, Update and Destroy (these are the C-U-D in CRUD, even if you are not doing REST), and undoing each one requires special handling, so this is also tracked and managed by UndoRecord.

To make a long story short, I’ve packaged all these ideas into a new Rails plugin: Rails Undo Redo (and very soon a gem as well, because this can help, and that’s also easy, or very easy), you can now easily transform any Rails Application using Active Record into a full fledged multi level undo/redo application like most desktop application.

For a full how-to, read the Rails Undo Redo project page, or try the Rails Undo Redo demo.

git, submodules and Capistrano

If you use git submodules, as git-rails does, and want to use Capistano, you’ll need to patch patch Capistrano (lib/capistano/recipes/deploy/scm/git.rb) to make sure your submodules get included.

        def checkout(revision, destination)
          git      = command

          branch   = head

          fail "No branch specified, use for example 'set :branch, \"origin/master\"' in your deploy.rb" unless branch

          if depth = configuration[:git_shallow_clone]
            execute  = "#{git} clone --depth #{depth} #{configuration[:repository]} #{destination} && "
          else
            execute  = "#{git} clone #{configuration[:repository]} #{destination} && "
          end

          execute += "cd #{destination} && #{git} checkout -b deploy #{branch}"

          if submodules = configuration[:git_enable_submodules]
            execute += " && git-submodule init &&"
            execute += "git-submodule update"
          end

          execute
        end

then define this in your deploy.rb:

set :git_enable_submodules,1

Or you can use the trunk version (post 2.1), which includes that support already.