-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgit-in-repo
executable file
·67 lines (57 loc) · 932 Bytes
/
git-in-repo
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
66
67
#!/usr/bin/env bash
app_name="$(basename "${BASH_SOURCE[0]}")"
print_help() {
expand -t 4 << EOF
Usage:
$app_name
Returns 0 if current working directory is a Git repository, non-zero otherwise.
Options:
-q, --quiet
Suppress output.
-s, --silent
Silence git stderr.
-?, --help
Show this help information and exit.
EOF
}
quiet=0
silent=0
while [[ $# -gt 0 ]]; do
case "$1" in
-q|--quiet)
quiet=1
shift
;;
-s|--silent)
silent=1
shift
;;
-\?|--help)
print_help
exit 0
;;
-*)
echo "$app_name: [Error] Unknown option: $1" >&2
exit 1
;;
*)
echo "$app_name: [Error] Unexpected argument: $1" >&2
exit 1
;;
esac
done
if [[ silent -eq 0 ]]; then
git rev-parse --git-dir > /dev/null
success=$?
else
git rev-parse --git-dir &> /dev/null
success=$?
fi
if [[ quiet -eq 0 ]]; then
if [[ success -eq 0 ]];then
echo "yes"
else
echo "no"
fi
fi
exit "$success"