Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 64 lines (56 sloc) 1.681 kB
#!/bin/bash -e
## Check if we're on a remote tracking branch
## read input, display help if necessary
if [[ "$@" == *--help* ]]; then
cat<<EOF
Check for a remote tracking branch
This command checks whether the repository is on a remote tracking
branch. Otherwise an error is raised.
Does not raise an error if the repository is in detached HEAD mode
and there are no new commits.
Usage:
git check-branch
EOF
exit 0;
fi
if ! git symbolic-ref -q HEAD > /dev/null ; then
## detached head cannot be remote tracking branch...
## ...but: if there are no new commits, we can safely ignore this
## FIXME: this test only succeed if the new commit is actually
## checked out
if ! git diff origin... --quiet; then
cat >&2 <<EOF
Error in $PWD:
Detached head and new commits. Attach the HEAD by creating
a new branch or risk losing the commits.
EOF
exit 1
fi
cat >&2 <<EOF
Warning in $PWD:
Detached head. This probably just mean that there are updates available
that are not yet used. To update to the most recent version, use
git checkout <branchname>
To list all branches, use
git branch -a
Alternatively try to use "git attach-head" or "git rpull" to update submodule.
EOF
exit 0
fi
tmp=`git branch --no-color -vv 2> /dev/null`
while read line; do
if [[ "${line:0:1}" != "*" ]]; then
continue
fi
#echo "$line"
remote=`expr "$line" : '.*\[\(.*\)\]'` || nontracking=0
done <<< "$tmp"
activebranch=`git name-rev --name-only HEAD`
if [[ "$nontracking" ]]; then
## if we're here: fail
cat >&2 <<EOF
Error in $PWD:
Branch "$activebranch" is not a remote tracking branch.
EOF
exit 1
fi
Jump to Line
Something went wrong with that request. Please try again.