3
3
set -eou pipefail
4
4
5
5
help () {
6
- echo " $0 range [end]"
7
- echo " merges every merge commit present in upstream and missing locally ."
6
+ echo " $0 [-b <branch>] range [end]"
7
+ echo " merges every merge commit present in upstream and missing in <branch> (default: master) ."
8
8
echo " If the optional [end] commit is provided, only merges up to [end]."
9
+ echo " If the optional [-b branch] provided, then ."
9
10
echo
10
- echo " $0 select <commit> ... <commit>"
11
- echo " merges every selected merge commit"
11
+ echo " $0 [-b <branch>] select <commit> ... <commit>"
12
+ echo " merges every selected merge commit into <branch> (default: master) "
12
13
echo
13
14
echo " This tool creates a branch and a script that can be executed to create the"
14
15
echo " PR automatically. The script requires the github-cli tool (aka gh)."
@@ -17,12 +18,9 @@ help() {
17
18
exit 1
18
19
}
19
20
20
- if [ " $# " -lt 1 ]; then
21
- help
22
- fi
23
-
24
21
REMOTE=upstream
25
22
REMOTE_BRANCH=" $REMOTE /master"
23
+ LOCAL_BRANCH=" master"
26
24
# Makes sure you have a remote "upstream" that is up-to-date
27
25
setup () {
28
26
ret=0
@@ -41,7 +39,7 @@ setup() {
41
39
}
42
40
43
41
range () {
44
- RANGESTART_COMMIT=$( git merge-base " $REMOTE_BRANCH " master )
42
+ RANGESTART_COMMIT=$( git merge-base " $REMOTE_BRANCH " " $LOCAL_BRANCH " )
45
43
RANGEEND_COMMIT=$( git rev-parse " $REMOTE_BRANCH " )
46
44
if [ " $# " = 1 ]; then
47
45
RANGEEND_COMMIT=$1
@@ -57,18 +55,37 @@ range() {
57
55
esac
58
56
}
59
57
58
+ # Process -b <branch> argument
59
+ while getopts " b:" opt; do
60
+ case $opt in
61
+ b)
62
+ LOCAL_BRANCH=$OPTARG
63
+ ;;
64
+ \? )
65
+ echo " Invalid option: -$OPTARG " >&2
66
+ ;;
67
+ esac
68
+ done
69
+
70
+ # Shift off the processed options
71
+ shift $(( OPTIND - 1 ))
72
+
73
+ if [ " $# " -lt 1 ]; then
74
+ help
75
+ fi
76
+
60
77
case $1 in
61
78
range)
62
79
shift
63
80
setup
64
81
range " $@ "
65
- REPRODUCE_COMMAND=" $0 range $RANGEEND_COMMIT "
82
+ REPRODUCE_COMMAND=" $0 -b $LOCAL_BRANCH range $RANGEEND_COMMIT "
66
83
;;
67
84
select)
68
85
shift
69
86
setup
70
87
COMMITS=$*
71
- REPRODUCE_COMMAND=" $0 select $@ "
88
+ REPRODUCE_COMMAND=" $0 -b $LOCAL_BRANCH select $@ "
72
89
;;
73
90
help)
74
91
help
87
104
done
88
105
# Remove trailing ","
89
106
TITLE=${TITLE% ?}
90
-
91
- BODY=$( printf " %s\n\n%s" " $BODY " " This PR can be recreated with \` $REPRODUCE_COMMAND \` ." )
107
+ BODY=$( printf " %s\n\n%s\n%s" " $BODY " " This PR can be recreated with \` $REPRODUCE_COMMAND \` ." " Tip: Use \` git show --remerge-diff\` to show the changes manually added to the merge commit." )
92
108
93
109
echo " -----------------------------------"
94
110
echo " $TITLE "
95
111
echo " -----------------------------------"
96
112
echo " $BODY "
97
113
echo " -----------------------------------"
98
114
# Create branch from PR commit and create PR
99
- git checkout master
115
+ git checkout " $LOCAL_BRANCH "
100
116
git pull --autostash
101
117
git checkout -b temp-merge-" $PRNUM "
102
118
@@ -115,7 +131,7 @@ cat <<EOT > "$FNAME"
115
131
#!/bin/sh
116
132
gh pr create -t '$TITLE ' -b '$BODY ' --web
117
133
# Remove temporary branch
118
- git checkout master
134
+ git checkout " $LOCAL_BRANCH "
119
135
git branch -D temp-merge-"$PRNUM "
120
136
EOT
121
137
chmod +x " $FNAME "
0 commit comments