mirror of
https://github.com/git/git
synced 2024-09-12 21:04:12 +00:00
2e5d6503bd
Since commite77aa336f1
("ls-files: optionally recurse into submodules", 2016-10-07) ls-files has known how to recurse into submodules when displaying files. Unfortunately this fails for certain cases, including when nesting more than one submodule, called from within a submodule that itself has submodules, or when the GIT_DIR environemnt variable is set. Prior to commitb58a68c1c1
("setup: allow for prefix to be passed to git commands", 2017-03-17) this resulted in an error indicating that --prefix and --super-prefix were incompatible. After this commit, instead, the process loops forever with a GIT_DIR set to the parent and continuously reads the parent submodule files and recursing forever. Fix this by preparing the environment properly for submodules when setting up the child process. This is similar to how other commands such as grep behave. This was not caught by the original tests because the scenario is avoided if the submodules are created separately and not stored as the standard method of putting the submodule git directory under .git/modules/<name>. We can update the test to show the failure by the addition of "git submodule absorbgitdirs" to the test case. However, note that this new test would run forever without the necessary fix in this patch. Signed-off-by: Jacob Keller <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
251 lines
5.7 KiB
Bash
Executable file
251 lines
5.7 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
test_description='Test ls-files recurse-submodules feature
|
|
|
|
This test verifies the recurse-submodules feature correctly lists files from
|
|
submodules.
|
|
'
|
|
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success 'setup directory structure and submodules' '
|
|
echo a >a &&
|
|
mkdir b &&
|
|
echo b >b/b &&
|
|
git add a b &&
|
|
git commit -m "add a and b" &&
|
|
git init submodule &&
|
|
echo c >submodule/c &&
|
|
git -C submodule add c &&
|
|
git -C submodule commit -m "add c" &&
|
|
git submodule add ./submodule &&
|
|
git commit -m "added submodule"
|
|
'
|
|
|
|
test_expect_success 'ls-files correctly outputs files in submodule' '
|
|
cat >expect <<-\EOF &&
|
|
.gitmodules
|
|
a
|
|
b/b
|
|
submodule/c
|
|
EOF
|
|
|
|
git ls-files --recurse-submodules >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'ls-files correctly outputs files in submodule with -z' '
|
|
lf_to_nul >expect <<-\EOF &&
|
|
.gitmodules
|
|
a
|
|
b/b
|
|
submodule/c
|
|
EOF
|
|
|
|
git ls-files --recurse-submodules -z >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'ls-files does not output files not added to a repo' '
|
|
cat >expect <<-\EOF &&
|
|
.gitmodules
|
|
a
|
|
b/b
|
|
submodule/c
|
|
EOF
|
|
|
|
echo a >not_added &&
|
|
echo b >b/not_added &&
|
|
echo c >submodule/not_added &&
|
|
git ls-files --recurse-submodules >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'ls-files recurses more than 1 level' '
|
|
cat >expect <<-\EOF &&
|
|
.gitmodules
|
|
a
|
|
b/b
|
|
submodule/.gitmodules
|
|
submodule/c
|
|
submodule/subsub/d
|
|
EOF
|
|
|
|
git init submodule/subsub &&
|
|
echo d >submodule/subsub/d &&
|
|
git -C submodule/subsub add d &&
|
|
git -C submodule/subsub commit -m "add d" &&
|
|
git -C submodule submodule add ./subsub &&
|
|
git -C submodule commit -m "added subsub" &&
|
|
git submodule absorbgitdirs &&
|
|
git ls-files --recurse-submodules >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success '--recurse-submodules and pathspecs setup' '
|
|
echo e >submodule/subsub/e.txt &&
|
|
git -C submodule/subsub add e.txt &&
|
|
git -C submodule/subsub commit -m "adding e.txt" &&
|
|
echo f >submodule/f.TXT &&
|
|
echo g >submodule/g.txt &&
|
|
git -C submodule add f.TXT g.txt &&
|
|
git -C submodule commit -m "add f and g" &&
|
|
echo h >h.txt &&
|
|
mkdir sib &&
|
|
echo sib >sib/file &&
|
|
git add h.txt sib/file &&
|
|
git commit -m "add h and sib/file" &&
|
|
git init sub &&
|
|
echo sub >sub/file &&
|
|
git -C sub add file &&
|
|
git -C sub commit -m "add file" &&
|
|
git submodule add ./sub &&
|
|
git commit -m "added sub" &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
.gitmodules
|
|
a
|
|
b/b
|
|
h.txt
|
|
sib/file
|
|
sub/file
|
|
submodule/.gitmodules
|
|
submodule/c
|
|
submodule/f.TXT
|
|
submodule/g.txt
|
|
submodule/subsub/d
|
|
submodule/subsub/e.txt
|
|
EOF
|
|
|
|
git ls-files --recurse-submodules >actual &&
|
|
test_cmp expect actual &&
|
|
cat actual &&
|
|
git ls-files --recurse-submodules "*" >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success '--recurse-submodules and pathspecs' '
|
|
cat >expect <<-\EOF &&
|
|
h.txt
|
|
submodule/g.txt
|
|
submodule/subsub/e.txt
|
|
EOF
|
|
|
|
git ls-files --recurse-submodules "*.txt" >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success '--recurse-submodules and pathspecs' '
|
|
cat >expect <<-\EOF &&
|
|
h.txt
|
|
submodule/f.TXT
|
|
submodule/g.txt
|
|
submodule/subsub/e.txt
|
|
EOF
|
|
|
|
git ls-files --recurse-submodules ":(icase)*.txt" >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success '--recurse-submodules and pathspecs' '
|
|
cat >expect <<-\EOF &&
|
|
h.txt
|
|
submodule/f.TXT
|
|
submodule/g.txt
|
|
EOF
|
|
|
|
git ls-files --recurse-submodules ":(icase)*.txt" ":(exclude)submodule/subsub/*" >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success '--recurse-submodules and pathspecs' '
|
|
cat >expect <<-\EOF &&
|
|
sub/file
|
|
EOF
|
|
|
|
git ls-files --recurse-submodules "sub" >actual &&
|
|
test_cmp expect actual &&
|
|
git ls-files --recurse-submodules "sub/" >actual &&
|
|
test_cmp expect actual &&
|
|
git ls-files --recurse-submodules "sub/file" >actual &&
|
|
test_cmp expect actual &&
|
|
git ls-files --recurse-submodules "su*/file" >actual &&
|
|
test_cmp expect actual &&
|
|
git ls-files --recurse-submodules "su?/file" >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success '--recurse-submodules and pathspecs' '
|
|
cat >expect <<-\EOF &&
|
|
sib/file
|
|
sub/file
|
|
EOF
|
|
|
|
git ls-files --recurse-submodules "s??/file" >actual &&
|
|
test_cmp expect actual &&
|
|
git ls-files --recurse-submodules "s???file" >actual &&
|
|
test_cmp expect actual &&
|
|
git ls-files --recurse-submodules "s*file" >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success '--recurse-submodules and relative paths' '
|
|
# From subdir
|
|
cat >expect <<-\EOF &&
|
|
b
|
|
EOF
|
|
git -C b ls-files --recurse-submodules >actual &&
|
|
test_cmp expect actual &&
|
|
|
|
# Relative path to top
|
|
cat >expect <<-\EOF &&
|
|
../.gitmodules
|
|
../a
|
|
b
|
|
../h.txt
|
|
../sib/file
|
|
../sub/file
|
|
../submodule/.gitmodules
|
|
../submodule/c
|
|
../submodule/f.TXT
|
|
../submodule/g.txt
|
|
../submodule/subsub/d
|
|
../submodule/subsub/e.txt
|
|
EOF
|
|
git -C b ls-files --recurse-submodules -- .. >actual &&
|
|
test_cmp expect actual &&
|
|
|
|
# Relative path to submodule
|
|
cat >expect <<-\EOF &&
|
|
../submodule/.gitmodules
|
|
../submodule/c
|
|
../submodule/f.TXT
|
|
../submodule/g.txt
|
|
../submodule/subsub/d
|
|
../submodule/subsub/e.txt
|
|
EOF
|
|
git -C b ls-files --recurse-submodules -- ../submodule >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success '--recurse-submodules does not support --error-unmatch' '
|
|
test_must_fail git ls-files --recurse-submodules --error-unmatch 2>actual &&
|
|
test_i18ngrep "does not support --error-unmatch" actual
|
|
'
|
|
|
|
test_incompatible_with_recurse_submodules () {
|
|
test_expect_success "--recurse-submodules and $1 are incompatible" "
|
|
test_must_fail git ls-files --recurse-submodules $1 2>actual &&
|
|
test_i18ngrep 'unsupported mode' actual
|
|
"
|
|
}
|
|
|
|
test_incompatible_with_recurse_submodules --deleted
|
|
test_incompatible_with_recurse_submodules --modified
|
|
test_incompatible_with_recurse_submodules --others
|
|
test_incompatible_with_recurse_submodules --stage
|
|
test_incompatible_with_recurse_submodules --killed
|
|
test_incompatible_with_recurse_submodules --unmerged
|
|
|
|
test_done
|