@@ -242,6 +242,85 @@ test_expect_success 'old records rest in peace' '
242242 test_path_is_missing $rr2/preimage
243243'
244244
245+ test_expect_success ' gc --skip-locked does nothing while MERGE_RR is locked' '
246+ mkdir -p $rr2 &&
247+ echo Hello >$rr2/preimage &&
248+ test-tool chmtime =$just_over_15_days_ago $rr2/preimage &&
249+
250+ test_when_finished "rm -f .git/MERGE_RR.lock" &&
251+ >.git/MERGE_RR.lock &&
252+ git rerere gc --skip-locked 2>err &&
253+ test_must_be_empty err &&
254+ test_path_is_file $rr2/preimage
255+ '
256+
257+ test_expect_success ' gc --skip-locked prunes while MERGE_RR is not locked' '
258+ mkdir -p $rr2 &&
259+ echo Hello >$rr2/preimage &&
260+ test-tool chmtime =$just_over_15_days_ago $rr2/preimage &&
261+
262+ git rerere gc --skip-locked &&
263+ test_path_is_missing $rr2/preimage
264+ '
265+
266+ test_expect_success ' --skip-locked is only accepted by gc' '
267+ test_must_fail git rerere --skip-locked clear 2>err &&
268+ test_grep "option .--skip-locked. requires .gc." err
269+ '
270+
271+ test_expect_success ' a held lock is waited out within rerere.lockTimeout' '
272+ git reset --hard &&
273+ rm -rf $rr &&
274+ test_when_finished "wait && rm -f .git/MERGE_RR.lock" &&
275+ >.git/MERGE_RR.lock &&
276+ {
277+ ( sleep 1 && rm -f .git/MERGE_RR.lock ) &
278+ } &&
279+ test_must_fail git -c rerere.lockTimeout=5000 merge first 2>err &&
280+ test_grep ! "Unable to create.*MERGE_RR\.lock" err &&
281+ test_grep "^=======\$" $rr/preimage
282+ '
283+
284+ test_expect_success ' merge fails on a lock it cannot take' '
285+ git reset --hard &&
286+ rm -rf $rr &&
287+ test_when_finished "rm -f .git/MERGE_RR.lock" &&
288+ >.git/MERGE_RR.lock &&
289+ test_must_fail git -c rerere.lockTimeout=0 merge first 2>err &&
290+ test_grep "Unable to create.*MERGE_RR\.lock" err &&
291+ test_grep "^=======\$" a1 &&
292+ test_path_is_missing $rr/preimage
293+ '
294+
295+ test_expect_success ' rerere, forget, clear and gc fail on a lock they cannot take' '
296+ test_when_finished "rm -f .git/MERGE_RR.lock" &&
297+ >.git/MERGE_RR.lock &&
298+ test_must_fail git -c rerere.lockTimeout=0 rerere 2>err &&
299+ test_grep "Unable to create.*MERGE_RR\.lock" err &&
300+ test_must_fail git -c rerere.lockTimeout=0 rerere forget a1 2>err &&
301+ test_grep "Unable to create.*MERGE_RR\.lock" err &&
302+ test_must_fail git -c rerere.lockTimeout=0 rerere clear 2>err &&
303+ test_grep "Unable to create.*MERGE_RR\.lock" err &&
304+ test_must_fail git -c rerere.lockTimeout=0 rerere gc 2>err &&
305+ test_grep "Unable to create.*MERGE_RR\.lock" err
306+ '
307+
308+ test_expect_success ' rebase --abort fails on a lock it cannot take' '
309+ git reset --hard &&
310+ git checkout -b lock-held-abort third &&
311+ test_when_finished "git checkout third && git branch -D lock-held-abort" &&
312+ test_must_fail git rebase first &&
313+ test_when_finished "test_might_fail git rebase --abort" &&
314+ test_when_finished "rm -f .git/MERGE_RR.lock" &&
315+ >.git/MERGE_RR.lock &&
316+ test_must_fail git -c rerere.lockTimeout=0 rebase --abort 2>err &&
317+ test_grep "Unable to create.*MERGE_RR\.lock" err &&
318+ test_path_is_dir .git/rebase-merge &&
319+ rm .git/MERGE_RR.lock &&
320+ git rebase --abort &&
321+ test_path_is_missing .git/rebase-merge
322+ '
323+
245324rerere_gc_custom_expiry_test () {
246325 five_days=" $1 " right_now=" $2 "
247326 test_expect_success " rerere gc with custom expiry ($five_days , $right_now )" '
0 commit comments