-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-merge-status
49 lines (42 loc) · 886 Bytes
/
git-merge-status
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
#!/bin/sh
set -eu
usage () {
echo "usage: git merge-status [-h] [<branch>]" >&2
echo >&2
echo "Shows merge status of all local branches against branch (defaults to" >&2
echo "the main branch)." >&2
echo >&2
echo "Options:" >&2
echo "-h Show this help" >&2
}
while getopts h flag; do
case "$flag" in
h) usage; exit 2;;
esac
done
shift $(($OPTIND - 1))
bulletize () {
sed -Ee 's/^/ - &/'
}
fail_if_empty () {
empty=1
while read line; do
echo "$line"
empty=0
done
test $empty -eq 0
}
if [ $# -gt 0 ]; then
base="$1"
else
base="$(git main-branch)"
fi
echo "Merged into $base:"
if ! git merged "$base" | bulletize | fail_if_empty; then
echo "(no branches)"
fi
echo
echo "Not merged into $base:"
if ! git merged -u "$base" | bulletize | fail_if_empty; then
echo "(no branches)"
fi