git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
9fcec604c397acc9a6b3d5c32520334372db0c1c blob 9649 bytes (raw)

  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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
 
#!/bin/sh

test_description='compare & swap push force/delete safety'

. ./test-lib.sh

setup_srcdst_basic () {
	rm -fr src dst &&
	git clone --no-local . src &&
	git clone --no-local src dst &&
	(
		cd src && git checkout HEAD^0
	)
}

# For tests with "--force-if-includes".
setup_src_dup_dst () {
	rm -fr src dup dst &&
	git init --bare dst &&
	git clone --no-local dst src &&
	git clone --no-local dst dup
	(
		cd src &&
		test_commit A &&
		test_commit B &&
		test_commit C &&
		git push origin
	) &&
	(
		cd dup &&
		git fetch &&
		git merge origin/main &&
		git switch -c branch main~2 &&
		test_commit D &&
		test_commit E &&
		git push origin --all
	) &&
	(
		cd src &&
		git switch main &&
		git fetch --all &&
		git branch branch --track origin/branch &&
		git rebase origin/main
	) &&
	(
		cd dup &&
		git switch main &&
		test_commit F &&
		test_commit G &&
		git switch branch &&
		test_commit H &&
		git push origin --all
	)
}

test_expect_success setup '
	# create template repository
	test_commit A &&
	test_commit B &&
	test_commit C
'

test_expect_success 'push to update (protected)' '
	setup_srcdst_basic &&
	(
		cd dst &&
		test_commit D &&
		test_must_fail git push --force-with-lease=main:main origin main 2>err &&
		grep "stale info" err
	) &&
	git ls-remote . refs/heads/main >expect &&
	git ls-remote src refs/heads/main >actual &&
	test_cmp expect actual
'

test_expect_success 'push to update (protected, forced)' '
	setup_srcdst_basic &&
	(
		cd dst &&
		test_commit D &&
		git push --force --force-with-lease=main:main origin main 2>err &&
		grep "forced update" err
	) &&
	git ls-remote dst refs/heads/main >expect &&
	git ls-remote src refs/heads/main >actual &&
	test_cmp expect actual
'

test_expect_success 'push to update (protected, tracking)' '
	setup_srcdst_basic &&
	(
		cd src &&
		git checkout main &&
		test_commit D &&
		git checkout HEAD^0
	) &&
	git ls-remote src refs/heads/main >expect &&
	(
		cd dst &&
		test_commit E &&
		git ls-remote . refs/remotes/origin/main >expect &&
		test_must_fail git push --force-with-lease=main origin main &&
		git ls-remote . refs/remotes/origin/main >actual &&
		test_cmp expect actual
	) &&
	git ls-remote src refs/heads/main >actual &&
	test_cmp expect actual
'

test_expect_success 'push to update (protected, tracking, forced)' '
	setup_srcdst_basic &&
	(
		cd src &&
		git checkout main &&
		test_commit D &&
		git checkout HEAD^0
	) &&
	(
		cd dst &&
		test_commit E &&
		git ls-remote . refs/remotes/origin/main >expect &&
		git push --force --force-with-lease=main origin main
	) &&
	git ls-remote dst refs/heads/main >expect &&
	git ls-remote src refs/heads/main >actual &&
	test_cmp expect actual
'

test_expect_success 'push to update (allowed)' '
	setup_srcdst_basic &&
	(
		cd dst &&
		test_commit D &&
		git push --force-with-lease=main:main^ origin main
	) &&
	git ls-remote dst refs/heads/main >expect &&
	git ls-remote src refs/heads/main >actual &&
	test_cmp expect actual
'

test_expect_success 'push to update (allowed, tracking)' '
	setup_srcdst_basic &&
	(
		cd dst &&
		test_commit D &&
		git push --force-with-lease=main origin main 2>err &&
		! grep "forced update" err
	) &&
	git ls-remote dst refs/heads/main >expect &&
	git ls-remote src refs/heads/main >actual &&
	test_cmp expect actual
'

test_expect_success 'push to update (allowed even though no-ff)' '
	setup_srcdst_basic &&
	(
		cd dst &&
		git reset --hard HEAD^ &&
		test_commit D &&
		git push --force-with-lease=main origin main 2>err &&
		grep "forced update" err
	) &&
	git ls-remote dst refs/heads/main >expect &&
	git ls-remote src refs/heads/main >actual &&
	test_cmp expect actual
'

test_expect_success 'push to delete (protected)' '
	setup_srcdst_basic &&
	git ls-remote src refs/heads/main >expect &&
	(
		cd dst &&
		test_must_fail git push --force-with-lease=main:main^ origin :main
	) &&
	git ls-remote src refs/heads/main >actual &&
	test_cmp expect actual
'

test_expect_success 'push to delete (protected, forced)' '
	setup_srcdst_basic &&
	(
		cd dst &&
		git push --force --force-with-lease=main:main^ origin :main
	) &&
	git ls-remote src refs/heads/main >actual &&
	test_must_be_empty actual
'

test_expect_success 'push to delete (allowed)' '
	setup_srcdst_basic &&
	(
		cd dst &&
		git push --force-with-lease=main origin :main 2>err &&
		grep deleted err
	) &&
	git ls-remote src refs/heads/main >actual &&
	test_must_be_empty actual
'

test_expect_success 'cover everything with default force-with-lease (protected)' '
	setup_srcdst_basic &&
	(
		cd src &&
		git branch nain main^
	) &&
	git ls-remote src refs/heads/\* >expect &&
	(
		cd dst &&
		test_must_fail git push --force-with-lease origin main main:nain
	) &&
	git ls-remote src refs/heads/\* >actual &&
	test_cmp expect actual
'

test_expect_success 'cover everything with default force-with-lease (allowed)' '
	setup_srcdst_basic &&
	(
		cd src &&
		git branch nain main^
	) &&
	(
		cd dst &&
		git fetch &&
		git push --force-with-lease origin main main:nain
	) &&
	git ls-remote dst refs/heads/main |
	sed -e "s/main/nain/" >expect &&
	git ls-remote src refs/heads/nain >actual &&
	test_cmp expect actual
'

test_expect_success 'new branch covered by force-with-lease' '
	setup_srcdst_basic &&
	(
		cd dst &&
		git branch branch main &&
		git push --force-with-lease=branch origin branch
	) &&
	git ls-remote dst refs/heads/branch >expect &&
	git ls-remote src refs/heads/branch >actual &&
	test_cmp expect actual
'

test_expect_success 'new branch covered by force-with-lease (explicit)' '
	setup_srcdst_basic &&
	(
		cd dst &&
		git branch branch main &&
		git push --force-with-lease=branch: origin branch
	) &&
	git ls-remote dst refs/heads/branch >expect &&
	git ls-remote src refs/heads/branch >actual &&
	test_cmp expect actual
'

test_expect_success 'new branch already exists' '
	setup_srcdst_basic &&
	(
		cd src &&
		git checkout -b branch main &&
		test_commit F
	) &&
	(
		cd dst &&
		git branch branch main &&
		test_must_fail git push --force-with-lease=branch: origin branch
	)
'

test_expect_success 'background updates of REMOTE can be mitigated with a non-updated REMOTE-push' '
	rm -rf src dst &&
	git init --bare src.bare &&
	test_when_finished "rm -rf src.bare" &&
	git clone --no-local src.bare dst &&
	test_when_finished "rm -rf dst" &&
	(
		cd dst &&
		test_commit G &&
		git remote add origin-push ../src.bare &&
		git push origin-push main:main
	) &&
	git clone --no-local src.bare dst2 &&
	test_when_finished "rm -rf dst2" &&
	(
		cd dst2 &&
		test_commit H &&
		git push
	) &&
	(
		cd dst &&
		test_commit I &&
		git fetch origin &&
		test_must_fail git push --force-with-lease origin-push &&
		git fetch origin-push &&
		git push --force-with-lease origin-push
	)
'

test_expect_success 'background updates to remote can be mitigated with "--force-if-includes"' '
	setup_src_dup_dst &&
	test_when_finished "rm -fr dst src dup" &&
	git ls-remote dst refs/heads/main >expect.main &&
	git ls-remote dst refs/heads/branch >expect.branch &&
	(
		cd src &&
		git switch branch &&
		test_commit I &&
		git switch main &&
		test_commit J &&
		git fetch --all &&
		test_must_fail git push --force-with-lease --force-if-includes --all
	) &&
	git ls-remote dst refs/heads/main >actual.main &&
	git ls-remote dst refs/heads/branch >actual.branch &&
	test_cmp expect.main actual.main &&
	test_cmp expect.branch actual.branch
'

test_expect_success 'background updates to remote can be mitigated with "push.useForceIfIncludes"' '
	setup_src_dup_dst &&
	test_when_finished "rm -fr dst src dup" &&
	git ls-remote dst refs/heads/main >expect.main &&
	(
		cd src &&
		git switch branch &&
		test_commit I &&
		git switch main &&
		test_commit J &&
		git fetch --all &&
		git config --local push.useForceIfIncludes true &&
		test_must_fail git push --force-with-lease=main origin main
	) &&
	git ls-remote dst refs/heads/main >actual.main &&
	test_cmp expect.main actual.main
'

test_expect_success '"--force-if-includes" should be disabled for --force-with-lease="<refname>:<expect>"' '
	setup_src_dup_dst &&
	test_when_finished "rm -fr dst src dup" &&
	git ls-remote dst refs/heads/main >expect.main &&
	(
		cd src &&
		git switch branch &&
		test_commit I &&
		git switch main &&
		test_commit J &&
		remote_head="$(git rev-parse refs/remotes/origin/main)" &&
		git fetch --all &&
		test_must_fail git push --force-if-includes --force-with-lease="main:$remote_head" 2>err &&
		grep "stale info" err
	) &&
	git ls-remote dst refs/heads/main >actual.main &&
	test_cmp expect.main actual.main
'

test_expect_success '"--force-if-includes" should allow forced update after a rebase ("pull --rebase")' '
	setup_src_dup_dst &&
	test_when_finished "rm -fr dst src dup" &&
	(
		cd src &&
		git switch branch &&
		test_commit I &&
		git switch main &&
		test_commit J &&
		git pull --rebase origin main &&
		git push --force-if-includes --force-with-lease="main"
	)
'

test_expect_success '"--force-if-includes" should allow forced update after a rebase ("pull --rebase", local rebase)' '
	setup_src_dup_dst &&
	test_when_finished "rm -fr dst src dup" &&
	(
		cd src &&
		git switch branch &&
		test_commit I &&
		git switch main &&
		test_commit J &&
		git pull --rebase origin main &&
		git rebase --onto HEAD~4 HEAD~1 &&
		git push --force-if-includes --force-with-lease="main"
	)
'

test_expect_success '"--force-if-includes" should allow deletes' '
	setup_src_dup_dst &&
	test_when_finished "rm -fr dst src dup" &&
	(
		cd src &&
		git switch branch &&
		git pull --rebase origin branch &&
		git push --force-if-includes --force-with-lease="branch" origin :branch
	)
'

test_done
debug log:

solving 9fcec604c3 ...
found 9fcec604c3 in https://public-inbox.org/git/3aef39320e96aad10e133f1c97a9010aa85aa894.1605221039.git.gitgitgadget@gmail.com/ ||
	https://public-inbox.org/git/4b1b1ee51f19b6625118f39ac1389b485f99290a.1605629548.git.gitgitgadget@gmail.com/
found 7813e8470e in git.git.git
preparing index
index prepared:
100755 7813e8470e550a2eaf19943552fa69dfd4501747	t/t5533-push-cas.sh

applying [1/2] https://public-inbox.org/git/3aef39320e96aad10e133f1c97a9010aa85aa894.1605221039.git.gitgitgadget@gmail.com/
diff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh
index 7813e8470e..9fcec604c3 100755

Checking patch t/t5533-push-cas.sh...
Applied patch t/t5533-push-cas.sh cleanly.

skipping https://public-inbox.org/git/4b1b1ee51f19b6625118f39ac1389b485f99290a.1605629548.git.gitgitgadget@gmail.com/ for 9fcec604c3
index at:
100755 9fcec604c397acc9a6b3d5c32520334372db0c1c	t/t5533-push-cas.sh

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).