-
-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathremote.bats
More file actions
326 lines (214 loc) · 9.31 KB
/
Copy pathremote.bats
File metadata and controls
326 lines (214 loc) · 9.31 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
#!/usr/bin/env bats
load test_helper
# remote remove and set #######################################################
@test "'remote remove' deletes remote branch and 'remote set' rebases onto initialized remote." {
{
"${_NB}" init
"${_NB}" add "Example File.md" --content "Example content."
_setup_remote_repo
"${_NB}" remote set "${_GIT_REMOTE_URL}" <<< "y${_NEWLINE}1${_NEWLINE}"
diff \
<("${_NB}" remote) \
<(printf "%s (master)\\n" "${_GIT_REMOTE_URL}")
diff \
<(git -C "${NB_DIR}/home" branch --all) \
<(printf "* master\\n remotes/origin/master\\n")
declare _before_hashes=()
_before_hashes=($("${_NB}" git rev-list origin/master))
[[ "${#_before_hashes[@]}" -eq 2 ]]
[[ "$("${_NB}" git log)" =~ \[nb\]\ Add:\ Example\ File\.md ]]
[[ "$("${_NB}" git log)" =~ Initial\ commit\. ]]
}
run "${_NB}" remote remove <<< "y${_NEWLINE}y${_NEWLINE}"
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
"${_NB}" remote && return 1
[[ "${status}" -eq 0 ]]
[[ "$("${_NB}" remote 2>&1)" =~ No\ remote\ configured. ]]
[[ "${lines[0]}" =~ Removing\ remote:\ .*${_GIT_REMOTE_URL} ]]
[[ "${lines[1]}" =~ Remote\ branch\ reset:\ .*master ]]
[[ "${lines[2]}" =~ Remote\ removed. ]]
diff \
<(git -C "${NB_DIR}/home" branch --all) \
<(printf "* master\\n")
# resets remote
diff \
<(git -C "${NB_DIR}/home" ls-remote \
--heads "${_GIT_REMOTE_URL}" \
| sed "s/.*\///g" || :) \
<(printf "master\\n")
git clone "${_GIT_REMOTE_URL}" "${_TMP_DIR}/new-clone"
run git -C "${_TMP_DIR}/new-clone" branch --all
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" =~ \*\ master ]]
[[ "${lines[1]}" =~ remotes/origin/HEAD\ \-\>\ origin/master ]]
[[ "${lines[2]}" =~ remotes/origin/master ]]
declare _after_hashes=()
_after_hashes=($(git -C "${_TMP_DIR}/new-clone" rev-list origin/master))
printf "_after_hashes: %s\\n" "${_after_hashes[@]}"
[[ "${#_after_hashes[@]}" -eq 1 ]]
! _contains "${_after_hashes[0]}" "${_before_hashes[@]}"
[[ "${_after_hashes[0]}" != "${_before_hashes[0]}" ]]
[[ "${_after_hashes[0]}" != "${_before_hashes[1]}" ]]
git -C "${_TMP_DIR}/new-clone" log
[[ "$(git -C "${_TMP_DIR}/new-clone" log)" =~ \[nb\]\ Initialize ]]
{
sleep 1
"${_NB}" notebooks add "Sample Notebook"
"${_NB}" notebooks use "Sample Notebook"
"${_NB}" add "Sample File.md" --content "Sample content."
declare _new_before_hashes=()
_new_before_hashes=($("${_NB}" git rev-list master))
printf "_new_before_hashes: %s\\n" "${_new_before_hashes[@]}"
[[ "${#_new_before_hashes[@]}" -eq 2 ]]
[[ "$("${_NB}" git log)" =~ \[nb\]\ Add:\ Sample\ File\.md ]]
[[ "$("${_NB}" git log)" =~ Initialize ]]
}
run "${_NB}" remote set "${_GIT_REMOTE_URL}" <<< "y${_NEWLINE}1${_NEWLINE}1${_NEWLINE}"
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
"${_NB}" remote
[[ "${status}" -eq 0 ]]
[[ "${lines[0]}" =~ Adding\ remote\ to:\ .*Sample\ Notebook ]]
[[ "${lines[1]}" =~ [^-]---------------------------------[^-] ]]
[[ "${lines[2]}" =~ URL:\ \ \ \ .*${_GIT_REMOTE_URL} ]]
[[ "${lines[3]}" =~ Branch:\ .*master ]]
[[ "${lines[4]}" =~ [^-]--------------[^-] ]]
[[ "${lines[5]}" =~ \
Remote\ set\ to:\ .*${_GIT_REMOTE_URL}.*\ \(.*master.*\) ]]
diff \
<("${_NB}" remote) \
<(printf "%s (master)\\n" "${_GIT_REMOTE_URL:-}")
git clone "${_GIT_REMOTE_URL}" "${_TMP_DIR}/new-clone-2"
run git -C "${_TMP_DIR}/new-clone-2" branch --all
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
[[ "${lines[0]}" =~ \*\ master ]]
[[ "${lines[1]}" =~ remotes/origin/HEAD\ \-\>\ origin/master ]]
[[ "${lines[2]}" =~ remotes/origin/master ]]
[[ -f "${_TMP_DIR}/new-clone-2/Sample File.md" ]]
declare _new_after_hashes=()
_new_after_hashes=($(git -C "${_TMP_DIR}/new-clone-2" rev-list origin/master))
printf "_new_after_hashes: %s\\n" "${_new_after_hashes[@]}"
git -C "${_TMP_DIR}/new-clone-2" log
[[ "${#_new_after_hashes[@]}" -eq 2 ]]
! _contains "${_new_after_hashes[0]}" "${_new_before_hashes[@]}"
[[ "${_new_after_hashes[1]}" == "${_after_hashes[0]}" ]]
[[ "${_new_after_hashes[0]}" != "${_new_before_hashes[1]}" ]]
[[ "${_new_after_hashes[0]}" != "${_new_before_hashes[0]}" ]]
[[ "$(git -C "${_TMP_DIR}/new-clone-2" log)" =~ \[nb\]\ Initialize ]]
}
# remote branches #############################################################
@test "'remote branches' with no existing remote prints message." {
{
"${_NB}" init
}
run "${_NB}" remote branches
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
[[ "${status}" -eq 1 ]]
[[ "${#lines[@]}" -eq 1 ]]
[[ "${lines[0]}" =~ No\ remote\ configured. ]]
}
@test "'remote branches <url>' with no existing remote prints remote branches with current branch highlighted." {
{
"${_NB}" init
_setup_remote_repo
}
run "${_NB}" remote branches "${_GIT_REMOTE_URL}"
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
[[ "${status}" -eq 0 ]]
[[ "${#lines[@]}" -eq 1 ]]
[[ "${lines[0]}" =~ .*master.* ]]
}
@test "'remote branches' with existing remote as orphan prints branches with current branch highlighted." {
{
"${_NB}" init
_setup_remote_repo
"${_NB}" git branch -m "example-branch"
"${_NB}" remote add "${_GIT_REMOTE_URL}" "example-branch" <<< "y${_NEWLINE}2${_NEWLINE}"
diff \
<(git -C "${NB_DIR}/home" ls-remote \
--heads "${_GIT_REMOTE_URL}" \
| sed "s/.*\///g" || :) \
<(printf "example-branch\\nmaster\\n")
}
run "${_NB}" remote branches
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
[[ "${status}" -eq 0 ]]
[[ "${#lines[@]}" -eq 2 ]]
[[ "${lines[0]}" =~ .*example-branch.* ]]
[[ "${lines[1]}" == "master" ]]
}
# remote ######################################################################
@test "'remote' with no arguments and no remote prints message." {
{
"${_NB}" init
}
run "${_NB}" remote
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
[[ "${status}" -eq 1 ]]
[[ "${lines[0]}" =~ No\ remote\ configured ]]
}
@test "'remote --url' with existing remote prints url." {
{
"${_NB}" init
cd "${NB_DIR}/home" &&
git remote add origin "${_GIT_REMOTE_URL}"
}
run "${_NB}" remote --url
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
[[ "${status}" -eq 0 ]]
[[ "${lines[0]}" == "${_GIT_REMOTE_URL}" ]]
}
@test "'remote' with no arguments and existing remote prints url and branch." {
{
"${_NB}" init
cd "${NB_DIR}/home" &&
git remote add origin "${_GIT_REMOTE_URL}"
}
run "${_NB}" remote
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
[[ "${status}" -eq 0 ]]
[[ "${lines[0]}" == "${_GIT_REMOTE_URL} (master)" ]]
}
@test "'remote' with no arguments does not trigger git commit." {
{
"${_NB}" init
cd "${NB_DIR}/home" &&
git remote add origin "${_GIT_REMOTE_URL}"
touch "${NB_DIR}/home/example.md"
[[ -f "${NB_DIR}/home/example.md" ]]
"${_NB}" git dirty
}
run "${_NB}" remote
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
[[ "${status}" -eq 0 ]]
[[ "${lines[0]}" == "${_GIT_REMOTE_URL} (master)" ]]
[[ -f "${NB_DIR}/home/example.md" ]]
"${_NB}" git dirty
# does not create git commit
cd "${NB_DIR}/home" || return 1
if [[ -n "$(git -C "${NB_DIR}/home" status --porcelain)" ]]
then
sleep 1
fi
! git log | grep -q '\[nb\] Commit'
! git log | grep -q '\[nb\] Sync'
}
# help ########################################################################
@test "'help remote' exits with 0 and prints help information." {
run "${_NB}" help remote
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
[[ "${status}" -eq 0 ]]
[[ "${lines[0]}" =~ Usage.*\: ]]
[[ "${lines[1]}" =~ \ \ nb\ remote ]]
}