-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgit-merge-topics
executable file
·132 lines (113 loc) · 1.91 KB
/
git-merge-topics
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# © Copyright 2014-2023 by Geert Uytterhoeven
#
# This file is subject to the terms and conditions of the GNU General Public
# License.
set -e
STATEDIR=.git-merge-topics
FILE=$STATEDIR/topics
STATE=$STATEDIR/state
function usage()
{
cat <<END
Usage: $(basename $0) [<topicfile>]
END
exit -1
}
case $# in
0)
if [ -d $STATEDIR -a -f $FILE ]; then
read topicfile < $FILE
else
echo No merge in progress
exit -1
fi
;;
1)
case $1 in
-h|--help)
usage
;;
*)
topicfile=$1
;;
esac
;;
*)
usage
;;
esac
i=0
done=0
if [ -d $STATEDIR -a -f $FILE ]; then
rm -f $FILE.tmp
echo $topicfile > $FILE.tmp
if ! cmp $FILE $FILE.tmp > /dev/null; then
echo $(basename $0) $(cat $FILE) still in progress
exit -1
fi
rm $FILE.tmp
if [ -f $STATE ]; then
done=$(cat $STATE)
fi
else
mkdir -p $STATEDIR
echo $topicfile > $FILE
fi
# Merge various topic branches
sed -e 's/\s\s*#.*$//g' < $topicfile | grep -v '^#' | grep -v '^$' | \
while IFS= read line; do
i=$((i + 1))
if [ $done -lt $i ]; then
cmd=${line%% *}
args=${line#* }
case $cmd in
BREAK|BRK)
echo
echo Paused. Remove BREAK to continue.
exit -1
;;
merge)
echo === Merging $args ===
case $args in
*\ *~*)
remote=${args%~*}
suffix=~${args#*~}
git fetch -q $remote
branch=FETCH_HEAD$suffix
;;
*\ *)
git fetch -q $args
branch=FETCH_HEAD
;;
*)
branch=$args
;;
esac
git show -s --oneline $branch
git merge --no-ff --no-edit $branch
;;
pick)
for commit in $args; do
echo === Cherry-picking \"$(git show -s --pretty=%s $commit)\" ===
git cherry-pick $commit
done
;;
revert)
for commit in $args; do
echo === Reverting \"$(git show -s --pretty=%s $commit)\" ===
git revert $commit
done
;;
*)
echo
echo Unknown command $cmd
exit -1
;;
esac
echo $i > $STATE
else
echo Skipping $line
fi
done
rm -rf $STATEDIR