]>
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 | 16 | |
6ab75ac8 | 17 | TEST_PASSES_SANITIZE_LEAK=true |
93c44d49 JK |
18 | . ./test-lib.sh |
19 | ||
a4882c27 JH |
20 | test_expect_success setup ' |
21 | echo initial >check && | |
22 | echo initial >top && | |
43b98acc | 23 | echo initial >foo && |
a4882c27 JH |
24 | mkdir dir1 dir2 && |
25 | echo initial >dir1/sub1 && | |
26 | echo initial >dir1/sub2 && | |
27 | echo initial >dir2/sub3 && | |
43b98acc | 28 | git add check dir1 dir2 top foo && |
a48fcd83 | 29 | test_tick && |
0cb0e143 | 30 | git commit -m initial && |
a4882c27 JH |
31 | |
32 | echo changed >check && | |
33 | echo changed >top && | |
34 | echo changed >dir2/sub3 && | |
35 | rm -f dir1/sub1 && | |
36 | echo other >dir2/other | |
93c44d49 JK |
37 | ' |
38 | ||
a4882c27 JH |
39 | test_expect_success update ' |
40 | git add -u dir1 dir2 | |
93c44d49 | 41 | ' |
93c44d49 | 42 | |
a4882c27 | 43 | test_expect_success 'update noticed a removal' ' |
c4d1d526 ÆAB |
44 | git ls-files dir1/sub1 >out && |
45 | test_must_be_empty out | |
a4882c27 | 46 | ' |
93c44d49 | 47 | |
a4882c27 | 48 | test_expect_success 'update touched correct path' ' |
c4d1d526 ÆAB |
49 | git diff-files --name-status dir2/sub3 >out && |
50 | test_must_be_empty out | |
a4882c27 | 51 | ' |
93c44d49 | 52 | |
a4882c27 | 53 | test_expect_success 'update did not touch other tracked files' ' |
c4d1d526 ÆAB |
54 | echo "M check" >expect && |
55 | git diff-files --name-status check >actual && | |
56 | test_cmp expect actual && | |
57 | ||
58 | echo "M top" >expect && | |
59 | git diff-files --name-status top >actual && | |
60 | test_cmp expect actual | |
a4882c27 | 61 | ' |
93c44d49 | 62 | |
a4882c27 | 63 | test_expect_success 'update did not touch untracked files' ' |
c4d1d526 ÆAB |
64 | git ls-files dir2/other >out && |
65 | test_must_be_empty out | |
a4882c27 | 66 | ' |
93c44d49 | 67 | |
a4882c27 | 68 | test_expect_success 'cache tree has not been corrupted' ' |
93c44d49 | 69 | |
a4882c27 JH |
70 | git ls-files -s | |
71 | sed -e "s/ 0 / /" >expect && | |
72 | git ls-tree -r $(git write-tree) | | |
73 | sed -e "s/ blob / /" >current && | |
82ebb0b6 | 74 | test_cmp expect current |
a4882c27 JH |
75 | |
76 | ' | |
93c44d49 | 77 | |
2ed2c222 SZ |
78 | test_expect_success 'update from a subdirectory' ' |
79 | ( | |
80 | cd dir1 && | |
81 | echo more >sub2 && | |
82 | git add -u sub2 | |
83 | ) | |
84 | ' | |
85 | ||
86 | test_expect_success 'change gets noticed' ' | |
c4d1d526 ÆAB |
87 | git diff-files --name-status dir1 >out && |
88 | test_must_be_empty out | |
2ed2c222 | 89 | ' |
93c44d49 | 90 | |
808d3d71 | 91 | test_expect_success 'non-qualified update in subdir updates from the root' ' |
7bf7a92f JK |
92 | ( |
93 | cd dir1 && | |
94 | echo even more >>sub2 && | |
29abb339 JH |
95 | git --literal-pathspecs add -u && |
96 | echo even more >>sub2 && | |
7bf7a92f JK |
97 | git add -u |
98 | ) && | |
7bf7a92f | 99 | git diff-files --name-only >actual && |
1c5e94f4 | 100 | test_must_be_empty actual |
7bf7a92f JK |
101 | ' |
102 | ||
889c6f0e | 103 | test_expect_success 'replace a file with a symlink' ' |
43b98acc BS |
104 | |
105 | rm foo && | |
889c6f0e | 106 | test_ln_s_add top foo |
43b98acc BS |
107 | |
108 | ' | |
109 | ||
25487bde JH |
110 | test_expect_success 'add everything changed' ' |
111 | ||
112 | git add -u && | |
c4d1d526 ÆAB |
113 | git diff-files >out && |
114 | test_must_be_empty out | |
25487bde JH |
115 | |
116 | ' | |
117 | ||
118 | test_expect_success 'touch and then add -u' ' | |
119 | ||
120 | touch check && | |
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 explicitly' ' | |
128 | ||
129 | touch check && | |
130 | git add check && | |
c4d1d526 ÆAB |
131 | git diff-files >out && |
132 | test_must_be_empty out | |
25487bde JH |
133 | |
134 | ' | |
135 | ||
c36f9412 | 136 | test_expect_success 'add -n -u should not add but just report' ' |
38ed1d89 JH |
137 | |
138 | ( | |
139 | echo "add '\''check'\''" && | |
140 | echo "remove '\''top'\''" | |
141 | ) >expect && | |
142 | before=$(git ls-files -s check top) && | |
e578d031 | 143 | git count-objects -v >objects_before && |
38ed1d89 JH |
144 | echo changed >>check && |
145 | rm -f top && | |
146 | git add -n -u >actual && | |
147 | after=$(git ls-files -s check top) && | |
e578d031 | 148 | git count-objects -v >objects_after && |
38ed1d89 JH |
149 | |
150 | test "$before" = "$after" && | |
e578d031 | 151 | test_cmp objects_before objects_after && |
1108cea7 | 152 | test_cmp expect actual |
38ed1d89 JH |
153 | |
154 | ' | |
155 | ||
4cc8d6c6 JH |
156 | test_expect_success 'add -u resolves unmerged paths' ' |
157 | git reset --hard && | |
158 | one=$(echo 1 | git hash-object -w --stdin) && | |
159 | two=$(echo 2 | git hash-object -w --stdin) && | |
160 | three=$(echo 3 | git hash-object -w --stdin) && | |
161 | { | |
162 | for path in path1 path2 | |
163 | do | |
74d2f569 ES |
164 | echo "100644 $one 1 $path" && |
165 | echo "100644 $two 2 $path" && | |
db5875aa | 166 | echo "100644 $three 3 $path" || return 1 |
7abcbcb7 ES |
167 | done && |
168 | echo "100644 $one 1 path3" && | |
169 | echo "100644 $one 1 path4" && | |
170 | echo "100644 $one 3 path5" && | |
4cc8d6c6 JH |
171 | echo "100644 $one 3 path6" |
172 | } | | |
173 | git update-index --index-info && | |
174 | echo 3 >path1 && | |
175 | echo 2 >path3 && | |
176 | echo 2 >path5 && | |
4cc8d6c6 | 177 | |
45c45e30 JH |
178 | # Fail to explicitly resolve removed paths with "git add" |
179 | test_must_fail git add --no-all path4 && | |
180 | test_must_fail git add --no-all path6 && | |
4cc8d6c6 | 181 | |
75973b2c JH |
182 | # "add -u" should notice removals no matter what stages |
183 | # the index entries are in. | |
184 | git add -u && | |
185 | git ls-files -s path1 path2 path3 path4 path5 path6 >actual && | |
4cc8d6c6 | 186 | { |
7abcbcb7 ES |
187 | echo "100644 $three 0 path1" && |
188 | echo "100644 $two 0 path3" && | |
4cc8d6c6 | 189 | echo "100644 $two 0 path5" |
75973b2c JH |
190 | } >expect && |
191 | test_cmp expect actual | |
4cc8d6c6 JH |
192 | ' |
193 | ||
1e7ef746 CP |
194 | test_expect_success '"add -u non-existent" should fail' ' |
195 | test_must_fail git add -u non-existent && | |
a90765be AS |
196 | git ls-files >actual && |
197 | ! grep "non-existent" actual | |
1e7ef746 CP |
198 | ' |
199 | ||
2ee045ee JS |
200 | test_expect_success '"commit -a" implies "add -u" if index becomes empty' ' |
201 | git rm -rf \* && | |
202 | git commit -m clean-slate && | |
203 | test_commit file1 && | |
204 | rm file1.t && | |
205 | test_tick && | |
206 | git commit -a -m remove && | |
207 | git ls-tree HEAD: >out && | |
208 | test_must_be_empty out | |
209 | ' | |
210 | ||
93c44d49 | 211 | test_done |