-
-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathgit-conflicts
executable file
·45 lines (41 loc) · 1.01 KB
/
git-conflicts
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
#!/bin/sh
set -e
usage () {
echo "usage: git conflicts [-rqh]" >&2
echo >&2
echo "Compares merge outcomes against all local branches and display " >&2
echo "whether a merge would cause merge conflicts." >&2
echo >&2
echo "Options:" >&2
echo "-r Remote branches (default is only local branches)" >&2
echo "-q Be quiet (only report about conflicts)" >&2
echo "-h Show this help" >&2
}
quiet=0
remotes=0
while getopts rqh flag; do
case "$flag" in
r) remotes=1;;
q) quiet=1;;
h) usage; exit 2;;
esac
done
shift $(($OPTIND - 1))
if git is-dirty; then
echo "Can't check when you have local changes." >&2
exit 2
fi
if [ "$remotes" -eq 1 ]; then
branches="$(git remote-branches)"
else
branches="$(git local-branches)"
fi
for branch in $branches; do
if git merges-cleanly "$branch"; then
if [ $quiet -eq 0 ]; then
echo "$branch... merges cleanly"
fi
else
echo "$branch... CONFLICTS AHEAD"
fi
done