git-update restore current branch
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 25 Apr 2013 15:37:30 +0000 (17:37 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 25 Apr 2013 15:37:30 +0000 (17:37 +0200)
git-mirror does not expect git-update to be a symlink as this seems to confuse git a lot

scripts/git-mirror.sh
scripts/git-update.sh

index 6a06913..6654727 100755 (executable)
@@ -209,8 +209,8 @@ function mirror_repo () {
 # of some repositories
 # instead of hacking this script that is already scary, I preferred to write
 # a separate script git-update.sh that runs a bit like auto-update.sh
-# and that additionally takes care of remote branches
-# the layout is as follows
+# and that also takes care of remote branches
+# so the overall the layout is as follows
 # * manually created the local mirror by running
 #   cd /git-slave
 #   git clone ssh://tophat@git.top-hat.info/tophat.git
@@ -218,15 +218,12 @@ function mirror_repo () {
 # * create a symlink for git-daemon
 #   cd /git
 #   ln -s /git-slave/tophat/.git tophat.git
-# * enable updates by just dropping a symlink there
-#   cd /git-slave/tophat
-#   ln -s /root/infrastructure/scripts/git-udate.sh 
 
 function slave_repo () {
     git_slave=$1; shift
     cd $git_slave
     for subdir in *; do
-       [ -x $subdir/git-update.sh ] && $subdir/git-update.sh
+       [ -d $subdir/.git ] && git-update.sh $subdir
     done
 }
 
index 93b8ffd..dc04653 100755 (executable)
@@ -20,6 +20,15 @@ fi
 ##########
 cd $DIRNAME
 
+### xxx ideally we should not need to git checkout anything
+# which would in addition remove the need for a non-bare repo
+# this would take a bit more time though
+
+# make sure we keep track of the current branch upon exit
+function current_branch () {
+    git branch | grep '^\*' | cut -d' ' -f2
+}
+
 function all_branches () {
     remote=$1; shift
     git branch -r | grep $remote | fgrep -v -- '->' | sed "s/.*\///g"
@@ -27,6 +36,7 @@ function all_branches () {
     
 
 function git_update () {
+    current_branch=$(current_branch)
     echo Running $COMMAND
     remote=origin
     for branch in $(all_branches $remote); do
@@ -35,6 +45,7 @@ function git_update () {
        git checkout $branch
        git merge --ff $remote/$branch
     done
+    git checkout $current_branch
 }
 
 git_update >& .git-update.log