Skip to content

Commit 6380576

Browse files
committed
tests: replace -C to --git-dir, dropping ../ prefixes as needed
An easy way to prepare the tests for a time when the `safe.bareRepository` default changes is to replaced `-C <dir>` with `--git-dir=<dir>` in those invocations that concern bare repositories. However, in some cases, further adjustments are required: since `-C` changes the work directory, relative paths specified in the Git command have to change, too. This commit takes care of the `git -C <dir>` invocations that specified paths in the current directory, via `../<name>` arguments. Naturally, these arguments now need to drop that `../` prefix. This commit can be verified mechanically via this awk script that applies the transformation on the old lines; empty output is success: git diff HEAD^! | awk ' /^diff/,/^\+\+\+/ { next } /^-/ { line = substr($0,2) # apply: -C X -> --git-dir=X and strip ../ if (match(line, /-C ([^ ]*)/, a)) { gsub(/-C [^ ]*/, "--git-dir=" a[1], line) } gsub(/\.\.\//, "", line) old[m++] = line } /^\+/ { new = substr($0,2); if (old[n++] != new) print old[n-1] " != " new }' Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent f9d49d6 commit 6380576

13 files changed

+27
-27
lines changed

t/t0001-init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ test_expect_success 'bare & --separate-git-dir incompatible within worktree' '
347347
test_when_finished "rm -rf bare.git linkwt seprepo" &&
348348
test_commit gumby &&
349349
git clone --bare . bare.git &&
350-
git -C bare.git worktree add --detach ../linkwt &&
350+
git --git-dir=bare.git worktree add --detach linkwt &&
351351
test_must_fail git -C linkwt init --separate-git-dir seprepo 2>err &&
352352
test_grep "incompatible" err
353353
'

t/t1091-sparse-checkout-builtin.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -991,8 +991,8 @@ test_expect_success 'check-rules cone mode' '
991991
EOF
992992
993993
git -C bare ls-tree -r --name-only HEAD >all-files &&
994-
git -C bare sparse-checkout check-rules --cone \
995-
--rules-file ../rules >check-rules-file <all-files &&
994+
git --git-dir=bare sparse-checkout check-rules --cone \
995+
--rules-file rules >check-rules-file <all-files &&
996996
997997
git -C repo sparse-checkout set --cone --stdin <rules&&
998998
git -C repo ls-files -t >out &&
@@ -1013,7 +1013,7 @@ test_expect_success 'check-rules non-cone mode' '
10131013
EOF
10141014
10151015
git -C bare ls-tree -r --name-only HEAD >all-files &&
1016-
git -C bare sparse-checkout check-rules --no-cone --rules-file ../rules\
1016+
git --git-dir=bare sparse-checkout check-rules --no-cone --rules-file rules\
10171017
>check-rules-file <all-files &&
10181018
10191019
git -C repo sparse-checkout set --no-cone --stdin <rules &&
@@ -1051,8 +1051,8 @@ test_expect_success 'check-rules cone mode is default' '
10511051
git -C repo sparse-checkout check-rules \
10521052
--rules-file ../rules >actual <all-files &&
10531053
1054-
git -C bare sparse-checkout check-rules \
1055-
--rules-file ../rules >actual-bare <all-files &&
1054+
git --git-dir=bare sparse-checkout check-rules \
1055+
--rules-file rules >actual-bare <all-files &&
10561056
10571057
test_cmp expect actual &&
10581058
test_cmp expect actual-bare

t/t2400-worktree-add.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ test_expect_success 'local clone from linked checkout' '
467467
'
468468

469469
test_expect_success 'local clone --shared from linked checkout' '
470-
git -C bare worktree add --detach ../baretree &&
470+
git --git-dir=bare worktree add --detach baretree &&
471471
git clone --local --shared baretree bare-clone &&
472472
grep /bare/ bare-clone/.git/objects/info/alternates
473473
'
@@ -1132,7 +1132,7 @@ test_expect_success '"add" in bare repo invokes post-checkout hook' '
11321132
echo $(pwd)/goozy
11331133
} >hook.expect &&
11341134
post_checkout_hook --git-dir bare &&
1135-
git -C bare worktree add --detach ../goozy &&
1135+
git --git-dir=bare worktree add --detach goozy &&
11361136
test_cmp hook.expect goozy/hook.actual
11371137
'
11381138

t/t2402-worktree-list.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ test_expect_success 'bare repo setup' '
211211

212212
test_expect_success '"list" all worktrees from bare main' '
213213
test_when_finished "rm -rf there out actual expect && git -C bare1 worktree prune" &&
214-
git -C bare1 worktree add --detach ../there main &&
214+
git --git-dir=bare1 worktree add --detach there main &&
215215
echo "$(pwd)/bare1 (bare)" >expect &&
216216
echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect &&
217217
git -C bare1 worktree list >out &&
@@ -221,7 +221,7 @@ test_expect_success '"list" all worktrees from bare main' '
221221

222222
test_expect_success '"list" all worktrees --porcelain from bare main' '
223223
test_when_finished "rm -rf there actual expect && git -C bare1 worktree prune" &&
224-
git -C bare1 worktree add --detach ../there main &&
224+
git --git-dir=bare1 worktree add --detach there main &&
225225
echo "worktree $(pwd)/bare1" >expect &&
226226
echo "bare" >>expect &&
227227
echo >>expect &&
@@ -235,7 +235,7 @@ test_expect_success '"list" all worktrees --porcelain from bare main' '
235235

236236
test_expect_success '"list" all worktrees from linked with a bare main' '
237237
test_when_finished "rm -rf there out actual expect && git -C bare1 worktree prune" &&
238-
git -C bare1 worktree add --detach ../there main &&
238+
git --git-dir=bare1 worktree add --detach there main &&
239239
echo "$(pwd)/bare1 (bare)" >expect &&
240240
echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect &&
241241
git -C there worktree list >out &&

t/t2406-worktree-repair.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ test_expect_success 'repair .git file from linked worktree' '
8181
test_expect_success 'repair .git file from bare.git' '
8282
test_when_finished "rm -rf bare.git corrupt && git worktree prune" &&
8383
git clone --bare . bare.git &&
84-
git -C bare.git worktree add --detach ../corrupt &&
84+
git --git-dir=bare.git worktree add --detach corrupt &&
8585
git -C corrupt rev-parse --absolute-git-dir >expect &&
8686
rm -f corrupt/.git &&
8787
(cd bare.git && GIT_DIR=. && export GIT_DIR &&

t/t3200-branch.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ test_expect_success 'bare main worktree has HEAD at branch deleted by secondary
406406
git init -b main nonbare &&
407407
test_commit -C nonbare x &&
408408
git clone --bare nonbare bare &&
409-
git -C bare worktree add --detach ../secondary main &&
409+
git --git-dir=bare worktree add --detach secondary main &&
410410
git -C secondary branch -D main
411411
'
412412

@@ -420,7 +420,7 @@ test_expect_success 'secondary worktrees recognize core.bare=true in main config
420420
git -C bare_repo config unset core.bare &&
421421
git -C bare_repo config --worktree core.bare true &&
422422
423-
git -C bare_repo worktree add ../secondary_worktree &&
423+
git --git-dir=bare_repo worktree add secondary_worktree &&
424424
git -C secondary_worktree checkout main
425425
'
426426

t/t5504-fetch-receive-strict.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ test_expect_success PERL_TEST_HELPERS 'badFilemode is not a strict error' '
372372
git init --bare dst.git &&
373373
git -C dst.git config transfer.fsckObjects true &&
374374
375-
git -C badmode.git push ../dst.git $tree:refs/tags/tree 2>err &&
375+
git --git-dir=badmode.git push dst.git $tree:refs/tags/tree 2>err &&
376376
grep "$tree: badFilemode" err
377377
'
378378

t/t5558-clone-bundle-uri.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ test_expect_success 'expand incremental bundle list' '
10351035
10361036
cp bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/"
10371037
) &&
1038-
git -C "$HTTPD_DOCUMENT_ROOT_PATH/fetch.git" fetch origin +refs/heads/*:refs/heads/*
1038+
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/fetch.git" fetch origin +refs/heads/*:refs/heads/*
10391039
'
10401040

10411041
test_expect_success 'creationToken heuristic with failed downloads (fetch)' '

t/t6020-bundle-misc.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,11 @@ test_expect_success 'fail to verify bundle without prerequisites' '
358358
error: <COMMIT-G> Z
359359
EOF
360360
361-
test_must_fail git -C test1.git bundle verify ../2.bdl 2>&1 |
361+
test_must_fail git --git-dir=test1.git bundle verify 2.bdl 2>&1 |
362362
make_user_friendly_and_stable_output >actual &&
363363
test_cmp expect actual &&
364364
365-
test_must_fail git -C test1.git bundle verify ../stdin-2.bdl 2>&1 |
365+
test_must_fail git --git-dir=test1.git bundle verify stdin-2.bdl 2>&1 |
366366
make_user_friendly_and_stable_output >actual &&
367367
test_cmp expect actual
368368
'
@@ -460,7 +460,7 @@ test_expect_success 'clone from bundle' '
460460
EOF
461461
test_cmp expect actual &&
462462
463-
git -C mirror.git fetch ../2.bdl "+refs/*:refs/*" &&
463+
git --git-dir=mirror.git fetch 2.bdl "+refs/*:refs/*" &&
464464
git -C mirror.git show-ref |
465465
make_user_friendly_and_stable_output >actual &&
466466
cat >expect <<-\EOF &&
@@ -470,7 +470,7 @@ test_expect_success 'clone from bundle' '
470470
EOF
471471
test_cmp expect actual &&
472472
473-
git -C mirror.git fetch ../3.bdl "+refs/*:refs/*" &&
473+
git --git-dir=mirror.git fetch 3.bdl "+refs/*:refs/*" &&
474474
git -C mirror.git show-ref |
475475
make_user_friendly_and_stable_output >actual &&
476476
cat >expect <<-\EOF &&
@@ -481,7 +481,7 @@ test_expect_success 'clone from bundle' '
481481
EOF
482482
test_cmp expect actual &&
483483
484-
git -C mirror.git fetch ../4.bdl "+refs/*:refs/*" &&
484+
git --git-dir=mirror.git fetch 4.bdl "+refs/*:refs/*" &&
485485
git -C mirror.git show-ref |
486486
make_user_friendly_and_stable_output >actual &&
487487
cat >expect <<-\EOF &&

t/t6500-gc.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ test_expect_success 'gc.repackFilterTo store filtered out objects' '
203203
test_when_finished "rm -rf bare.git filtered.git" &&
204204
205205
git init --bare filtered.git &&
206-
git -C bare.git -c gc.repackFilter=blob:none \
207-
-c gc.repackFilterTo=../filtered.git/objects/pack/pack \
206+
git --git-dir=bare.git -c gc.repackFilter=blob:none \
207+
-c gc.repackFilterTo=filtered.git/objects/pack/pack \
208208
-c repack.writeBitmaps=false -c gc.cruftPacks=false gc &&
209209
210210
test_stdout_line_count = 1 ls bare.git/objects/pack/*.pack &&

0 commit comments

Comments
 (0)