]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3007-ls-files-recurse-submodules.sh
ls-files: pass through safe options for --recurse-submodules
[thirdparty/git.git] / t / t3007-ls-files-recurse-submodules.sh
CommitLineData
e77aa336
BW
1#!/bin/sh
2
3test_description='Test ls-files recurse-submodules feature
4
5This test verifies the recurse-submodules feature correctly lists files from
6submodules.
7'
8
9. ./test-lib.sh
10
11test_expect_success 'setup directory structure and submodules' '
12 echo a >a &&
13 mkdir b &&
14 echo b >b/b &&
15 git add a b &&
16 git commit -m "add a and b" &&
17 git init submodule &&
18 echo c >submodule/c &&
19 git -C submodule add c &&
20 git -C submodule commit -m "add c" &&
21 git submodule add ./submodule &&
22 git commit -m "added submodule"
23'
24
25test_expect_success 'ls-files correctly outputs files in submodule' '
26 cat >expect <<-\EOF &&
27 .gitmodules
28 a
29 b/b
30 submodule/c
31 EOF
32
33 git ls-files --recurse-submodules >actual &&
34 test_cmp expect actual
35'
36
07c01b9f
BW
37test_expect_success 'ls-files correctly outputs files in submodule with -z' '
38 lf_to_nul >expect <<-\EOF &&
39 .gitmodules
40 a
41 b/b
42 submodule/c
43 EOF
44
45 git ls-files --recurse-submodules -z >actual &&
46 test_cmp expect actual
47'
48
e77aa336
BW
49test_expect_success 'ls-files does not output files not added to a repo' '
50 cat >expect <<-\EOF &&
51 .gitmodules
52 a
53 b/b
54 submodule/c
55 EOF
56
57 echo a >not_added &&
58 echo b >b/not_added &&
59 echo c >submodule/not_added &&
60 git ls-files --recurse-submodules >actual &&
61 test_cmp expect actual
62'
63
64test_expect_success 'ls-files recurses more than 1 level' '
65 cat >expect <<-\EOF &&
66 .gitmodules
67 a
68 b/b
69 submodule/.gitmodules
70 submodule/c
71 submodule/subsub/d
72 EOF
73
74 git init submodule/subsub &&
75 echo d >submodule/subsub/d &&
76 git -C submodule/subsub add d &&
77 git -C submodule/subsub commit -m "add d" &&
78 git -C submodule submodule add ./subsub &&
79 git -C submodule commit -m "added subsub" &&
80 git ls-files --recurse-submodules >actual &&
81 test_cmp expect actual
82'
83
84test_expect_success '--recurse-submodules does not support using path arguments' '
85 test_must_fail git ls-files --recurse-submodules b 2>actual &&
86 test_i18ngrep "does not support pathspec" actual
87'
88
89test_expect_success '--recurse-submodules does not support --error-unmatch' '
90 test_must_fail git ls-files --recurse-submodules --error-unmatch 2>actual &&
91 test_i18ngrep "does not support --error-unmatch" actual
92'
93
94test_incompatible_with_recurse_submodules () {
95 test_expect_success "--recurse-submodules and $1 are incompatible" "
96 test_must_fail git ls-files --recurse-submodules $1 2>actual &&
97 test_i18ngrep 'unsupported mode' actual
98 "
99}
100
e77aa336
BW
101test_incompatible_with_recurse_submodules --deleted
102test_incompatible_with_recurse_submodules --modified
103test_incompatible_with_recurse_submodules --others
104test_incompatible_with_recurse_submodules --stage
105test_incompatible_with_recurse_submodules --killed
106test_incompatible_with_recurse_submodules --unmerged
e77aa336
BW
107
108test_done