File: git-which-branch.sh

package info (click to toggle)
telepathy-logger-qt 17.09.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 856 kB
  • sloc: python: 3,801; cpp: 2,212; xml: 1,001; sh: 126; makefile: 7
file content (25 lines) | stat: -rw-r--r-- 683 bytes parent folder | download | duplicates (42)
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