-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-create-merge
executable file
·82 lines (69 loc) · 1.67 KB
/
git-create-merge
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
force_ours="no"
force_theirs="no"
while (( "$#" )); do
if [ "$1" == "-f1" ]; then
force_ours="yes"
elif [ "$1" == "-f2" ]; then
force_theirs="yes"
else
break;
fi
shift
done
if [ "$#" != 2 ]; then
echo
echo "Create a merge commit for current branch"
echo "with current content (staged and commited)"
echo "and specified parents."
echo
echo "Syntax: git-create-merge <ours-parent> <theirs-parent>"
echo
exit 1
fi
ours_sha="$(git rev-parse --verify --quiet $1)"
if [ $? -ne 0 ]
then
echo
echo "ERROR: First argument '$1' is not a known commit"
echo
exit 1
fi
theirs_sha="$(git rev-parse --verify --quiet $2)"
if [ $? -ne 0 ]
then
echo
echo "ERROR: Second argument '$2' is not a known commit"
echo
exit 1
fi
if [ "$ours_sha" = "$theirs_sha" ]; then
echo
echo "ERROR: Arguments '$1' and '$2' are same commit $ours_sha"
echo
exit 1
fi
branch="$(git rev-parse --symbolic-full-name --abbrev-ref HEAD)"
if [ "$branch" = "HEAD" ]; then
echo
echo "ERROR: Detached head"
echo
exit 1
fi
if [ "$force_ours" != "yes" ] && ! git merge-base --is-ancestor $1 $branch; then
echo
echo "ERROR: Proposed first parent '$1' is not reachable from '$branch'"
echo " Override with option -f1"
echo
exit 1
fi
if [ "$force_theirs" != "yes" ] && ! git merge-base --is-ancestor $2 $branch; then
echo
echo "ERROR: Proposed second parent '$2' is not reachable from '$branch'"
echo " Override with option -f2"
echo
exit 1
fi
git reset --soft $ours_sha
git update-ref MERGE_HEAD $theirs_sha
git commit --edit -m "Merge '$2' into '$branch'"