git: Add a post-update hook for new repositories.
[matthijs/servers/drsnuggles.git] / usr / local / bin / git-wrapper
index cd8f7c1d4a11cc2ede3ddd724b7cbfab261a08b9..6896ec8904e6dfe0677522564effdbb36a1868c7 100755 (executable)
@@ -9,6 +9,13 @@
 # --base-path-relaxed. 
 
 BASE_PATH='/data/vcs/git'
+POST_UPDATE_HOOK="$BASE_PATH/hooks/post-update"
+
+function init_repos() {
+       mkdir "$1" &> /dev/null  || return 1 
+       (cd $1 && git --bare init &> /dev/null) || return 1
+       cp -P "$POST_UPDATE_HOOK" "$1/hooks/" || return 1
+}
 
 # We keep an array of arguments, so we can handle quoting an spaces in
 # arguments properly.
@@ -27,9 +34,10 @@ do
                        DIR="$BASE_PATH/$DIR"
                fi
        
-               # Create the git repository if it does not exist yet    
-               if [ ! -e "$DIR" ]; then
-                       mkdir "$DIR" &> /dev/null && (cd $DIR && git --bare init &> /dev/null)
+               # When the client wants us to receive a pack, create the git
+               # repository if it does not exist yet   
+               if [ "`basename $0`" = "git-receive-pack" -a ! -e "$DIR" ]; then
+                       init_repos "$DIR"
                fi
                ARGS[$i]="$DIR"
        else