Tuesday, September 06, 2005

Commit from a build file

Subversion comes standard with a command line client that can be used to commit changes. The usual sequence is add new files & remove deleted files, update from the repository, run the build file, and then commit to the repository. This sequence should be followed on every commit, and should be automated.

I've previously shown how easy it is to add & remove with Ruby. Update and commit can be executed in Ruby by `svn up` and `svn commit*` respectively.

All of these commands could be written into a rake build file as tasks. Each task would have pre-requisite tasks and execution will stop if any pre-requisite task fails. Rake supports this with it's dependency model. Expressing dependency in rake is easy.

task TaskName => [:pre-req1, :pre-req2, ...]

Therefore, the dependencies in our build file would look something like this:

task commit => [:test, :update]
task test => [:compile]
task update => [:add, :remove]


Compile, add & remove don't have any dependencies in our example, and are not shown.

The dependency model ensures a commit will not be executed unless all the pre-requisite tasks had been executed. Developers would be abstracted from this and could commit their changes by simply executing "rake commit" from the command line.

* Be sure to set the EDITOR environment variable. When the EDITOR variable is set any commit (without a message or file specified) will cause an editor window to open for you to enter a commit message.

1 comment:

  1. Anonymous9:11 PM

    Hah! Talk about co-incidence - I'd just made a similar comment on the XP mailing list:

    http://groups.yahoo.com/group/extremeprogramming/message/111887

    ReplyDelete

Note: Only a member of this blog may post a comment.