Skip to content

Commit f64e635

Browse files
committed
Merge branch 'js/adjust-tests-to-explicitly-access-bare-repo' into seen
Some tests assume that bare repository accesses are by default allowed; rewrite some of them to avoid the assumption, rewrite others to explicitly set safe.bareRepository to allow them. Comments? * js/adjust-tests-to-explicitly-access-bare-repo: git p4 clone --bare: need to be explicit about the gitdir t9700: stop relying on implicit bare repo discovery t9210: pass `safe.bareRepository=all` to `scalar register` t6020: use `-C` for worktree, `--git-dir` for bare repository t5619: wrap `test_commit_bulk` in `GIT_DIR` subshell for bare repo t5540/t5541: avoid accessing a bare repository via `-C <dir>` t5509: specify bare repository path explicitly t5505: export `GIT_DIR` after `git init --bare` t5503: avoid discovering a bare repository t2406: use `--git-dir=.` for bare repository worktree repair t2400: explicitly specify bare repo for `git worktree add` t1900: avoid using `-C <dir>` for a bare repository t1020: use `--git-dir` instead of subshell for bare repo t0056: allow implicit bare repo discovery for `-C` work-tree tests t0003: use `--git-dir` for bare repo attribute tests t0001: replace `cd`+`git` with `git --git-dir` in `check_config` t0001: allow implicit bare repo discovery for aliased-command test
2 parents 38a323e + 347da97 commit f64e635

16 files changed

+74
-93
lines changed

git-p4.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4360,6 +4360,7 @@ def run(self, args):
43604360
init_cmd = ["git", "init"]
43614361
if self.cloneBare:
43624362
init_cmd.append("--bare")
4363+
os.environ["GIT_DIR"] = os.getcwd()
43634364
retcode = subprocess.call(init_cmd)
43644365
if retcode:
43654366
raise subprocess.CalledProcessError(retcode, init_cmd)

t/lib-httpd.sh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ test_http_push_nonff () {
259259

260260
test_expect_success 'non-fast-forward push fails' '
261261
cd "$REMOTE_REPO" &&
262-
HEAD=$(git rev-parse --verify HEAD) &&
262+
HEAD=$(git --git-dir=. rev-parse --verify HEAD) &&
263263
264264
cd "$LOCAL_REPO" &&
265265
git checkout $BRANCH &&
@@ -270,7 +270,7 @@ test_http_push_nonff () {
270270
(
271271
cd "$REMOTE_REPO" &&
272272
echo "$HEAD" >expect &&
273-
git rev-parse --verify HEAD >actual &&
273+
git --git-dir=. rev-parse --verify HEAD >actual &&
274274
test_cmp expect actual
275275
)
276276
'
@@ -284,18 +284,16 @@ test_http_push_nonff () {
284284
'
285285

286286
test_expect_${EXPECT_CAS_RESULT} 'force with lease aka cas' '
287-
HEAD=$( cd "$REMOTE_REPO" && git rev-parse --verify HEAD ) &&
287+
HEAD=$(git --git-dir="$REMOTE_REPO" rev-parse --verify HEAD) &&
288288
test_when_finished '\''
289-
(cd "$REMOTE_REPO" && git update-ref HEAD "$HEAD")
289+
git --git-dir="$REMOTE_REPO" update-ref HEAD "$HEAD"
290290
'\'' &&
291291
(
292292
cd "$LOCAL_REPO" &&
293293
git push -v --force-with-lease=$BRANCH:$HEAD origin
294294
) &&
295295
git rev-parse --verify "$BRANCH" >expect &&
296-
(
297-
cd "$REMOTE_REPO" && git rev-parse --verify HEAD
298-
) >actual &&
296+
git --git-dir="$REMOTE_REPO" rev-parse --verify HEAD >actual &&
299297
test_cmp expect actual
300298
'
301299
}

t/t0001-init.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ check_config () {
2020
return 1
2121
fi
2222

23-
bare=$(cd "$1" && git config --bool core.bare)
24-
worktree=$(cd "$1" && git config core.worktree) ||
23+
bare=$(git --git-dir="$1" config --bool core.bare)
24+
worktree=$(git --git-dir="$1" config core.worktree) ||
2525
worktree=unset
2626

2727
test "$bare" = "$2" && test "$worktree" = "$3" || {
@@ -77,6 +77,7 @@ test_expect_success 'plain nested through aliased command' '
7777
'
7878

7979
test_expect_success 'plain nested in bare through aliased command' '
80+
test_config_global safe.bareRepository all &&
8081
(
8182
git init --bare bare-ancestor-aliased.git &&
8283
cd bare-ancestor-aliased.git &&

t/t0003-attributes.sh

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,14 @@ test_expect_success 'setup bare' '
346346

347347
test_expect_success 'bare repository: check that .gitattribute is ignored' '
348348
(
349-
cd bare.git &&
350-
(
351-
echo "f test=f" &&
352-
echo "a/i test=a/i"
353-
) >.gitattributes &&
354-
attr_check f unspecified &&
355-
attr_check a/f unspecified &&
356-
attr_check a/c/f unspecified &&
357-
attr_check a/i unspecified &&
358-
attr_check subdir/a/i unspecified
359-
)
349+
echo "f test=f" &&
350+
echo "a/i test=a/i"
351+
) >bare.git/.gitattributes &&
352+
attr_check f unspecified --git-dir=bare.git &&
353+
attr_check a/f unspecified --git-dir=bare.git &&
354+
attr_check a/c/f unspecified --git-dir=bare.git &&
355+
attr_check a/i unspecified --git-dir=bare.git &&
356+
attr_check subdir/a/i unspecified --git-dir=bare.git
360357
'
361358

362359
bad_attr_source_err="fatal: bad --attr-source or GIT_ATTR_SOURCE"
@@ -449,41 +446,32 @@ test_expect_success 'diff without repository with attr source' '
449446
'
450447

451448
test_expect_success 'bare repository: with --source' '
452-
(
453-
cd bare.git &&
454-
attr_check_source foo/bar/f f tag-1 &&
455-
attr_check_source foo/bar/a/i n tag-1 &&
456-
attr_check_source foo/bar/f unspecified tag-2 &&
457-
attr_check_source foo/bar/a/i m tag-2 &&
458-
attr_check_source foo/bar/g g tag-2 &&
459-
attr_check_source foo/bar/g unspecified tag-1
460-
)
449+
attr_check_source foo/bar/f f tag-1 --git-dir=bare.git &&
450+
attr_check_source foo/bar/a/i n tag-1 --git-dir=bare.git &&
451+
attr_check_source foo/bar/f unspecified tag-2 --git-dir=bare.git &&
452+
attr_check_source foo/bar/a/i m tag-2 --git-dir=bare.git &&
453+
attr_check_source foo/bar/g g tag-2 --git-dir=bare.git &&
454+
attr_check_source foo/bar/g unspecified tag-1 --git-dir=bare.git
461455
'
462456

463457
test_expect_success 'bare repository: check that --cached honors index' '
464-
(
465-
cd bare.git &&
466-
GIT_INDEX_FILE=../.git/index \
467-
git check-attr --cached --stdin --all <../stdin-all |
468-
sort >actual &&
469-
test_cmp ../specified-all actual
470-
)
458+
GIT_INDEX_FILE=.git/index \
459+
git --git-dir=bare.git check-attr --cached --stdin --all <stdin-all |
460+
sort >actual &&
461+
test_cmp specified-all actual
471462
'
472463

473464
test_expect_success 'bare repository: test info/attributes' '
465+
mkdir -p bare.git/info &&
474466
(
475-
cd bare.git &&
476-
mkdir info &&
477-
(
478-
echo "f test=f" &&
479-
echo "a/i test=a/i"
480-
) >info/attributes &&
481-
attr_check f f &&
482-
attr_check a/f f &&
483-
attr_check a/c/f f &&
484-
attr_check a/i a/i &&
485-
attr_check subdir/a/i unspecified
486-
)
467+
echo "f test=f" &&
468+
echo "a/i test=a/i"
469+
) >bare.git/info/attributes &&
470+
attr_check f f --git-dir=bare.git &&
471+
attr_check a/f f --git-dir=bare.git &&
472+
attr_check a/c/f f --git-dir=bare.git &&
473+
attr_check a/i a/i --git-dir=bare.git &&
474+
attr_check subdir/a/i unspecified --git-dir=bare.git
487475
'
488476

489477
test_expect_success 'binary macro expanded by -a' '

t/t0056-git-C.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ test_expect_success 'Order should not matter: "--git-dir=a.git -C c" is equivale
5757
test_expect_success 'Effect on --work-tree option: "-C c/a.git --work-tree=../a" is equivalent to "--work-tree=c/a --git-dir=c/a.git"' '
5858
rm c/a/a.txt &&
5959
git --git-dir=c/a.git --work-tree=c/a status >expected &&
60+
test_config_global safe.bareRepository all &&
6061
git -C c/a.git --work-tree=../a status >actual &&
6162
test_cmp expected actual
6263
'
6364

6465
test_expect_success 'Order should not matter: "--work-tree=../a -C c/a.git" is equivalent to "-C c/a.git --work-tree=../a"' '
66+
test_config_global safe.bareRepository all &&
6567
git -C c/a.git --work-tree=../a status >expected &&
6668
git --work-tree=../a -C c/a.git status >actual &&
6769
test_cmp expected actual

t/t1020-subdirectory.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,7 @@ test_expect_success 'no file/rev ambiguity check inside a bare repo (explicit GI
177177
test_expect_success 'no file/rev ambiguity check inside a bare repo' '
178178
test_when_finished "rm -fr foo.git" &&
179179
git clone -s --bare .git foo.git &&
180-
(
181-
cd foo.git &&
182-
git show -s HEAD
183-
)
180+
git --git-dir=foo.git show -s HEAD
184181
'
185182

186183
test_expect_success SYMLINKS 'detection should not be fooled by a symlink' '

t/t1900-repo-info.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,21 @@ test_repo_info () {
2020
repo_name=$3
2121
key=$4
2222
expected_value=$5
23+
repo_flag=${6:--C}
2324

2425
test_expect_success "setup: $label" '
2526
eval "$init_command $repo_name"
2627
'
2728

2829
test_expect_success "lines: $label" '
2930
echo "$key=$expected_value" > expect &&
30-
git -C "$repo_name" repo info "$key" >actual &&
31+
git $repo_flag "$repo_name" repo info "$key" >actual &&
3132
test_cmp expect actual
3233
'
3334

3435
test_expect_success "nul: $label" '
3536
printf "%s\n%s\0" "$key" "$expected_value" >expect &&
36-
git -C "$repo_name" repo info --format=nul "$key" >actual &&
37+
git $repo_flag "$repo_name" repo info --format=nul "$key" >actual &&
3738
test_cmp_bin expect actual
3839
'
3940
}
@@ -48,7 +49,7 @@ test_repo_info 'bare repository = false is retrieved correctly' \
4849
'git init' 'nonbare' 'layout.bare' 'false'
4950

5051
test_repo_info 'bare repository = true is retrieved correctly' \
51-
'git init --bare' 'bare' 'layout.bare' 'true'
52+
'git init --bare' 'bare' 'layout.bare' 'true' '--git-dir'
5253

5354
test_repo_info 'shallow repository = false is retrieved correctly' \
5455
'git init' 'nonshallow' 'layout.shallow' 'false'

t/t2400-worktree-add.sh

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,8 @@ test_expect_success 'not die on re-checking out current branch' '
171171
'
172172

173173
test_expect_success '"add" from a bare repo' '
174-
(
175-
git clone --bare . bare &&
176-
cd bare &&
177-
git worktree add -b bare-main ../there2 main
178-
)
174+
git clone --bare . bare &&
175+
git -C bare --git-dir=. worktree add -b bare-main ../there2 main
179176
'
180177

181178
test_expect_success 'checkout from a bare repo without "add"' '
@@ -186,15 +183,11 @@ test_expect_success 'checkout from a bare repo without "add"' '
186183
'
187184

188185
test_expect_success '"add" default branch of a bare repo' '
189-
(
190-
git clone --bare . bare2 &&
191-
cd bare2 &&
192-
git worktree add ../there3 main &&
193-
cd ../there3 &&
194-
# Simple check that a Git command does not
195-
# immediately fail with the current setup
196-
git status
197-
) &&
186+
git clone --bare . bare2 &&
187+
git -C bare2 --git-dir=. worktree add ../there3 main &&
188+
# Simple check that a Git command does not
189+
# immediately fail with the current setup
190+
git status &&
198191
cat >expect <<-EOF &&
199192
init.t
200193
EOF

t/t2406-worktree-repair.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ test_expect_success 'repair .git file from bare.git' '
8484
git -C bare.git worktree add --detach ../corrupt &&
8585
git -C corrupt rev-parse --absolute-git-dir >expect &&
8686
rm -f corrupt/.git &&
87-
git -C bare.git worktree repair &&
87+
git -C bare.git --git-dir=. worktree repair &&
8888
git -C corrupt rev-parse --absolute-git-dir >actual &&
8989
test_cmp expect actual
9090
'

t/t5503-tagfollow.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,13 @@ test_expect_success 'new clone fetch main and tags' '
168168

169169
test_expect_success 'fetch specific OID with tag following' '
170170
git init --bare clone3.git &&
171-
(
172-
cd clone3.git &&
173-
git remote add origin .. &&
174-
git fetch origin $B:refs/heads/main &&
171+
git --git-dir=clone3.git remote add origin "$PWD" &&
172+
git --git-dir=clone3.git fetch origin $B:refs/heads/main &&
175173
176-
git -C .. for-each-ref >expect &&
177-
git for-each-ref >actual &&
174+
git for-each-ref >expect &&
175+
git --git-dir=clone3.git for-each-ref >actual &&
178176
179-
test_cmp expect actual
180-
)
177+
test_cmp expect actual
181178
'
182179

183180
test_done

0 commit comments

Comments
 (0)