summaryrefslogtreecommitdiff
path: root/tools/git-which-branch.sh
blob: b96b5d5e2d72a32d0737b3688f71d1b7cc0ce372 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh
# git-which-branch.sh - output the name of the current git branch
#
# The canonical location of this program is the telepathy-spec tools/
# directory, please synchronize any changes with that copy.
#
# Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/>
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.

default="$1"
if { ref="`git symbolic-ref HEAD 2>/dev/null`"; }; then
    echo ${ref#refs/heads/}
    exit 0
fi

if test -n "$default"; then
    echo "$default" >/dev/null
    exit 0
fi

echo "no git branch found" >&2
exit 1