]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | ||
3 | test_description='git add -u | |
4 | ||
5 | This test creates a working tree state with three files: | |
6 | ||
7 | top (previously committed, modified) | |
8 | dir/sub (previously committed, modified) | |
9 | dir/other (untracked) | |
10 | ||
11 | and issues a git add -u with path limiting on "dir" to add | |
12 | only the updates to dir/sub. | |
13 | ||
14 | Also tested are "git add -u" without limiting, and "git add -u" | |
15 | without contents changes, and other conditions' | |
16 | ||
17 | . ./test-lib.sh | |
18 | ||
19 | test_expect_success setup ' | |
20 | echo initial >check && | |
21 | echo initial >top && | |
22 | echo initial >foo && | |
23 | mkdir dir1 dir2 && | |
24 | echo initial >dir1/sub1 && | |
25 | echo initial >dir1/sub2 && | |
26 | echo initial >dir2/sub3 && | |
27 | git add check dir1 dir2 top foo && | |
28 | test_tick && | |
29 | git commit -m initial && | |
30 | ||
31 | echo changed >check && | |
32 | echo changed >top && | |
33 | echo changed >dir2/sub3 && | |
34 | rm -f dir1/sub1 && | |
35 | echo other >dir2/other | |
36 | ' | |
37 | ||
38 | test_expect_success update ' | |
39 | git add -u dir1 dir2 | |
40 | ' | |
41 | ||
42 | test_expect_success 'update noticed a removal' ' | |
43 | git ls-files dir1/sub1 >out && | |
44 | test_must_be_empty out | |
45 | ' | |
46 | ||
47 | test_expect_success 'update touched correct path' ' | |
48 | git diff-files --name-status dir2/sub3 >out && | |
49 | test_must_be_empty out | |
50 | ' | |
51 | ||
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 && | |
56 | ||
57 | echo "M top" >expect && | |
58 | git diff-files --name-status top >actual && | |
59 | test_cmp expect actual | |
60 | ' | |
61 | ||
62 | test_expect_success 'update did not touch untracked files' ' | |
63 | git ls-files dir2/other >out && | |
64 | test_must_be_empty out | |
65 | ' | |
66 | ||
67 | test_expect_success 'error out when passing untracked path' ' | |
68 | git reset --hard && | |
69 | echo content >>baz && | |
70 | echo content >>top && | |
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 | |
75 | ' | |
76 | ||
77 | test_expect_success 'cache tree has not been corrupted' ' | |
78 | ||
79 | git ls-files -s | | |
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 | |
84 | ||
85 | ' | |
86 | ||
87 | test_expect_success 'update from a subdirectory' ' | |
88 | ( | |
89 | cd dir1 && | |
90 | echo more >sub2 && | |
91 | git add -u sub2 | |
92 | ) | |
93 | ' | |
94 | ||
95 | test_expect_success 'change gets noticed' ' | |
96 | git diff-files --name-status dir1 >out && | |
97 | test_must_be_empty out | |
98 | ' | |
99 | ||
100 | test_expect_success 'non-qualified update in subdir updates from the root' ' | |
101 | ( | |
102 | cd dir1 && | |
103 | echo even more >>sub2 && | |
104 | git --literal-pathspecs add -u && | |
105 | echo even more >>sub2 && | |
106 | git add -u | |
107 | ) && | |
108 | git diff-files --name-only >actual && | |
109 | test_must_be_empty actual | |
110 | ' | |
111 | ||
112 | test_expect_success 'replace a file with a symlink' ' | |
113 | ||
114 | rm foo && | |
115 | test_ln_s_add top foo | |
116 | ||
117 | ' | |
118 | ||
119 | test_expect_success 'add everything changed' ' | |
120 | ||
121 | git add -u && | |
122 | git diff-files >out && | |
123 | test_must_be_empty out | |
124 | ||
125 | ' | |
126 | ||
127 | test_expect_success 'touch and then add -u' ' | |
128 | ||
129 | touch check && | |
130 | git add -u && | |
131 | git diff-files >out && | |
132 | test_must_be_empty out | |
133 | ||
134 | ' | |
135 | ||
136 | test_expect_success 'touch and then add explicitly' ' | |
137 | ||
138 | touch check && | |
139 | git add check && | |
140 | git diff-files >out && | |
141 | test_must_be_empty out | |
142 | ||
143 | ' | |
144 | ||
145 | test_expect_success 'add -n -u should not add but just report' ' | |
146 | ||
147 | ( | |
148 | echo "add '\''check'\''" && | |
149 | echo "remove '\''top'\''" | |
150 | ) >expect && | |
151 | before=$(git ls-files -s check top) && | |
152 | git count-objects -v >objects_before && | |
153 | echo changed >>check && | |
154 | rm -f top && | |
155 | git add -n -u >actual && | |
156 | after=$(git ls-files -s check top) && | |
157 | git count-objects -v >objects_after && | |
158 | ||
159 | test "$before" = "$after" && | |
160 | test_cmp objects_before objects_after && | |
161 | test_cmp expect actual | |
162 | ||
163 | ' | |
164 | ||
165 | test_expect_success 'add -u resolves unmerged paths' ' | |
166 | git reset --hard && | |
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) && | |
170 | { | |
171 | for path in path1 path2 | |
172 | do | |
173 | echo "100644 $one 1 $path" && | |
174 | echo "100644 $two 2 $path" && | |
175 | echo "100644 $three 3 $path" || return 1 | |
176 | done && | |
177 | echo "100644 $one 1 path3" && | |
178 | echo "100644 $one 1 path4" && | |
179 | echo "100644 $one 3 path5" && | |
180 | echo "100644 $one 3 path6" | |
181 | } | | |
182 | git update-index --index-info && | |
183 | echo 3 >path1 && | |
184 | echo 2 >path3 && | |
185 | echo 2 >path5 && | |
186 | ||
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 && | |
190 | ||
191 | # "add -u" should notice removals no matter what stages | |
192 | # the index entries are in. | |
193 | git add -u && | |
194 | git ls-files -s path1 path2 path3 path4 path5 path6 >actual && | |
195 | { | |
196 | echo "100644 $three 0 path1" && | |
197 | echo "100644 $two 0 path3" && | |
198 | echo "100644 $two 0 path5" | |
199 | } >expect && | |
200 | test_cmp expect actual | |
201 | ' | |
202 | ||
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 | |
207 | ' | |
208 | ||
209 | test_expect_success '"commit -a" implies "add -u" if index becomes empty' ' | |
210 | git rm -rf \* && | |
211 | git commit -m clean-slate && | |
212 | test_commit file1 && | |
213 | rm file1.t && | |
214 | test_tick && | |
215 | git commit -a -m remove && | |
216 | git ls-tree HEAD: >out && | |
217 | test_must_be_empty out | |
218 | ' | |
219 | ||
220 | test_done |