-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-ref-type
executable file
·66 lines (54 loc) · 1.25 KB
/
git-ref-type
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env sh
# Support bash to support `source` with fallback on $0 if this does not run with bash
# https://stackoverflow.com/a/35006505/6512
selfArg="$BASH_SOURCE"
if [ -z "$selfArg" ]; then
selfArg="$0"
fi
self=$(realpath $selfArg 2> /dev/null)
if [ -z "$self" ]; then
self="$selfArg"
fi
dir=$(cd "${self%[/\\]*}" > /dev/null; cd '../scripts' && pwd)
usage() {
echo -n "${scriptName} [OPTION]... [FILE]...
Returns 'branch' if local working copy is a branch checkout.
Returns 'tag' if a tag is checked out.
"
}
BRANCH=`git symbolic-ref --quiet --short HEAD 2> /dev/null`
TAG=`git describe --tags --exact-match 2> /dev/null`
# Set up options for --type and --help.
while [ $# -gt 0 ]; do
case "$1" in
-t|--type)
if [[ -n $BRANCH ]]; then
echo "branch"
elif [[ -n $TAG ]]; then
echo "tag"
else
exit 1
fi
exit 0
;;
-h|--help) usage >&2; exit 0;;
*)
echo "Invalid option: $1"
exit 1
esac
shift
done
# Print the branch or tag name
if [ -n "$BRANCH" ]; then
echo 'branch'
elif [ -n "$TAG" ]; then
echo 'tag'
else
git remote -v > /dev/null 2>&1
retVal=$?
if [ $retVal -ne 0 ]; then
echo "Not a git repo"
exit 1
fi
echo 'sha'
fi