Skip to content

Commit 2c25781

Browse files
committed
tests: add set/unset GIT_DIR pairs where appropriate
There are quite a few tests that assume that the default of the `safe.bareRepository` setting is that it allows discovery of bare repositories. This is unsafe. To allow the default to change, this commit tackles a couple of places in the test suite: By setting GIT_DIR after changing the current working directory to the bare repository, Git no longer needs to discover it, and by unsetting GIT_DIR as soon as leaving said directory, Git once again returns to the regular programming of discovering the `.git` directory. This commit can be validated mechanically by running the following command-line: git diff HEAD^! | awk ' /^diff/,/^\+\+\+/ { next } /^-/ { old[m++] = substr($0,2) } /^\+/ { new = substr($0,2) # undo: strip GIT_DIR export gsub(/ GIT_DIR=[.] && export GIT_DIR &&/, "", new) # undo: strip sane_unset GIT_DIR gsub(/ && sane_unset GIT_DIR/, "", new) if (old[n++] != new) print old[n-1] " != " new }' Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent aeda526 commit 2c25781

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

t/t1400-update-ref.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ test_expect_success setup '
2929
git checkout --orphan main &&
3030
create_test_commits "" &&
3131
mkdir $bare &&
32-
cd $bare &&
32+
cd $bare && GIT_DIR=. && export GIT_DIR &&
3333
git init --bare -b main &&
3434
create_test_commits "bare" &&
35-
cd -
35+
cd - && sane_unset GIT_DIR
3636
'
3737

3838
test_expect_success "create $m" '

t/t1800-hook.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,9 @@ test_expect_success 'server hooks expect stdout redirected to stderr' '
533533
test_when_finished "rm -f stdout.actual stderr.actual" &&
534534
git init --bare remote-server &&
535535
git remote add origin-server remote-server &&
536-
cd remote-server &&
536+
cd remote-server && GIT_DIR=. && export GIT_DIR &&
537537
setup_hooks pre-receive update post-receive post-update &&
538-
cd .. &&
538+
cd .. && sane_unset GIT_DIR &&
539539
git push origin-server HEAD:new-branch >stdout.actual 2>stderr.actual &&
540540
check_stdout_merged_to_stderr pre-receive update post-receive post-update
541541
'

t/t2400-worktree-add.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ test_expect_success '"add" default branch of a bare repo' '
198198
test_expect_success '"add" to bare repo with worktree config' '
199199
(
200200
git clone --bare . bare3 &&
201-
cd bare3 &&
201+
cd bare3 && GIT_DIR=. && export GIT_DIR &&
202202
git config extensions.worktreeconfig true &&
203203
204204
# Add config values that are erroneous to have in
@@ -212,7 +212,7 @@ test_expect_success '"add" to bare repo with worktree config' '
212212
git config --worktree bogus.key value &&
213213
git config --unset core.bare &&
214214
git worktree add ../there4 main &&
215-
cd ../there4 &&
215+
cd ../there4 && sane_unset GIT_DIR &&
216216
217217
# Simple check that a Git command does not
218218
# immediately fail with the current setup

t/t5500-fetch-pack.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,11 @@ test_expect_success 'fetch in shallow repo unreachable shallow objects' '
454454
(
455455
git clone --bare --branch B --single-branch "file://$(pwd)/." no-reflog &&
456456
git clone --depth 1 "file://$(pwd)/no-reflog" shallow9 &&
457-
cd no-reflog &&
457+
cd no-reflog && GIT_DIR=. && export GIT_DIR &&
458458
git tag -d TAGB1 TAGB2 &&
459459
git update-ref refs/heads/B B~~ &&
460460
git gc --prune=now &&
461-
cd ../shallow9 &&
461+
cd ../shallow9 && sane_unset GIT_DIR &&
462462
git fetch origin &&
463463
git fsck --no-dangling
464464
)

t/t5540-http-push-webdav.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ test_expect_success 'setup remote repository' '
4040
git commit -m initial &&
4141
cd - &&
4242
git clone --bare test_repo test_repo.git &&
43-
cd test_repo.git &&
43+
cd test_repo.git && GIT_DIR=. && export GIT_DIR &&
4444
git --bare update-server-info &&
4545
test_hook --setup post-update <<-\EOF &&
4646
exec git update-server-info
4747
EOF
4848
ORIG_HEAD=$(git rev-parse --verify HEAD) &&
49-
cd - &&
49+
cd - && sane_unset GIT_DIR &&
5050
mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
5151
'
5252

t/t5541-http-push-smart.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ test_expect_success 'setup remote repository' '
2626
git commit -m initial &&
2727
cd - &&
2828
git clone --bare test_repo test_repo.git &&
29-
cd test_repo.git &&
29+
cd test_repo.git && GIT_DIR=. && export GIT_DIR &&
3030
git config http.receivepack true &&
3131
git config core.logallrefupdates true &&
3232
ORIG_HEAD=$(git rev-parse --verify HEAD) &&
33-
cd - &&
33+
cd - && sane_unset GIT_DIR &&
3434
mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
3535
'
3636

0 commit comments

Comments
 (0)