From 4dbbab333c0247da1b955e99e38cea36ea4e4984 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 25 Apr 2013 17:37:30 +0200 Subject: [PATCH] git-update restore current branch git-mirror does not expect git-update to be a symlink as this seems to confuse git a lot --- scripts/git-mirror.sh | 9 +++------ scripts/git-update.sh | 11 +++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/scripts/git-mirror.sh b/scripts/git-mirror.sh index 6a06913..6654727 100755 --- a/scripts/git-mirror.sh +++ b/scripts/git-mirror.sh @@ -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 } diff --git a/scripts/git-update.sh b/scripts/git-update.sh index 93b8ffd..dc04653 100755 --- a/scripts/git-update.sh +++ b/scripts/git-update.sh @@ -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 -- 2.47.0