-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·327 lines (272 loc) · 8.74 KB
/
test.sh
File metadata and controls
executable file
·327 lines (272 loc) · 8.74 KB
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#!/usr/bin/env sh
commit() (
repo="${1}"
message="${2}"
GIT_COMMITTER_DATE="@1 +0000" \
git \
-C "${repo}" \
commit \
--quiet \
--allow-empty \
--date="@0 +0000" \
--message "${message}"
)
merge() (
repo="${1}"
branch="${2}"
shift 2
GIT_AUTHOR_DATE="@1 +0000" \
GIT_COMMITTER_DATE="@1 +0000" \
git \
-C "${repo}" \
merge \
--no-log \
--quiet \
--no-edit \
"${@}" \
"${branch}"
)
new_repo() (
repo_dir="$(mktemp -d)"
git -C "${repo_dir}" init --quiet --initial-branch master "$@"
git -C "${repo_dir}" config user.name 'David Plowie'
git -C "${repo_dir}" config user.email 'dplowie@gritte.rs'
echo "${repo_dir}"
)
test_after_init() (
expected="$(
cat <<-EOF
## master...(no upstream; no remote)
EOF
)"
repo="$(new_repo)"
actual="$(git -C "${repo}" repo-status)"
test "${actual}" = "${expected}" || {
printf "%s\n\nwas different from\n\n%s\n" "${actual}" "${expected}"
printf "repo: %s\n\n" "${repo}"
}
)
test_after_first_commit() (
expected="$(
cat <<-EOF
## master...(no upstream; no remote)
EOF
)"
repo="$(new_repo)"
commit "${repo}" "Initial commit"
actual="$(git -C "${repo}" repo-status)"
test "${actual}" = "${expected}" || {
printf "\noutput\n\n%s\n\nwas different from\n\n%s\n\n" "${actual}" "${expected}"
printf "repo: %s\n\n" "${repo}"
}
)
test_hint_untracked_upstream() (
expected="$(
cat <<-EOF
## master...origin/master (0/0)
hint: ‘origin/master’ branch exists, but isn’t marked as upstream.
hint: It is recommended to run:
hint:
hint: git branch --set-upstream-to origin/master
hint:
hint: So you can run shorter versions of commands:
hint:
hint: git push origin <branch> → git push
hint: git rebase origin/<branch> → git rebase
hint: git merge origin/<branch> → git merge
EOF
)"
origin="$(new_repo --bare)"
repo="$(new_repo)"
commit "${repo}" "Initial commit"
git -C "${repo}" remote add origin "${origin}"
git -C "${repo}" push --quiet origin master
echo 'ref: refs/remotes/origin/master' >"${repo}/.git/refs/remotes/origin/HEAD"
actual="$(git -C "${repo}" repo-status)"
test "${actual}" = "${expected}" || {
printf "\noutput\n\n%s\n\nwas different from\n\n%s\n\n" "${actual}" "${expected}"
printf "origin: %s\nrepo: %s\n\n" "${origin}" "${repo}"
}
)
test_hint_mistracked_upstream() (
expected="$(
cat <<-EOF
## master...origin/master (0/0)
hint: current ‘master’ branch tracks ‘origin/other’,
hint: but probably should track ‘origin/master’ instead.
hint: run this command to fix this:
hint: git branch --set-upstream-to origin/master
EOF
)"
origin="$(new_repo --bare)"
repo="$(new_repo)"
commit "${repo}" "Initial commit"
git -C "${repo}" remote add origin "${origin}"
git -C "${repo}" push --quiet origin master
git -C "${repo}" push --quiet --set-upstream origin master:other
echo 'ref: refs/remotes/origin/master' >"${repo}/.git/refs/remotes/origin/HEAD"
actual="$(git -C "${repo}" repo-status)"
test "${actual}" = "${expected}" || {
printf "\noutput\n\n%s\n\nwas different from\n\n%s\n\n" "${actual}" "${expected}"
printf "origin: %s\nrepo: %s\n\n" "${origin}" "${repo}"
}
)
test_correct_upstream() (
expected="$(
cat <<-EOF
## master...origin/master (0/0)
EOF
)"
origin="$(new_repo --bare)"
repo="$(new_repo)"
commit "${repo}" "Initial commit"
git -C "${repo}" remote add origin "${origin}"
git -C "${repo}" push --quiet --set-upstream origin master
echo 'ref: refs/remotes/origin/master' >"${repo}/.git/refs/remotes/origin/HEAD"
actual="$(git -C "${repo}" repo-status)"
test "${actual}" = "${expected}" || {
printf "\noutput\n\n%s\n\nwas different from\n\n%s\n\n" "${actual}" "${expected}"
printf "origin: %s\nrepo: %s\n\n" "${origin}" "${repo}"
}
)
test_ahead_of_upstream() (
expected="$(
cat <<-EOF
## master...origin/master (1/0)
< Second commit
| c6193d9 David Plowie 54 years ago HEAD -> master
o Initial commit
6a103bc David Plowie 54 years ago origin/master, origin/HEAD
EOF
)"
origin="$(new_repo --bare)"
repo="$(new_repo)"
commit "${repo}" "Initial commit"
git -C "${repo}" remote add origin "${origin}"
git -C "${repo}" push --quiet --set-upstream origin master
commit "${repo}" "Second commit"
echo 'ref: refs/remotes/origin/master' >"${repo}/.git/refs/remotes/origin/HEAD"
actual="$(git -C "${repo}" repo-status)"
test "${actual}" = "${expected}" || {
printf "\noutput\n\n%s\n\nwas different from\n\n%s\n\n" "${actual}" "${expected}"
printf "origin: %s\nrepo: %s\n\n" "${origin}" "${repo}"
}
)
test_rebase_lost_merges_hint() (
expected="$(
cat <<-EOF
## topic...(no upstream; no remote)
hint: The branch before the rebase contained these merge commits:
hint: f4a10dd Merge other branch
hint: but the branch after the rebase contains no merge commits. This might be
hint: intentional, but can also mean that merge commits were lost during the
hint: rebase because you didn’t pass the ‘--rebase-merges’ flag. If this was not
hint: intentional, you can run
hint: git reset --hard ORIG_HEAD
hint: to reset the branch to the state before the rebase, and attempt the rebase
hint: again.
hint: If this was intentional and you wish this hint went away,
hint: run ‘git commit --amend’ or perform a no-op ‘git reset’.
EOF
)"
repo="$(new_repo)"
commit "${repo}" "Initial commit"
git -C "${repo}" checkout --quiet -b topic
commit "${repo}" "Second commit"
git -C "${repo}" checkout --quiet -b other master
commit "${repo}" "Third commit"
git -C "${repo}" checkout --quiet -
merge "${repo}" other -m "Merge other branch"
GIT_AUTHOR_DATE="@1 +0000" \
GIT_COMMITTER_DATE="@1 +0000" \
git -C "${repo}" rebase --quiet master
actual="$(git -C "${repo}" repo-status)"
test "${actual}" = "${expected}" || {
printf "\noutput\n\n%s\n\nwas different from\n\n%s\n\n" "${actual}" "${expected}"
printf "repo: %s\n\n" "${repo}"
}
)
test_intent_to_add_hint() (
expected="$(
cat <<-EOF
## working tree status
?? some-file
## master...(no upstream; no remote)
hint: Your last reset moved ‘HEAD’ from a revision that tracked these paths:
hint: some-file
hint: to a revision that doesn’t. If you wish to keep tracking them, run
hint: git add [<path>...]
hint: You can avoid this issue by adding ‘--intent-to-add’ or ‘-N’ flag to your
hint: reset invocations.
EOF
)"
repo="$(new_repo)"
commit "${repo}" "Initial commit"
echo some-content >"${repo}/some-file"
git -C "${repo}" add some-file
commit "${repo}" "Second commit"
git -C "${repo}" reset @^
actual="$(git -C "${repo}" repo-status)"
test "${actual}" = "${expected}" || {
printf "\noutput\n\n%s\n\nwas different from\n\n%s\n\n" "${actual}" "${expected}"
printf "repo: %s\n\n" "${repo}"
}
)
test_rebase_status() (
expected="$(
cat <<-EOF
## rebase summary
✓ pick 6a103bc Initial commit # empty
→ edit c6193d9 Second commit # empty
· pick 4af4e41 Third commit # empty
EOF
)"
repo="$(new_repo)"
commit "${repo}" "Initial commit"
commit "${repo}" "Second commit"
commit "${repo}" "Third commit"
# ed is the standard text editor
GIT_SEQUENCE_EDITOR="printf '2s/pick/edit/\nw\nq\n' | ed >/dev/null 2>/dev/null" \
GIT_COMMITTER_DATE="@1 +0000" \
GIT_AUTHOR_DATE="@1 +0000" \
git -C "${repo}" rebase -i --root --quiet 2>/dev/null
actual="$(git -C "${repo}" repo-status)"
test "${actual}" = "${expected}" || {
printf "\noutput\n\n%s\n\nwas different from\n\n%s\n\n" "${actual}" "${expected}"
printf "repo: %s\n\n" "${repo}"
}
)
test_remote_head_file_missing_hint() (
expected="$(
cat <<-EOF
## master...(no upstream)
hint: file ‘.git/refs/remotes/origin/HEAD’ not found.
hint: This file is used to guess the branch on a remote repository this branch will
hint: be merged to. The file can be missing if the remote was added to the repository
hint: that already existed locally, as opposed to creating a local repository by
hint: cloning from a remote. You can fix the issue by running this command:
hint: git remote set-head origin --auto
hint: This is merely a hindrance to libstatus merge target guessing. It doesn’t
hint: impact any other git operations.
EOF
)"
origin="$(new_repo --bare)"
repo="$(new_repo)"
commit "${repo}" "Initial commit"
git -C "${repo}" remote add origin "${origin}"
actual="$(git -C "${repo}" repo-status)"
test "${actual}" = "${expected}" || {
printf "\noutput\n\n%s\n\nwas different from\n\n%s\n\n" "${actual}" "${expected}"
printf "origin: %s\nrepo: %s\n\n" "${origin}" "${repo}"
}
)
if test -z "${1}"; then
# Run all the tests.
sed -ne 's|^\(test_[A-Za-z0-9_]*\).*|\1|p' "${0}" \
| while read -r testcase; do
echo "${testcase}" && "${testcase}"
done
else
# Run the test given as argument.
"${1}"
fi