git-p4: fix typos
[git/gitster.git] / t / t2200-add-update.sh
blobdf235ac306e7126f7090bc62c451e906b174c387
1 #!/bin/sh
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)
9 dir/other (untracked)
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
18 . ./test-lib.sh
20 test_expect_success setup '
21 echo initial >check &&
22 echo initial >top &&
23 echo initial >foo &&
24 mkdir dir1 dir2 &&
25 echo initial >dir1/sub1 &&
26 echo initial >dir1/sub2 &&
27 echo initial >dir2/sub3 &&
28 git add check dir1 dir2 top foo &&
29 test_tick &&
30 git commit -m initial &&
32 echo changed >check &&
33 echo changed >top &&
34 echo changed >dir2/sub3 &&
35 rm -f dir1/sub1 &&
36 echo other >dir2/other
39 test_expect_success update '
40 git add -u dir1 dir2
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 'error out when passing untracked path' '
69 git reset --hard &&
70 echo content >>baz &&
71 echo content >>top &&
72 test_must_fail git add -u baz top 2>err &&
73 test_grep -e "error: pathspec .baz. did not match any file(s) known to git" err &&
74 git diff --cached --name-only >actual &&
75 test_must_be_empty actual
78 test_expect_success 'cache tree has not been corrupted' '
80 git ls-files -s |
81 sed -e "s/ 0 / /" >expect &&
82 git ls-tree -r $(git write-tree) |
83 sed -e "s/ blob / /" >current &&
84 test_cmp expect current
88 test_expect_success 'update from a subdirectory' '
90 cd dir1 &&
91 echo more >sub2 &&
92 git add -u sub2
96 test_expect_success 'change gets noticed' '
97 git diff-files --name-status dir1 >out &&
98 test_must_be_empty out
101 test_expect_success 'non-qualified update in subdir updates from the root' '
103 cd dir1 &&
104 echo even more >>sub2 &&
105 git --literal-pathspecs add -u &&
106 echo even more >>sub2 &&
107 git add -u
108 ) &&
109 git diff-files --name-only >actual &&
110 test_must_be_empty actual
113 test_expect_success 'replace a file with a symlink' '
115 rm foo &&
116 test_ln_s_add top foo
120 test_expect_success 'add everything changed' '
122 git add -u &&
123 git diff-files >out &&
124 test_must_be_empty out
128 test_expect_success 'touch and then add -u' '
130 touch check &&
131 git add -u &&
132 git diff-files >out &&
133 test_must_be_empty out
137 test_expect_success 'touch and then add explicitly' '
139 touch check &&
140 git add check &&
141 git diff-files >out &&
142 test_must_be_empty out
146 test_expect_success 'add -n -u should not add but just report' '
149 echo "add '\''check'\''" &&
150 echo "remove '\''top'\''"
151 ) >expect &&
152 before=$(git ls-files -s check top) &&
153 git count-objects -v >objects_before &&
154 echo changed >>check &&
155 rm -f top &&
156 git add -n -u >actual &&
157 after=$(git ls-files -s check top) &&
158 git count-objects -v >objects_after &&
160 test "$before" = "$after" &&
161 test_cmp objects_before objects_after &&
162 test_cmp expect actual
166 test_expect_success 'add -u resolves unmerged paths' '
167 git reset --hard &&
168 one=$(echo 1 | git hash-object -w --stdin) &&
169 two=$(echo 2 | git hash-object -w --stdin) &&
170 three=$(echo 3 | git hash-object -w --stdin) &&
172 for path in path1 path2
174 echo "100644 $one 1 $path" &&
175 echo "100644 $two 2 $path" &&
176 echo "100644 $three 3 $path" || return 1
177 done &&
178 echo "100644 $one 1 path3" &&
179 echo "100644 $one 1 path4" &&
180 echo "100644 $one 3 path5" &&
181 echo "100644 $one 3 path6"
183 git update-index --index-info &&
184 echo 3 >path1 &&
185 echo 2 >path3 &&
186 echo 2 >path5 &&
188 # Fail to explicitly resolve removed paths with "git add"
189 test_must_fail git add --no-all path4 &&
190 test_must_fail git add --no-all path6 &&
192 # "add -u" should notice removals no matter what stages
193 # the index entries are in.
194 git add -u &&
195 git ls-files -s path1 path2 path3 path4 path5 path6 >actual &&
197 echo "100644 $three 0 path1" &&
198 echo "100644 $two 0 path3" &&
199 echo "100644 $two 0 path5"
200 } >expect &&
201 test_cmp expect actual
204 test_expect_success '"add -u non-existent" should fail' '
205 test_must_fail git add -u non-existent &&
206 git ls-files >actual &&
207 ! grep "non-existent" actual
210 test_expect_success '"commit -a" implies "add -u" if index becomes empty' '
211 git rm -rf \* &&
212 git commit -m clean-slate &&
213 test_commit file1 &&
214 rm file1.t &&
215 test_tick &&
216 git commit -a -m remove &&
217 git ls-tree HEAD: >out &&
218 test_must_be_empty out
221 test_done