forked from nvie/git-toolbelt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-merges-cleanly
executable file
·53 lines (44 loc) · 1001 Bytes
/
git-merges-cleanly
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
#!/bin/sh
set -e
usage () {
echo "usage: git merges-cleanly [-vh] <branch>" >&2
echo >&2
echo "Performes a temporal merge against the given branch (but aborts or undoes" >&2
echo "the merge) and reports success or failure through the exit code." >&2
echo >&2
echo "Options:" >&2
echo "-h Show this help" >&2
echo "-l List conflicting files" >&2
}
showlist=0
while getopts lh flag; do
case "$flag" in
h) usage; exit 2;;
l) showlist=1;;
esac
done
shift $(($OPTIND - 1))
if [ $# -ne 1 ]; then
usage
exit 2
fi
branch=$1
git sha -q "$1"
if git is-dirty; then
echo "Can't check when you have local changes." >&2
exit 2
fi
if git merge --quiet "$branch" >/dev/null 2>/dev/null; then
git undo-merge >/dev/null 2>/dev/null
exit 0
else
if [ $showlist -eq 1 ]; then
git diff --name-only --diff-filter=U
fi
git merge --abort >/dev/null 2>/dev/null
if [ $showlist -eq 1 ]; then
exit 0
else
exit 1
fi
fi