Skip to content

Commit

Permalink
Merge pull request #193 from softins/checkout-hook
Browse files Browse the repository at this point in the history
Improve post-checkout hook and README
  • Loading branch information
lasconic committed Jan 30, 2013
2 parents a92b31d + 2f0aec7 commit 4d17135
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
36 changes: 29 additions & 7 deletions build/git/hooks/README
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
Copy the post-checkout file from build/git/hooks/ into .git/hooks/ in order
for git to update mscore/revision.h with the branch number automatically when
checking out:
Handling of mscore/revision.h
-----------------------------

$ cp -p build/git/hooks/post-checkout .git/hooks/
The copy of mscore/revision.h in the git repository is just a default, to
prevent build failures from a freshly cloned or checked-out repo. It contains
the string "Unknown" instead of a build number.

It is always possible to update mscore/revision.h with the build number
of the current checked-out branch by doing "make revision". However, the
updated mscore/revision.h should never be commited back to git. This can
be prevented manually by restoring the original value before committing,
with "git checkout -- mscore/revision.h"

But there is an easier way to achieve all this automatically...

The post-checkout script in this directory should be installed as a hook in
git, and will update mscore/revision.h with the branch number automatically
when checking out a new branch.

The hook also does "git update-index --assume-unchanged mscore/revision.h",
so that git does not expect the updated mscore/revision.h file to be staged
or committed. It also stops it from showing up in "git diff" or "git status".

This only needs doing once, and then removes the need to do "make revision"
manually for setting the correct revision number after doing a checkout.
To install the hook from this directory, do:

$ cp -p post-checkout ../../../.git/hooks/

Alternatively from the top-level directory, do:

$ cp -p build/git/hooks/post-checkout .git/hooks/

This works for Linux, Windows (MinGW) and OSX.
This only needs doing once, and works for Linux, Windows (MinGW) and OSX.
7 changes: 6 additions & 1 deletion build/git/hooks/post-checkout
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
#!/bin/sh
git rev-parse --short HEAD >mscore/revision.h
# only do this for branch-level checkouts
case $3 in
1) git update-index --assume-unchanged mscore/revision.h
git rev-parse --short HEAD >mscore/revision.h
;;
esac

0 comments on commit 4d17135

Please sign in to comment.