ls-files tests: add meaningful --with-tree tests
Add tests for "ls-files --with-tree". There was effectively no coverage for any normal usage of this command, only the tests added in 54e1abce90e (Add test case for ls-files --with-tree, 2007-10-03) for an obscure bug. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Mar 20, 2021 at 23:37 UTC
8de78218c53480ded696c751f922b0622697a8b0
1 file changed
+41
t/t3060-ls-files-with-tree.sh
+41
@@ -47,6 +47,12 @@ test_expect_success setup '
47
git add .
48
'
49
50
+test_expect_success 'usage' '
51
+ test_expect_code 128 git ls-files --with-tree=HEAD -u &&
52
+ test_expect_code 128 git ls-files --with-tree=HEAD -s &&
53
+ test_expect_code 128 git ls-files --recurse-submodules --with-tree=HEAD
54
+'
55
+
56
test_expect_success 'git ls-files --with-tree should succeed from subdir' '
57
# We have to run from a sub-directory to trigger prune_path
58
# Then we finally get to run our --with-tree test
@@ -60,4 +66,39 @@ test_expect_success \
66
'git ls-files --with-tree should add entries from named tree.' \
67
'test_cmp expected output'
68
69
+test_expect_success 'no duplicates in --with-tree output' '
70
+ git ls-files --with-tree=HEAD >actual &&
71
+ sort -u actual >expected &&
72
+ test_cmp expected actual
73
+'
74
+
75
+test_expect_success 'setup: output in a conflict' '
76
+ test_create_repo conflict &&
77
+ test_commit -C conflict BASE file &&
78
+ test_commit -C conflict A file foo &&
79
+ git -C conflict reset --hard BASE &&
80
+ test_commit -C conflict B file bar
81
+'
82
+
83
+test_expect_success 'output in a conflict' '
84
+ test_must_fail git -C conflict merge A B &&
85
+ cat >expected <<-\EOF &&
86
+ file
87
+ file
88
+ file
89
+ file
90
+ EOF
91
+ git -C conflict ls-files --with-tree=HEAD >actual &&
92
+ test_cmp expected actual
93
+'
94
+
95
+test_expect_success 'output with removed .git/index' '
96
+ cat >expected <<-\EOF &&
97
+ file
98
+ EOF
99
+ rm conflict/.git/index &&
100
+ git -C conflict ls-files --with-tree=HEAD >actual &&
101
+ test_cmp expected actual
102
+'
103
+
104
test_done