3 test_description
='git add -u
5 This test creates a working tree state with three files:
7 top (previously committed, modified)
8 dir/sub (previously committed, modified)
11 and issues a git add -u with path limiting on "dir" to add
12 only the updates to dir/sub.
14 Also tested are "git add -u" without limiting, and "git add -u"
15 without contents changes, and other conditions'
17 TEST_PASSES_SANITIZE_LEAK
=true
20 test_expect_success setup
'
21 echo initial >check &&
25 echo initial >dir1/sub1 &&
26 echo initial >dir1/sub2 &&
27 echo initial >dir2/sub3 &&
28 git add check dir1 dir2 top foo &&
30 git commit -m initial &&
32 echo changed >check &&
34 echo changed >dir2/sub3 &&
36 echo other >dir2/other
39 test_expect_success update
'
43 test_expect_success
'update noticed a removal' '
44 git ls-files dir1/sub1 >out &&
45 test_must_be_empty out
48 test_expect_success
'update touched correct path' '
49 git diff-files --name-status dir2/sub3 >out &&
50 test_must_be_empty out
53 test_expect_success
'update did not touch other tracked files' '
54 echo "M check" >expect &&
55 git diff-files --name-status check >actual &&
56 test_cmp expect actual &&
58 echo "M top" >expect &&
59 git diff-files --name-status top >actual &&
60 test_cmp expect actual
63 test_expect_success
'update did not touch untracked files' '
64 git ls-files dir2/other >out &&
65 test_must_be_empty out
68 test_expect_success
'cache tree has not been corrupted' '
71 sed -e "s/ 0 / /" >expect &&
72 git ls-tree -r $(git write-tree) |
73 sed -e "s/ blob / /" >current &&
74 test_cmp expect current
78 test_expect_success
'update from a subdirectory' '
86 test_expect_success
'change gets noticed' '
87 git diff-files --name-status dir1 >out &&
88 test_must_be_empty out
91 test_expect_success
'non-qualified update in subdir updates from the root' '
94 echo even more >>sub2 &&
95 git --literal-pathspecs add -u &&
96 echo even more >>sub2 &&
99 git diff-files --name-only >actual &&
100 test_must_be_empty actual
103 test_expect_success
'replace a file with a symlink' '
106 test_ln_s_add top foo
110 test_expect_success
'add everything changed' '
113 git diff-files >out &&
114 test_must_be_empty out
118 test_expect_success
'touch and then add -u' '
122 git diff-files >out &&
123 test_must_be_empty out
127 test_expect_success
'touch and then add explicitly' '
131 git diff-files >out &&
132 test_must_be_empty out
136 test_expect_success
'add -n -u should not add but just report' '
139 echo "add '\''check'\''" &&
140 echo "remove '\''top'\''"
142 before=$(git ls-files -s check top) &&
143 git count-objects -v >objects_before &&
144 echo changed >>check &&
146 git add -n -u >actual &&
147 after=$(git ls-files -s check top) &&
148 git count-objects -v >objects_after &&
150 test "$before" = "$after" &&
151 test_cmp objects_before objects_after &&
152 test_cmp expect actual
156 test_expect_success
'add -u resolves unmerged paths' '
158 one=$(echo 1 | git hash-object -w --stdin) &&
159 two=$(echo 2 | git hash-object -w --stdin) &&
160 three=$(echo 3 | git hash-object -w --stdin) &&
162 for path in path1 path2
164 echo "100644 $one 1 $path" &&
165 echo "100644 $two 2 $path" &&
166 echo "100644 $three 3 $path" || return 1
168 echo "100644 $one 1 path3" &&
169 echo "100644 $one 1 path4" &&
170 echo "100644 $one 3 path5" &&
171 echo "100644 $one 3 path6"
173 git update-index --index-info &&
178 # Fail to explicitly resolve removed paths with "git add"
179 test_must_fail git add --no-all path4 &&
180 test_must_fail git add --no-all path6 &&
182 # "add -u" should notice removals no matter what stages
183 # the index entries are in.
185 git ls-files -s path1 path2 path3 path4 path5 path6 >actual &&
187 echo "100644 $three 0 path1" &&
188 echo "100644 $two 0 path3" &&
189 echo "100644 $two 0 path5"
191 test_cmp expect actual
194 test_expect_success
'"add -u non-existent" should fail' '
195 test_must_fail git add -u non-existent &&
196 git ls-files >actual &&
197 ! grep "non-existent" actual
200 test_expect_success
'"commit -a" implies "add -u" if index becomes empty' '
202 git commit -m clean-slate &&
206 git commit -a -m remove &&
207 git ls-tree HEAD: >out &&
208 test_must_be_empty out