-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkshop-cherry-pick
executable file
·159 lines (140 loc) · 3.41 KB
/
workshop-cherry-pick
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
# Usage: ./workshop-cherry-pick [commit] --start [start-branch] --end [end-branch]
set -e
# keep this array up to date with all the branches (in order)
ws=("workshop0-starter"
"workshop0-step1"
"workshop0-step2"
"workshop0-step3"
"workshop0-step4"
"workshop0-step5"
"workshop0-step6"
"workshop0-step7"
"workshop0-step8"
"workshop0-step9"
"workshop0-step10"
"workshop0-step11"
"workshop0-step12"
"workshop0-step13"
"workshop0-complete"
"workshop1-starter"
"workshop1-step1"
"workshop1-step2"
"workshop1-complete"
"workshop2-starter"
"workshop2-step1"
"workshop2-step2"
"workshop2-step3"
"workshop2-step4"
"workshop2-step5"
"workshop2-step6"
"workshop2-step7"
"workshop2-step8"
"workshop2-step9"
"workshop2-step10"
"workshop2-complete"
"workshop3-complete"
"workshop4-starter"
"workshop4-step1"
"workshop4-step2"
"workshop4-step3"
"workshop4-complete"
"workshop5-starter"
"workshop5-complete"
"noauth"
"workshop6-starter"
"workshop6-step1"
"workshop6-step2"
"workshop6-step3"
"workshop6-step4"
"workshop6-step5"
"workshop6-step6"
"workshop6-step7"
"workshop6-step8"
"workshop6-complete"
"workshop7-starter"
"workshop7-step1"
"workshop7-step2"
"workshop7-step3"
"workshop7-step4"
"workshop7-step5"
"workshop7-complete"
"workshop8-starter"
"workshop8-step0"
"workshop8-step1"
"workshop8-step2"
"workshop8-step3"
"workshop8-step4"
"workshop8-step5"
"workshop8-step6"
"workshop8-step7"
"workshop8-step8"
"workshop8-complete"
)
# use most recent commit if commit not specified
commit=$(git rev-parse HEAD)
# start on the first workshop if not specified
startbr=${ws[0]}
# no end branch by default
endbr=""
# iterate through script parameters
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-s|--start)
startbr="$2"
shift # consume --start
shift # consume value
;;
-e|--end)
endbr="$2"
shift # consume --end
shift # consume value
;;
*) # positional arg
commit="$1"
shift # consume value
;;
esac
done
message=$(git log -1 --pretty=%B $commit)
# if ws does not contain START
if [[ ! " ${ws[@]} " =~ " ${startbr} " ]]; then
echo "ERROR: invalid branch $startbr"
exit 1
fi
echo "cherry-picking commit $commit to all branches starting from $startbr"
origbranch=$(git symbolic-ref --short HEAD)
active=false
for branch in "${ws[@]}"; do
if [ "$branch" == "$startbr" ]; then
active=true
fi
$active || continue
if [ "$branch" == "$endbr" ]; then
active=false
fi
brstatus=$(git checkout $branch)
# makes sure you actually have the must up-to-date branch
if [[ "$brstatus" =~ "branch is behind" ]]; then
echo "branch is behind, pulling"
git pull
fi
# makes the script idempotent
if [ "$message" == "$(git log -1 --pretty=%B)" ]; then
echo "WARN: commit was already cherry-picked to this branch, skipping"
echo "------------"
continue
fi
# actually apply the cherry-pick here
if git cherry-pick --allow-empty $commit ; then
echo "success"
echo "------------"
else
echo "WARN: conflict encountered! please resolve this and re-run the script"
exit 1
fi
done
git checkout $origbranch
echo "done"