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'
19 test_expect_success setup
'
20 echo initial >check &&
24 echo initial >dir1/sub1 &&
25 echo initial >dir1/sub2 &&
26 echo initial >dir2/sub3 &&
27 git add check dir1 dir2 top foo &&
29 git commit -m initial &&
31 echo changed >check &&
33 echo changed >dir2/sub3 &&
35 echo other >dir2/other
38 test_expect_success update
'
42 test_expect_success
'update noticed a removal' '
43 git ls-files dir1/sub1 >out &&
44 test_must_be_empty out
47 test_expect_success
'update touched correct path' '
48 git diff-files --name-status dir2/sub3 >out &&
49 test_must_be_empty out
52 test_expect_success
'update did not touch other tracked files' '
53 echo "M check" >expect &&
54 git diff-files --name-status check >actual &&
55 test_cmp expect actual &&
57 echo "M top" >expect &&
58 git diff-files --name-status top >actual &&
59 test_cmp expect actual
62 test_expect_success
'update did not touch untracked files' '
63 git ls-files dir2/other >out &&
64 test_must_be_empty out
67 test_expect_success
'error out when passing untracked path' '
71 test_must_fail git add -u baz top 2>err &&
72 test_grep -e "error: pathspec .baz. did not match any file(s) known to git" err &&
73 git diff --cached --name-only >actual &&
74 test_must_be_empty actual
77 test_expect_success
'cache tree has not been corrupted' '
80 sed -e "s/ 0 / /" >expect &&
81 git ls-tree -r $(git write-tree) |
82 sed -e "s/ blob / /" >current &&
83 test_cmp expect current
87 test_expect_success
'update from a subdirectory' '
95 test_expect_success
'change gets noticed' '
96 git diff-files --name-status dir1 >out &&
97 test_must_be_empty out
100 test_expect_success
'non-qualified update in subdir updates from the root' '
103 echo even more >>sub2 &&
104 git --literal-pathspecs add -u &&
105 echo even more >>sub2 &&
108 git diff-files --name-only >actual &&
109 test_must_be_empty actual
112 test_expect_success
'replace a file with a symlink' '
115 test_ln_s_add top foo
119 test_expect_success
'add everything changed' '
122 git diff-files >out &&
123 test_must_be_empty out
127 test_expect_success
'touch and then add -u' '
131 git diff-files >out &&
132 test_must_be_empty out
136 test_expect_success
'touch and then add explicitly' '
140 git diff-files >out &&
141 test_must_be_empty out
145 test_expect_success
'add -n -u should not add but just report' '
148 echo "add '\''check'\''" &&
149 echo "remove '\''top'\''"
151 before=$(git ls-files -s check top) &&
152 git count-objects -v >objects_before &&
153 echo changed >>check &&
155 git add -n -u >actual &&
156 after=$(git ls-files -s check top) &&
157 git count-objects -v >objects_after &&
159 test "$before" = "$after" &&
160 test_cmp objects_before objects_after &&
161 test_cmp expect actual
165 test_expect_success
'add -u resolves unmerged paths' '
167 one=$(echo 1 | git hash-object -w --stdin) &&
168 two=$(echo 2 | git hash-object -w --stdin) &&
169 three=$(echo 3 | git hash-object -w --stdin) &&
171 for path in path1 path2
173 echo "100644 $one 1 $path" &&
174 echo "100644 $two 2 $path" &&
175 echo "100644 $three 3 $path" || return 1
177 echo "100644 $one 1 path3" &&
178 echo "100644 $one 1 path4" &&
179 echo "100644 $one 3 path5" &&
180 echo "100644 $one 3 path6"
182 git update-index --index-info &&
187 # Fail to explicitly resolve removed paths with "git add"
188 test_must_fail git add --no-all path4 &&
189 test_must_fail git add --no-all path6 &&
191 # "add -u" should notice removals no matter what stages
192 # the index entries are in.
194 git ls-files -s path1 path2 path3 path4 path5 path6 >actual &&
196 echo "100644 $three 0 path1" &&
197 echo "100644 $two 0 path3" &&
198 echo "100644 $two 0 path5"
200 test_cmp expect actual
203 test_expect_success
'"add -u non-existent" should fail' '
204 test_must_fail git add -u non-existent &&
205 git ls-files >actual &&
206 ! grep "non-existent" actual
209 test_expect_success
'"commit -a" implies "add -u" if index becomes empty' '
211 git commit -m clean-slate &&
215 git commit -a -m remove &&
216 git ls-tree HEAD: >out &&
217 test_must_be_empty out