[PATCH] Exit with status code 2 if we get an exception.
[git/git-svn.git] / git-branch.sh
blob81b9e6cce138452ab50c1dee869b82a9f6706d34
1 #!/bin/sh
3 . git-sh-setup || die "Not a git archive"
5 usage () {
6 echo >&2 "usage: $(basename $0)"' [<branchname> [start-point]]
8 If no arguments, show available branches and mark current branch with a star.
9 If one argument, create a new branch <branchname> based off of current HEAD.
10 If two arguments, create a new branch <branchname> based off of <start-point>.
12 exit 1
15 case "$#" in
17 headref=$(readlink "$GIT_DIR/HEAD" | sed -e 's|^refs/heads/||')
18 git-rev-parse --symbolic --all |
19 sed -ne 's|^refs/heads/||p' |
20 sort |
21 while read ref
23 if test "$headref" = "$ref"
24 then
25 pfx='*'
26 else
27 pfx=' '
29 echo "$pfx $ref"
30 done
31 exit 0 ;;
33 head=HEAD ;;
35 head="$2^0" ;;
36 esac
37 branchname="$1"
39 case "$branchname" in
40 -*)
41 usage;;
42 esac
44 rev=$(git-rev-parse --verify "$head") || exit
46 [ -e "$GIT_DIR/refs/heads/$branchname" ] && die "$branchname already exists"
48 echo $rev > "$GIT_DIR/refs/heads/$branchname"