3 # uses the directory where the command lies, so just symlink this script wherever it's needed
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
11 COMMAND=$(basename $0)
12 # without an argument, use the place where the command is stored
13 if [[ -z "$@" ]] ; then
15 DIRNAME=$(cd $DIRNAME; pwd -P)
23 ### xxx ideally we should not need to git checkout anything
24 # which would in addition remove the need for a non-bare repo
25 # this would take a bit more time though
27 # make sure we keep track of the current branch upon exit
28 function current_branch () {
29 git branch | grep '^\*' | cut -d' ' -f2
32 function all_branches () {
34 git branch -r | grep $remote | fgrep -v -- '->' | sed "s/.*\///g"
38 function git_update () {
39 current_branch=$(current_branch)
42 for branch in $(all_branches $remote); do
43 # create the branch as a tracking branch if not yet existing
44 git branch | grep -q ' '$branch'$' || git branch --track $branch $remote/$branch
46 git merge --ff $remote/$branch
48 git checkout $current_branch
51 git_update >& .git-update.log