]>
Commit | Line | Data |
---|---|---|
93c44d49 JK |
1 | #!/bin/sh |
2 | ||
25487bde | 3 | test_description='git add -u |
93c44d49 JK |
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 | ||
5be60078 | 11 | and issues a git add -u with path limiting on "dir" to add |
25487bde JH |
12 | only the updates to dir/sub. |
13 | ||
14 | Also tested are "git add -u" without limiting, and "git add -u" | |
4cc8d6c6 | 15 | without contents changes, and other conditions' |
93c44d49 JK |
16 | |
17 | . ./test-lib.sh | |
18 | ||
a4882c27 JH |
19 | test_expect_success setup ' |
20 | echo initial >check && | |
21 | echo initial >top && | |
43b98acc | 22 | echo initial >foo && |
a4882c27 JH |
23 | mkdir dir1 dir2 && |
24 | echo initial >dir1/sub1 && | |
25 | echo initial >dir1/sub2 && | |
26 | echo initial >dir2/sub3 && | |
43b98acc | 27 | git add check dir1 dir2 top foo && |
a48fcd83 | 28 | test_tick && |
0cb0e143 | 29 | git commit -m initial && |
a4882c27 JH |
30 | |
31 | echo changed >check && | |
32 | echo changed >top && | |
33 | echo changed >dir2/sub3 && | |
34 | rm -f dir1/sub1 && | |
35 | echo other >dir2/other | |
93c44d49 JK |
36 | ' |
37 | ||
a4882c27 JH |
38 | test_expect_success update ' |
39 | git add -u dir1 dir2 | |
93c44d49 | 40 | ' |
93c44d49 | 41 | |
a4882c27 | 42 | test_expect_success 'update noticed a removal' ' |
c4d1d526 ÆAB |
43 | git ls-files dir1/sub1 >out && |
44 | test_must_be_empty out | |
a4882c27 | 45 | ' |
93c44d49 | 46 | |
a4882c27 | 47 | test_expect_success 'update touched correct path' ' |
c4d1d526 ÆAB |
48 | git diff-files --name-status dir2/sub3 >out && |
49 | test_must_be_empty out | |
a4882c27 | 50 | ' |
93c44d49 | 51 | |
a4882c27 | 52 | test_expect_success 'update did not touch other tracked files' ' |
c4d1d526 ÆAB |
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 | |
a4882c27 | 60 | ' |
93c44d49 | 61 | |
a4882c27 | 62 | test_expect_success 'update did not touch untracked files' ' |
c4d1d526 ÆAB |
63 | git ls-files dir2/other >out && |
64 | test_must_be_empty out | |
a4882c27 | 65 | ' |
93c44d49 | 66 | |
7de13cfe GT |
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 | ||
a4882c27 | 77 | test_expect_success 'cache tree has not been corrupted' ' |
93c44d49 | 78 | |
a4882c27 JH |
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 && | |
82ebb0b6 | 83 | test_cmp expect current |
a4882c27 JH |
84 | |
85 | ' | |
93c44d49 | 86 | |
2ed2c222 SZ |
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' ' | |
c4d1d526 ÆAB |
96 | git diff-files --name-status dir1 >out && |
97 | test_must_be_empty out | |
2ed2c222 | 98 | ' |
93c44d49 | 99 | |
808d3d71 | 100 | test_expect_success 'non-qualified update in subdir updates from the root' ' |
7bf7a92f JK |
101 | ( |
102 | cd dir1 && | |
103 | echo even more >>sub2 && | |
29abb339 JH |
104 | git --literal-pathspecs add -u && |
105 | echo even more >>sub2 && | |
7bf7a92f JK |
106 | git add -u |
107 | ) && | |
7bf7a92f | 108 | git diff-files --name-only >actual && |
1c5e94f4 | 109 | test_must_be_empty actual |
7bf7a92f JK |
110 | ' |
111 | ||
889c6f0e | 112 | test_expect_success 'replace a file with a symlink' ' |
43b98acc BS |
113 | |
114 | rm foo && | |
889c6f0e | 115 | test_ln_s_add top foo |
43b98acc BS |
116 | |
117 | ' | |
118 | ||
25487bde JH |
119 | test_expect_success 'add everything changed' ' |
120 | ||
121 | git add -u && | |
c4d1d526 ÆAB |
122 | git diff-files >out && |
123 | test_must_be_empty out | |
25487bde JH |
124 | |
125 | ' | |
126 | ||
127 | test_expect_success 'touch and then add -u' ' | |
128 | ||
129 | touch check && | |
130 | git add -u && | |
c4d1d526 ÆAB |
131 | git diff-files >out && |
132 | test_must_be_empty out | |
25487bde JH |
133 | |
134 | ' | |
135 | ||
136 | test_expect_success 'touch and then add explicitly' ' | |
137 | ||
138 | touch check && | |
139 | git add check && | |
c4d1d526 ÆAB |
140 | git diff-files >out && |
141 | test_must_be_empty out | |
25487bde JH |
142 | |
143 | ' | |
144 | ||
c36f9412 | 145 | test_expect_success 'add -n -u should not add but just report' ' |
38ed1d89 JH |
146 | |
147 | ( | |
148 | echo "add '\''check'\''" && | |
149 | echo "remove '\''top'\''" | |
150 | ) >expect && | |
151 | before=$(git ls-files -s check top) && | |
e578d031 | 152 | git count-objects -v >objects_before && |
38ed1d89 JH |
153 | echo changed >>check && |
154 | rm -f top && | |
155 | git add -n -u >actual && | |
156 | after=$(git ls-files -s check top) && | |
e578d031 | 157 | git count-objects -v >objects_after && |
38ed1d89 JH |
158 | |
159 | test "$before" = "$after" && | |
e578d031 | 160 | test_cmp objects_before objects_after && |
1108cea7 | 161 | test_cmp expect actual |
38ed1d89 JH |
162 | |
163 | ' | |
164 | ||
4cc8d6c6 JH |
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 | |
74d2f569 ES |
173 | echo "100644 $one 1 $path" && |
174 | echo "100644 $two 2 $path" && | |
db5875aa | 175 | echo "100644 $three 3 $path" || return 1 |
7abcbcb7 ES |
176 | done && |
177 | echo "100644 $one 1 path3" && | |
178 | echo "100644 $one 1 path4" && | |
179 | echo "100644 $one 3 path5" && | |
4cc8d6c6 JH |
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 && | |
4cc8d6c6 | 186 | |
45c45e30 JH |
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 && | |
4cc8d6c6 | 190 | |
75973b2c JH |
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 && | |
4cc8d6c6 | 195 | { |
7abcbcb7 ES |
196 | echo "100644 $three 0 path1" && |
197 | echo "100644 $two 0 path3" && | |
4cc8d6c6 | 198 | echo "100644 $two 0 path5" |
75973b2c JH |
199 | } >expect && |
200 | test_cmp expect actual | |
4cc8d6c6 JH |
201 | ' |
202 | ||
1e7ef746 CP |
203 | test_expect_success '"add -u non-existent" should fail' ' |
204 | test_must_fail git add -u non-existent && | |
a90765be AS |
205 | git ls-files >actual && |
206 | ! grep "non-existent" actual | |
1e7ef746 CP |
207 | ' |
208 | ||
2ee045ee JS |
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 | ||
93c44d49 | 220 | test_done |