-
Notifications
You must be signed in to change notification settings - Fork 5
/
git-case-merge
executable file
·52 lines (41 loc) · 1.47 KB
/
git-case-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
#!/bin/bash
#
# Assumptions:
# - in a git repository
# - we can access git-case-common
# - the branch defined by GIT_CASE_HEAD exists (see git-case-common)
source $(dirname $0)/git-case-common
DEFAULT="origin/$GIT_CASE_HEAD"
RBRANCH="${1:-$DEFAULT}"
while test -n "$1" ; do
OPT="$1" ; shift
case "$OPT" in
-h|--help)
die "$PROGRAM [<remote>]"
;;
esac
done
REMOTE_HEAD=$(git rev-parse --revs-only "${RBRANCH}")
test -z "$REMOTE_HEAD" && "cannot determine sha1 of $RBRANCH"
if test -z "$(git rev-parse --revs-only ${GIT_CASE_HEAD})" ; then
echo "Creating local branch ${GIT_CASE_HEAD} based on ${RBRANCH}"
git-update-ref "refs/heads/$GIT_CASE_HEAD" "$REMOTE_HEAD"
exit 0
fi
CURRENT_HEAD=$(git rev-parse --revs-only "${GIT_CASE_HEAD}")
test -z "$CURRENT_HEAD" && "cannot determine sha1 of $GIT_CASE_HEAD"
# we work in the working dir
go_to_git_case_work_dir
BASE=$(git-merge-base ${CURRENT_HEAD} ${REMOTE_HEAD})
if test $BASE = $REMOTE_HEAD ; then
echo "Already upto date."
exit 0
elif test $BASE = $CURRENT_HEAD ; then
echo "Performing fast-forward."
git-update-ref "refs/heads/$GIT_CASE_HEAD" "$REMOTE_HEAD" "$CURRENT_HEAD"
else
echo "Merging."
# for now we will only do aggressive merges
git read-tree -m -i --aggressive "$BASE" "$GIT_CASE_HEAD" "$RBRANCH"
commit_index_and_update_branch "merged with $RBRANCH" "-p $GIT_CASE_HEAD -p $RBRANCH"
fi