oops
[infrastructure.git] / scripts / git-update.sh
1 #!/bin/bash
2
3 # uses the directory where the command lies, so just symlink this script wherever it's needed
4 #
5 # based on auto-update that historically was guessing the scm in use
6 # this one is git-specific, it does the usual git pull 
7 # but also exposes all remote branches as local
8
9
10 ####################
11 COMMAND=$(basename $0)
12 # without an argument, use the place where the command is stored
13 if [[ -z "$@" ]] ; then
14     DIRNAME=$(dirname $0)
15     DIRNAME=$(cd $DIRNAME; pwd -P)
16 else
17     DIRNAME="$1" ; shift
18 fi
19
20 ##########
21 cd $DIRNAME
22
23 function all_branches () {
24     remote=$1; shift
25     git branch -r | grep $remote | fgrep -v -- '->' | sed "s/.*\///g"
26 }
27     
28
29 function git_update () {
30     echo Running $COMMAND
31     remote=origin
32     for branch in $(all_branches $remote); do
33         # create the branch as a tracking branch if not yet existing
34         git branch | grep -q ' '$branch'$' || git branch --track $branch $remote/$branch
35         git checkout $branch
36         git merge --ff $remote/$branch
37     done
38 }
39
40 git_update >& .git-update.log