-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from softins/checkout-hook
Improve post-checkout hook and README
- Loading branch information
Showing
2 changed files
with
35 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |