new script git-update.sh that also pulls branches
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 25 Apr 2013 09:17:49 +0000 (11:17 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 25 Apr 2013 09:17:49 +0000 (11:17 +0200)
scripts/git-mirror.sh
scripts/git-update.sh [new file with mode: 0755]

index 8761ac1..cb89395 100755 (executable)
@@ -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 (executable)
index 0000000..bd555e3
--- /dev/null
@@ -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