new script git-update.sh that also pulls branches
[infrastructure.git] / scripts / git-update.sh
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