Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docs:git:hooks [2010/12/29 16:40] billhdocs:git:hooks [2011/01/05 16:19] (current) billh
Line 3: Line 3:
  
 ===== build number ===== ===== build number =====
-You might want a distinct number to represent this "build", or commit (even though we don't really have binary builds in languages like php).  We can use a post-commit hook to pull in a subset of the SHA-1 hash.  In this example we use the first 6 characters of the SHA-1.+You might want a distinct number to represent this "build", or commit (even though we don't really have binary builds in languages like php).  We can use a post-commit hook to pull in a subset of the SHA-1 hash.  In this example we use the first 6 characters of the SHA-1, writing out to a file named "BUILD".
 <code sh> <code sh>
 #!/bin/sh #!/bin/sh
-# 
-# An example hook script that is called after a successful 
-# commit is made. 
-# 
-# To enable this hook, rename this file to "post-commit". 
  
 git log|head -n 1|cut -c 8-13 - > BUILD git log|head -n 1|cut -c 8-13 - > BUILD
 </code> </code>
 +
 +:!: Don't forget this gotcha...when you change branches, the build file would keep the commit hash from the last commit.  It is likely that your other branch wouldn't be on the same commit, so we need another hook to update this when we do any checkout.  Copy the same contents of post-commit to a new file called post-checkout.
 +
 +You should also see [[#global hooks]].
  
 ===== pre-commit: store compressed database dump with each commit ===== ===== pre-commit: store compressed database dump with each commit =====
Line 26: Line 25:
 exit $? exit $?
 </code> </code>
 +
 +===== global hooks =====
 +There are several ways to set up hooks so that all projects use the same set of files.  I prefer to symlink a hooks directory.  See [[git on windows]] for examples of using mklink in windows.  Basically we allow git to do its think with git init or git clone, then we delete the .git/hooks directory and replace it with a symlink called hooks which points to our global location.
  
 ===== External Links ===== ===== External Links =====
 * http://www.kernel.org/pub/software/scm/git/docs/githooks.html * http://www.kernel.org/pub/software/scm/git/docs/githooks.html
  • docs/git/hooks.1293666000.txt.gz
  • Last modified: 2010/12/29 16:40
  • by billh