From 8481e3c8b6f6776f08bece291044e478a530f5ae Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 25 Apr 2013 11:17:49 +0200 Subject: [PATCH] new script git-update.sh that also pulls branches --- scripts/git-mirror.sh | 5 ++++- scripts/git-update.sh | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 scripts/git-update.sh diff --git a/scripts/git-mirror.sh b/scripts/git-mirror.sh index 8761ac1..cb89395 100755 --- a/scripts/git-mirror.sh +++ b/scripts/git-mirror.sh @@ -145,7 +145,10 @@ function mirror_repo () { MASTER_REPO=${MASTER_GIT}/${GIT_NAME} # if the local master is a symlink (like /git/vserver-reference.git -> sliceref.git) - # then skip it, the target itself will be handled if in scope + # then skip it + # we use this for either aliases (like vserver-reference and sliceimage) or + # for repos managed in other locations (like /git-slave) but where + # the symlink is needed so they get served by git-daemon [ -h ${MASTER_REPO} ] && return # if there is no remote repository it may be that we only have diff --git a/scripts/git-update.sh b/scripts/git-update.sh new file mode 100755 index 0000000..bd555e3 --- /dev/null +++ b/scripts/git-update.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# +# uses the directory where the command lies, so just symlink this script wherever it's needed +# +# based on auto-update that historically was guessing the scm in use +# this one is git-specific, it does the usual git pull +# but also exposes all remote branches as local +# + +#################### +COMMAND=$(basename $0) +# without an argument, use the place where the command is stored +if [[ -z "$@" ]] ; then + DIRNAME=$(dirname $0) + DIRNAME=$(cd $DIRNAME; pwd -P) +else + DIRNAME="$1" ; shift +fi + +########## +cd $DIRNAME + +function all_branches () { + remote=$1; shift + git branch -r | grep $remote | fgrep -v -- '->' | sed "s/.*\///g" +} + + +function git_update () { + echo Running $COMMAND + remote=origin + for branch in $(all_branches $remote); do + # create the branch as a tracking branch if not yet existing + git branch | grep -q ' '$branch'$' || git branch --track $branch $remote/$branch + git checkout $branch + git merge --ff $remote/$branch +} + +git_update >& .git-update.log -- 2.43.0