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 test "$(git ls-files dir1/sub1)" = ""
46 test_expect_success 'update touched correct path' '
47 test "$(git diff-files --name-status dir2/sub3)" = ""
50 test_expect_success 'update did not touch other tracked files' '
51 test "$(git diff-files --name-status check)" = "M check" &&
52 test "$(git diff-files --name-status top)" = "M top"
55 test_expect_success 'update did not touch untracked files' '
56 test "$(git ls-files dir2/other)" = ""
59 test_expect_success 'cache tree has not been corrupted' '
62 sed -e "s/ 0 / /" >expect &&
63 git ls-tree -r $(git write-tree) |
64 sed -e "s/ blob / /" >current &&
65 test_cmp expect current
69 test_expect_success 'update from a subdirectory' '
77 test_expect_success 'change gets noticed' '
79 test "$(git diff-files --name-status dir1)" = ""
83 # Note that this is scheduled to change in Git 2.0, when
84 # "git add -u" will become full-tree by default.
85 test_expect_success 'non-limited update in subdir leaves root alone' '
88 echo even more >>sub2 &&
91 cat >expect <<-\EOF &&
95 git diff-files --name-only >actual &&
96 test_cmp expect actual
99 test_expect_success SYMLINKS 'replace a file with a symlink' '
107 test_expect_success 'add everything changed' '
110 test -z "$(git diff-files)"
114 test_expect_success 'touch and then add -u' '
118 test -z "$(git diff-files)"
122 test_expect_success 'touch and then add explicitly' '
126 test -z "$(git diff-files)"
130 test_expect_success 'add -n -u should not add but just report' '
133 echo "add '\''check'\''" &&
134 echo "remove '\''top'\''"
136 before=$(git ls-files -s check top) &&
137 echo changed >>check &&
139 git add -n -u >actual &&
140 after=$(git ls-files -s check top) &&
142 test "$before" = "$after" &&
143 test_i18ncmp expect actual
147 test_expect_success 'add -u resolves unmerged paths' '
149 one=$(echo 1 | git hash-object -w --stdin) &&
150 two=$(echo 2 | git hash-object -w --stdin) &&
151 three=$(echo 3 | git hash-object -w --stdin) &&
153 for path in path1 path2
155 echo "100644 $one 1 $path"
156 echo "100644 $two 2 $path"
157 echo "100644 $three 3 $path"
159 echo "100644 $one 1 path3"
160 echo "100644 $one 1 path4"
161 echo "100644 $one 3 path5"
162 echo "100644 $one 3 path6"
164 git update-index --index-info &&
169 # Explicit resolving by adding removed paths should fail
170 test_must_fail git add path4 &&
171 test_must_fail git add path6 &&
173 # "add -u" should notice removals no matter what stages
174 # the index entries are in.
176 git ls-files -s path1 path2 path3 path4 path5 path6 >actual &&
178 echo "100644 $three 0 path1"
179 echo "100644 $two 0 path3"
180 echo "100644 $two 0 path5"
182 test_cmp expect actual
185 test_expect_success '"add -u non-existent" should fail' '
186 test_must_fail git add -u non-existent &&
187 ! (git ls-files | grep "non-existent")