-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-mergeable
More file actions
executable file
·57 lines (46 loc) · 1.35 KB
/
git-mergeable
File metadata and controls
executable file
·57 lines (46 loc) · 1.35 KB
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
#!/bin/bash -e
# Prints appropriate usage
display_usage()
{
echo "Usage: $0 [-h | --help] [-v | --verbose] BRANCH_TO BRANCH_FROM"
HELP_TEXT="Runs git merge-base --is-ancestor to determine if BRANCH_TO can "
HELP_TEXT+="be fast-forwarded onto BRANCH_FROM."
echo "${HELP_TEXT}" | fold -s
echo " BRANCH_TO Merging to this branch"
echo " BRANCH_FROM Merging from this branch"
echo " -h | --help Displays this help text"
}
BRANCH_TO=
BRANCH_FROM=
POSITIONAL_ARG_COUNT=0
while [ -n "${1}" ]; do
case "${1}" in
-h | --help)
display_usage
exit 0
;;
*)
# These are the positional arguments so we have to count.
POSITIONAL_ARG_COUNT=$((POSITIONAL_ARG_COUNT + 1))
case "${POSITIONAL_ARG_COUNT}" in
1)
BRANCH_TO="${1}"
;;
2)
BRANCH_FROM="${1}"
;;
*)
echo "Too many positional arguments" 2>&1
exit 1
;;
esac
;;
esac
# We're done with the current argument, move to the next.
shift
done
# Actually do the check
if ! git merge-base --is-ancestor "${BRANCH_TO}" "${BRANCH_FROM}"; then
echo "Not an ancestor"
exit 1
fi