Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f96fd12efb
Fetching contributors…

Cannot retrieve contributors at this time

executable file 53 lines (46 sloc) 1.53 kb
#!/bin/bash -e
## Attaches HEAD if commit and top of branch are identical anyway
## Fast forwards local branch if HEAD matches top of remote branch.
## If argument -w is given: warn if HEAD cannot be attached
## prefer master over other branches
## TODO: do some error checking?
## stop if HEAD is a ref already
if [[ $(cat .git/HEAD | cut -c1-4) == "ref:" ]]; then
exit 0
fi
## get arguments
while getopts ":w" opt; do
case $opt in
w)
w=1
#echo "-f was triggered!" >&2
;;
\?)
# ignore this
#echo "Invalid option: -$OPTARG" >&2
;;
esac
done
HEAD=`git rev-parse HEAD`
## get first refs for master (prefer master)
branch=`git show-ref master | grep $HEAD | sed 's/.*refs\///' | sed -e '2,$ d'`
if [[ ! "$branch" ]]; then
## ok, allow all refs but HEAD and tags/*, get first match
branch=`git show-ref | grep $HEAD | sed -e 's/.*refs\///' -e '/HEAD/ d' -e '/tags\// d' | sed -e '2,$ d'`
fi
if [[ ! "$branch" ]]; then
if [[ "$w" ]]; then
echo "Warning in $PWD:"
echo " Cannot attach HEAD. There are probably unmerged updates available. Go (\"cd\") there and use \"git brach -v\" list available branches. Switch branches with \"git checkout <branchname>\"."
fi
else
## try to attach head now
branch=${branch#heads/}
echo "Attaching $PWD to $branch..."
lbranch=${branch#remotes/*/}
git checkout --quiet "$lbranch" > /dev/null
if [ "$branch" != "$lbranch" ]; then
echo "Fast forwarding local branch"
git merge --quiet --ff-only $HEAD
fi
fi
Jump to Line
Something went wrong with that request. Please try again.