tests: don't assume a .git/info for .git/info/attributes

Change those tests that assumed that a .git/info directory would be created for them when writing .git/info/attributes to explicitly create the directory by setting "TEST_CREATE_REPO_NO_TEMPLATE=1" before sourcing test-lib.sh, and using the "--template=" argument to "git clone". The change here in here in t7814-grep-recurse-submodules.sh would continue "succeeding" with only the "TEST_CREATE_REPO_NO_TEMPLATE=1" part of this change. That's because those tests use "test_expect_failure", so they'd "pass" without this change, as "test_expect_failure" by design isn't discerning about what failure conditions it'll accept. But as we're fixing these sorts of issues across the test suite let's fix this one too. This issue was spotted with a local merge with another topic of mine[1], which introduces a stricter alternative to "test_expect_failure". 1. https://lore.kernel.org/git/cover-0.7-00000000000-20220318T002951Z-avarab@gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jun 3, 2022 at 13:15 UTC 8da0b02d9911d483d34ad8994c879953eebd345c
7 files changed +28 -7
t/t0003-attributes.sh
+4 -1
@@ -3,6 +3,7 @@
3 test_description=gitattributes
4
5 TEST_PASSES_SANITIZE_LEAK=true
6 +TEST_CREATE_REPO_NO_TEMPLATE=1
7 . ./test-lib.sh
8
9 attr_check_basic () {
@@ -284,7 +285,7 @@ test_expect_success 'using --git-dir and --work-tree' '
285 '
286
287 test_expect_success 'setup bare' '
287 - git clone --bare . bare.git
288 + git clone --template= --bare . bare.git
289 '
290
291 test_expect_success 'bare repository: check that .gitattribute is ignored' '
@@ -315,6 +316,7 @@ test_expect_success 'bare repository: check that --cached honors index' '
316 test_expect_success 'bare repository: test info/attributes' '
317 (
318 cd bare.git &&
319 + mkdir info &&
320 (
321 echo "f test=f" &&
322 echo "a/i test=a/i"
@@ -360,6 +362,7 @@ test_expect_success SYMLINKS 'symlinks respected in core.attributesFile' '
362
363 test_expect_success SYMLINKS 'symlinks respected in info/attributes' '
364 test_when_finished "rm .git/info/attributes" &&
365 + mkdir .git/info &&
366 ln -s ../../attr .git/info/attributes &&
367 attr_check file set
368 '
t/t0028-working-tree-encoding.sh
+2
@@ -5,6 +5,7 @@ test_description='working-tree-encoding conversion via gitattributes'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 +TEST_CREATE_REPO_NO_TEMPLATE=1
9 . ./test-lib.sh
10 . "$TEST_DIRECTORY/lib-encoding.sh"
11
@@ -69,6 +70,7 @@ test_expect_success 'check $GIT_DIR/info/attributes support' '
70 test_when_finished "rm -f test.utf32.git" &&
71 test_when_finished "git reset --hard HEAD" &&
72
73 + mkdir .git/info &&
74 echo "*.utf32 text working-tree-encoding=utf-32" >.git/info/attributes &&
75 git add test.utf32 &&
76
t/t5000-tar-tree.sh
+4 -1
@@ -24,6 +24,7 @@ commit id embedding:
24
25 '
26
27 +TEST_CREATE_REPO_NO_TEMPLATE=1
28 . ./test-lib.sh
29
30 SUBSTFORMAT=%H%n
@@ -143,6 +144,7 @@ test_expect_success 'populate workdir' '
144 test_expect_success \
145 'add ignored file' \
146 'echo ignore me >a/ignored &&
147 + mkdir .git/info &&
148 echo ignored export-ignore >.git/info/attributes'
149
150 test_expect_success 'add files to repository' '
@@ -157,7 +159,8 @@ test_expect_success 'setup export-subst' '
159 '
160
161 test_expect_success 'create bare clone' '
160 - git clone --bare . bare.git &&
162 + git clone --template= --bare . bare.git &&
163 + mkdir bare.git/info &&
164 cp .git/info/attributes bare.git/info/attributes
165 '
166
t/t5001-archive-attr.sh
+4 -1
@@ -2,6 +2,7 @@
2
3 test_description='git archive attribute tests'
4
5 +TEST_CREATE_REPO_NO_TEMPLATE=1
6 . ./test-lib.sh
7
8 SUBSTFORMAT='%H (%h)%n'
@@ -20,6 +21,7 @@ extract_tar_to_dir () {
21
22 test_expect_success 'setup' '
23 echo ignored >ignored &&
24 + mkdir .git/info &&
25 echo ignored export-ignore >>.git/info/attributes &&
26 git add ignored &&
27
@@ -46,7 +48,8 @@ test_expect_success 'setup' '
48
49 git commit -m. &&
50
49 - git clone --bare . bare &&
51 + git clone --template= --bare . bare &&
52 + mkdir bare/info &&
53 cp .git/info/attributes bare/info/attributes
54 '
55
t/t5002-archive-attr-pattern.sh
+4 -1
@@ -3,6 +3,7 @@
3 test_description='git archive attribute pattern tests'
4
5 TEST_PASSES_SANITIZE_LEAK=true
6 +TEST_CREATE_REPO_NO_TEMPLATE=1
7 . ./test-lib.sh
8
9 test_expect_exists() {
@@ -15,6 +16,7 @@ test_expect_missing() {
16
17 test_expect_success 'setup' '
18 echo ignored >ignored &&
19 + mkdir .git/info &&
20 echo ignored export-ignore >>.git/info/attributes &&
21 git add ignored &&
22
@@ -54,7 +56,8 @@ test_expect_success 'setup' '
56
57 git commit -m. &&
58
57 - git clone --bare . bare &&
59 + git clone --template= --bare . bare &&
60 + mkdir bare/info &&
61 cp .git/info/attributes bare/info/attributes
62 '
63
t/t5003-archive-zip.sh
+4 -1
@@ -2,6 +2,7 @@
2
3 test_description='git archive --format=zip test'
4
5 +TEST_CREATE_REPO_NO_TEMPLATE=1
6 . ./test-lib.sh
7
8 SUBSTFORMAT=%H%n
@@ -121,6 +122,7 @@ test_expect_success 'prepare file list' '
122 test_expect_success \
123 'add ignored file' \
124 'echo ignore me >a/ignored &&
125 + mkdir .git/info &&
126 echo ignored export-ignore >.git/info/attributes'
127
128 test_expect_success 'add files to repository' '
@@ -139,7 +141,8 @@ test_expect_success 'setup export-subst and diff attributes' '
141 '
142
143 test_expect_success 'create bare clone' '
142 - git clone --bare . bare.git &&
144 + git clone --template= --bare . bare.git &&
145 + mkdir bare.git/info &&
146 cp .git/info/attributes bare.git/info/attributes &&
147 # Recreate our changes to .git/config rather than just copying it, as
148 # we do not want to clobber core.bare or other settings.
t/t7814-grep-recurse-submodules.sh
+6 -2
@@ -6,6 +6,7 @@ This test verifies the recurse-submodules feature correctly greps across
6 submodules.
7 '
8
9 +TEST_CREATE_REPO_NO_TEMPLATE=1
10 . ./test-lib.sh
11
12 GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
@@ -471,8 +472,10 @@ test_expect_failure 'grep --textconv: superproject .gitattributes (from index) d
472 test_expect_failure 'grep --textconv: superproject .git/info/attributes does not affect submodules' '
473 reset_and_clean &&
474 test_config_global diff.d2x.textconv "sed -e \"s/d/x/\"" &&
474 - super_attr="$(git rev-parse --git-path info/attributes)" &&
475 + super_info="$(git rev-parse --git-path info)" &&
476 + super_attr="$super_info/attributes" &&
477 test_when_finished "rm -f \"$super_attr\"" &&
478 + mkdir "$super_info" &&
479 echo "a diff=d2x" >"$super_attr" &&
480
481 cat >expect <<-\EOF &&
@@ -516,7 +519,8 @@ test_expect_failure 'grep --textconv correctly reads submodule .git/info/attribu
519 reset_and_clean &&
520 test_config_global diff.d2x.textconv "sed -e \"s/d/x/\"" &&
521
519 - submodule_attr="$(git -C submodule rev-parse --path-format=absolute --git-path info/attributes)" &&
522 + submodule_info="$(git -C submodule rev-parse --path-format=absolute --git-path info)" &&
523 + submodule_attr="$submodule_info/attributes" &&
524 test_when_finished "rm -f \"$submodule_attr\"" &&
525 echo "a diff=d2x" >"$submodule_attr" &&
526