tags:

views:

37

answers:

1

We have migrated from CVS to Git. Our Hudson build script used to save the value of the CVS_BRANCH environment variable in the generated build along with the Hudson BUILD_ID to allow for later investigation.

I cannot figure out how Hudson (or the Git plugin) presents the Git SHA1 name of the current commit to the ant script, as I cannot locate any definite source saying where I should look.

I'd prefer not to invoke git to get it if it is present in the environment, but can do if that is necessary.

What have I missed?

+1  A: 

Well, if you really want to avoid calling git command (git describe or git rev-parse), then you can do the following:

  1. Look up $GIT_DIR/HEAD file. If it is symbolic link, its target is fully qualified name of current branch (e.g. 'refs/heads/master' if current branch is 'master'); shouldn't happen except in very old repositories managed by very old git.

    If it is ordinary file, it is either of the form ref: refs/heads/<branch> (so called symref), or it contains SHA-1 id of current commit (so called "detached HEAD" aka. anonymous branch: '(no branch)' in git branch output.

  2. Current commit is either in $GIT_DIR/refs/head/branch file, or it can be found in the $GIT_DIR/packed-refs file. If both exist, then loose ref (in a seperate file named after fully qualified branch name) wins.

But I am not sure if it is worth it.

Jakub Narębski