git: Make git-wrapper copy post-receive as well.
[matthijs/servers/drsnuggles.git] / usr / local / bin / git-wrapper
index cd8f7c1d4a11cc2ede3ddd724b7cbfab261a08b9..e79896549d843768298bd65a591a5f6d39baedcc 100755 (executable)
@@ -9,6 +9,16 @@
 # --base-path-relaxed. 
 
 BASE_PATH='/data/vcs/git'
+HOOKS_PATH="$BASE_PATH/hooks"
+HOOKS="post-update post-receive"
+
+function init_repos() {
+       mkdir "$1" &> /dev/null  || return 1 
+       (cd $1 && git --bare init &> /dev/null) || return 1
+       for hook in $HOOKS; do
+           ln -s "$HOOKS_PATH/$hook" "$1/hooks/" || return 1
+       done
+}
 
 # We keep an array of arguments, so we can handle quoting an spaces in
 # arguments properly.
@@ -27,9 +37,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" || exit 1
                fi
                ARGS[$i]="$DIR"
        else