t3705: test that 'sparse_entry' is unstaged
The tests in t3705-add-sparse-checkout.sh check to see how 'git add' behaves with paths outside the sparse-checkout definition. These currently check to see if a given warning is present but not that the index is not updated with the sparse entries. Add a new 'test_sparse_entry_unstaged' helper to be sure 'git add' is behaving correctly. We need to modify setup_sparse_entry to actually commit the sparse_entry file so it exists at HEAD and as an entry in the index, but its exact contents are not staged in the index. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Sep 24, 2021 at 15:39 UTC
ca267aee15c79376ba861bfa47a3b2ad18e74d02
1 file changed
+14
t/t3705-add-sparse-checkout.sh
+14
@@ -19,6 +19,7 @@ setup_sparse_entry () {
19
fi &&
20
git add sparse_entry &&
21
git update-index --skip-worktree sparse_entry &&
22
+ git commit --allow-empty -m "ensure sparse_entry exists at HEAD" &&
23
SPARSE_ENTRY_BLOB=$(git rev-parse :sparse_entry)
24
}
25
@@ -36,6 +37,11 @@ setup_gitignore () {
37
EOF
38
}
39
40
+test_sparse_entry_unstaged () {
41
+ git diff --staged -- sparse_entry >diff &&
42
+ test_must_be_empty diff
43
+}
44
+
45
test_expect_success 'setup' "
46
cat >sparse_error_header <<-EOF &&
47
The following pathspecs didn't match any eligible path, but they do match index
@@ -55,6 +61,7 @@ test_expect_success 'git add does not remove sparse entries' '
61
setup_sparse_entry &&
62
rm sparse_entry &&
63
test_must_fail git add sparse_entry 2>stderr &&
64
+ test_sparse_entry_unstaged &&
65
test_cmp error_and_hint stderr &&
66
test_sparse_entry_unchanged
67
'
@@ -73,6 +80,7 @@ test_expect_success 'git add . does not remove sparse entries' '
80
rm sparse_entry &&
81
setup_gitignore &&
82
test_must_fail git add . 2>stderr &&
83
+ test_sparse_entry_unstaged &&
84
85
cat sparse_error_header >expect &&
86
echo . >>expect &&
@@ -88,6 +96,7 @@ do
96
setup_sparse_entry &&
97
echo modified >sparse_entry &&
98
test_must_fail git add $opt sparse_entry 2>stderr &&
99
+ test_sparse_entry_unstaged &&
100
test_cmp error_and_hint stderr &&
101
test_sparse_entry_unchanged
102
'
@@ -98,6 +107,7 @@ test_expect_success 'git add --refresh does not update sparse entries' '
107
git ls-files --debug sparse_entry | grep mtime >before &&
108
test-tool chmtime -60 sparse_entry &&
109
test_must_fail git add --refresh sparse_entry 2>stderr &&
110
+ test_sparse_entry_unstaged &&
111
test_cmp error_and_hint stderr &&
112
git ls-files --debug sparse_entry | grep mtime >after &&
113
test_cmp before after
@@ -106,6 +116,7 @@ test_expect_success 'git add --refresh does not update sparse entries' '
116
test_expect_success 'git add --chmod does not update sparse entries' '
117
setup_sparse_entry &&
118
test_must_fail git add --chmod=+x sparse_entry 2>stderr &&
119
+ test_sparse_entry_unstaged &&
120
test_cmp error_and_hint stderr &&
121
test_sparse_entry_unchanged &&
122
! test -x sparse_entry
@@ -116,6 +127,7 @@ test_expect_success 'git add --renormalize does not update sparse entries' '
127
setup_sparse_entry "LINEONE\r\nLINETWO\r\n" &&
128
echo "sparse_entry text=auto" >.gitattributes &&
129
test_must_fail git add --renormalize sparse_entry 2>stderr &&
130
+ test_sparse_entry_unstaged &&
131
test_cmp error_and_hint stderr &&
132
test_sparse_entry_unchanged
133
'
@@ -124,6 +136,7 @@ test_expect_success 'git add --dry-run --ignore-missing warn on sparse path' '
136
setup_sparse_entry &&
137
rm sparse_entry &&
138
test_must_fail git add --dry-run --ignore-missing sparse_entry 2>stderr &&
139
+ test_sparse_entry_unstaged &&
140
test_cmp error_and_hint stderr &&
141
test_sparse_entry_unchanged
142
'
@@ -148,6 +161,7 @@ test_expect_success 'do not warn when pathspec matches dense entries' '
161
test_expect_success 'add obeys advice.updateSparsePath' '
162
setup_sparse_entry &&
163
test_must_fail git -c advice.updateSparsePath=false add sparse_entry 2>stderr &&
164
+ test_sparse_entry_unstaged &&
165
test_cmp sparse_entry_error stderr
166
167
'