3 test_description
='git add in sparse checked out working trees'
9 # Optionally take a printf format string to write to the sparse_entry file
10 setup_sparse_entry
() {
11 # 'sparse_entry' might already be in the index with the skip-worktree
12 # bit set. Remove it so that the subsequent git add can update it.
13 git update-index
--force-remove sparse_entry
&&
16 printf "$1" >sparse_entry
20 git add sparse_entry
&&
21 git update-index
--skip-worktree sparse_entry
&&
22 SPARSE_ENTRY_BLOB
=$
(git rev-parse
:sparse_entry
)
25 test_sparse_entry_unchanged
() {
26 echo "100644 $SPARSE_ENTRY_BLOB 0 sparse_entry" >expected
&&
27 git ls-files
--stage sparse_entry
>actual
&&
28 test_cmp expected actual
32 test_when_finished
rm -f .gitignore
&&
33 cat >.gitignore
<<-EOF
39 test_expect_success
'setup' "
40 cat >sparse_error_header <<-EOF &&
41 The following pathspecs didn't match any eligible path, but they do match index
42 entries outside the current sparse checkout:
45 cat >sparse_hint <<-EOF &&
46 hint: Disable or modify the sparsity rules if you intend to update such entries.
47 hint: Disable this message with \"git config advice.updateSparsePath false\"
50 echo sparse_entry | cat sparse_error_header - >sparse_entry_error &&
51 cat sparse_entry_error sparse_hint >error_and_hint
54 test_expect_success
'git add does not remove sparse entries' '
57 test_must_fail git add sparse_entry 2>stderr &&
58 test_cmp error_and_hint stderr &&
59 test_sparse_entry_unchanged
62 test_expect_success
'git add -A does not remove sparse entries' '
66 git add -A 2>stderr &&
67 test_must_be_empty stderr &&
68 test_sparse_entry_unchanged
71 test_expect_success
'git add . does not remove sparse entries' '
75 test_must_fail git add . 2>stderr &&
77 cat sparse_error_header >expect &&
79 cat sparse_hint >>expect &&
81 test_cmp expect stderr &&
82 test_sparse_entry_unchanged
85 for opt
in "" -f -u --ignore-removal --dry-run
87 test_expect_success
"git add${opt:+ $opt} does not update sparse entries" '
89 echo modified >sparse_entry &&
90 test_must_fail git add $opt sparse_entry 2>stderr &&
91 test_cmp error_and_hint stderr &&
92 test_sparse_entry_unchanged
96 test_expect_success
'git add --refresh does not update sparse entries' '
98 git ls-files --debug sparse_entry | grep mtime >before &&
99 test-tool chmtime -60 sparse_entry &&
100 test_must_fail git add --refresh sparse_entry 2>stderr &&
101 test_cmp error_and_hint stderr &&
102 git ls-files --debug sparse_entry | grep mtime >after &&
103 test_cmp before after
106 test_expect_success
'git add --chmod does not update sparse entries' '
107 setup_sparse_entry &&
108 test_must_fail git add --chmod=+x sparse_entry 2>stderr &&
109 test_cmp error_and_hint stderr &&
110 test_sparse_entry_unchanged &&
111 ! test -x sparse_entry
114 test_expect_success
'git add --renormalize does not update sparse entries' '
115 test_config core.autocrlf false &&
116 setup_sparse_entry "LINEONE\r\nLINETWO\r\n" &&
117 echo "sparse_entry text=auto" >.gitattributes &&
118 test_must_fail git add --renormalize sparse_entry 2>stderr &&
119 test_cmp error_and_hint stderr &&
120 test_sparse_entry_unchanged
123 test_expect_success
'git add --dry-run --ignore-missing warn on sparse path' '
124 setup_sparse_entry &&
126 test_must_fail git add --dry-run --ignore-missing sparse_entry 2>stderr &&
127 test_cmp error_and_hint stderr &&
128 test_sparse_entry_unchanged
131 test_expect_success
'do not advice about sparse entries when they do not match the pathspec' '
132 setup_sparse_entry &&
133 test_must_fail git add nonexistent 2>stderr &&
134 grep "fatal: pathspec .nonexistent. did not match any files" stderr &&
135 ! grep -F -f sparse_error_header stderr
138 test_expect_success
'do not warn when pathspec matches dense entries' '
139 setup_sparse_entry &&
140 echo modified >sparse_entry &&
142 git add "*_entry" 2>stderr &&
143 test_must_be_empty stderr &&
144 test_sparse_entry_unchanged &&
145 git ls-files --error-unmatch dense_entry
148 test_expect_success
'add obeys advice.updateSparsePath' '
149 setup_sparse_entry &&
150 test_must_fail git -c advice.updateSparsePath=false add sparse_entry 2>stderr &&
151 test_cmp sparse_entry_error stderr