-
Notifications
You must be signed in to change notification settings - Fork 9
/
create-stage.sh
executable file
·226 lines (165 loc) · 5.69 KB
/
create-stage.sh
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/usr/bin/env bash
set -euo pipefail
set -x
num="$1"
remote="origin"
main="$num-main"
merge="$num-merge-branch"
rebase="$num-rebase-branch"
thhgttg="$num-life"
cherry="$num-cherry-pick-branch"
current="$(git branch --show-current)"
declare -a branches=($merge $rebase $cherry $thhgttg)
function log {
local text="$1"
printf '\e[32;1m%s\e[0m\n' "=> $text"
}
# cleanup
log "performing cleanup"
for branch in "${branches[@]}"; do
git branch -D $branch || true
git push -d $remote $branch || true
done
git branch -D $main || true
git push -d $remote $main || true
git tag -d "$num-v1.0.0" || true
git push -d $remote "$num-v1.0.0" || true
[ -z ${CLEANUP_ONLY+x} ] || exit 0
log "switching to base"
git pull
# create single starting commit
log "generating initial commit"
git switch -c $main
cat >README.md << EOF
# Personalized Git Techbier for ${num^^}
> File for participant ${num^^}
This file is the main test file on which you will perform your exercises. A
secondary file 'content.md' is used for exercises.
This file is the entry point for all your exercises. A secondary file
\`content.md\` is the file which you will need to change to actually perform the
exercises.
## Amend
Switch to branch \`$main\`. Oh no, there is a typo (or should I say "typoo") in
the last commit! Amend the commit to correct the commit message.
Oh no again, we wanted to have two exclamation marks (!!) on in the content.
Change the line in the content file to:
\`\`\`
Hello world!!
\`\`\`
Push all your changes to \`$main\` again.
> Don't push as an extra commit! We only amended here, so there should only be
> the one commit with message
> \`"fix: correct typoo in content for participant $num"\`.
## Merge
Merge branch \`$merge\` into \`$main\`. Resolve any conflicts that might arise
by keeping the changes from \`$merge\`.
Don't forget to push your changes.
## Rebase
Switch to branch \`$rebase\` and rebase it **onto \`$main\`**. Resolve any
conflicts that might arise by keeping the changes from \`$rebase\`.
Don't forget to push your changes.
## Squash
The branch \`$rebase\` should be 2 commits ahead of \`$main\`. Squash the two
commits into a single commit with message:
\`\`\`
feat: beautify world and ask participant $num how (s)he is enjoying it
\`\`\`
Don't forget to push your changes.
## Cherry Pick
Damn, there is an amazing commit on branch \`$cherry\` with message:
\`\`\`
feat: add content that should also be on $main
\`\`\`
This should indeed also be on \`$main\`. Let's cherry-pick it onto main! Resolve
any conflicts that might arise by keeping the changes from \`$cherry\`.
And ...
...yup, don't forget to push your changes.
## Tag
I think how that we merged \`$merge\` into \`$main\` and added the amazing
commit from \`$cherry\`, we could go live with version \`1.0.0\`!
Let's create a tag \`$num-v1.0.0\` on the last commit on \`$main\` and push it to the
remote.
## Reset
Now it's your time to show your Markdown skillz. Switch to branch \`$rebase\`
and modify \`content.md\` by adding whether you are a cat or a dog person, then
commit it, but don't push!
Ahhhhhh, turns out being a cat or dog person is sensitive information, let's
hard reset back to the status of \`$rebase\` that is on the remote.
## Stash
> You should be on branch \`$rebase\`.
Mhhh maybe we could add less sensitive information, like the meaning of life.
Add a line to \`content.md\` that says:
\`\`\`
The answer to the meaning of life, the universe, and everything is ...
\`\`\`
Ahhh you don't get time to find the answer to it, and a colleague asks you to
review his code on branch \`$thhgttg\`. Stash your changes for later, and have a
look at the \`$thhgttg\` branch. Once you have had a look, go back to
\`$rebase\` and finish your line, commit the changes, and push them.
EOF
cat >content.md <<EOF
# Content
Hello word!
EOF
git add .
git commit -am "chore: initial commit for participant $num"
git push -u $remote $main
# branch of here
log "generating feature branches"
for branch in "${branches[@]}"; do
git branch $branch
git push -u $remote $branch
done
# move main forward
log "generating extra commit on $main"
git switch $main
cat >content.md <<EOF
# Content
Hello world!
EOF
git commit -am "fix: correct typoo in content for participant $num"
git push
# generate content and conflict on merge branch
log "populating $merge"
git switch $merge
cat >content.md <<EOF
# Content
Hello world ... (sad face)
EOF
git commit -am "feat: change the mood to sad ..."
echo "...and hello participant $num!! (happy face)" >> content.md
git commit -am "feat: welcome participant $num!"
git push
# generate content and conflict on rebase branch
log "populating $rebase"
git switch $rebase
cat >content.md <<EOF
# Content
Hello beautiful world!
EOF
git commit -am "feat: make the world beautiful"
echo "Oops forgot to add: Hope you are enjoying the techbier so far!" >> content.md
git commit -am "feat: ask participant $num how (s)he is enjoying it"
git push
# generate content and conflict on cherry branch
log "populating $cherry"
git switch $cherry
echo "This is some cherry sweet content I would like to have on $main!" >> content.md
git commit -am "feat: add content that should also be on $main"
git push
# generate content on life branch
log "populating $thhgttg"
git switch $thhgttg
cat >solution.md <<EOF
It's 42!!!!!
If you want to know how to mindlessly waste computing power, or are especially
bored even though this is an amazing TechBier, here is an article that is quite
irrelevant: https://news.mit.edu/2019/answer-life-universe-and-everything-sum-three-cubes-mathematics-0910
EOF
git add .
git commit -m "feat: find the solution"
git push
# switch back to initial branch to restore state
log "switching back to $current"
git switch $current
# vim:tw=80