]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2203-add-intent.sh
Merge branch 'js/diff-files-i-t-a-fix-for-difftool'
[thirdparty/git.git] / t / t2203-add-intent.sh
CommitLineData
39425819
JH
1#!/bin/sh
2
3test_description='Intent to add'
4
5. ./test-lib.sh
6
7test_expect_success 'intent to add' '
425a28e0
NTND
8 test_commit 1 &&
9 git rm 1.t &&
10 echo hello >1.t &&
39425819
JH
11 echo hello >file &&
12 echo hello >elif &&
13 git add -N file &&
425a28e0
NTND
14 git add elif &&
15 git add -N 1.t
16'
17
18test_expect_success 'git status' '
19 git status --porcelain | grep -v actual >actual &&
20 cat >expect <<-\EOF &&
21 DA 1.t
22 A elif
23 A file
24 EOF
25 test_cmp expect actual
39425819
JH
26'
27
6de5aafd
NTND
28test_expect_success 'git status with porcelain v2' '
29 git status --porcelain=v2 | grep -v "^?" >actual &&
62798a70 30 nam1=$(echo 1 | git hash-object --stdin) &&
31 nam2=$(git hash-object elif) &&
6de5aafd 32 cat >expect <<-EOF &&
8125a58b 33 1 DA N... 100644 000000 100644 $nam1 $ZERO_OID 1.t
34 1 A. N... 000000 100644 100644 $ZERO_OID $nam2 elif
35 1 .A N... 000000 000000 100644 $ZERO_OID $ZERO_OID file
6de5aafd
NTND
36 EOF
37 test_cmp expect actual
38'
39
39425819
JH
40test_expect_success 'check result of "add -N"' '
41 git ls-files -s file >actual &&
42 empty=$(git hash-object --stdin </dev/null) &&
43 echo "100644 $empty 0 file" >expect &&
44 test_cmp expect actual
45'
46
47test_expect_success 'intent to add is just an ordinary empty blob' '
48 git add -u &&
49 git ls-files -s file >actual &&
50 git ls-files -s elif | sed -e "s/elif/file/" >expect &&
51 test_cmp expect actual
52'
53
54test_expect_success 'intent to add does not clobber existing paths' '
55 git add -N file elif &&
56 empty=$(git hash-object --stdin </dev/null) &&
57 git ls-files -s >actual &&
58 ! grep "$empty" actual
59'
60
3f6d56de 61test_expect_success 'i-t-a entry is simply ignored' '
331fcb59
JH
62 test_tick &&
63 git commit -a -m initial &&
64 git reset --hard &&
65
66 echo xyzzy >rezrov &&
67 echo frotz >nitfol &&
68 git add rezrov &&
69 git add -N nitfol &&
3f6d56de
JH
70 git commit -m second &&
71 test $(git ls-tree HEAD -- nitfol | wc -l) = 0 &&
b42b4519 72 test $(git diff --name-only HEAD -- nitfol | wc -l) = 1 &&
0231ae71 73 test $(git diff --name-only -- nitfol | wc -l) = 1
331fcb59
JH
74'
75
76test_expect_success 'can commit with an unrelated i-t-a entry in index' '
77 git reset --hard &&
3f6d56de 78 echo bozbar >rezrov &&
331fcb59
JH
79 echo frotz >nitfol &&
80 git add rezrov &&
81 git add -N nitfol &&
82 git commit -m partial rezrov
83'
84
85test_expect_success 'can "commit -a" with an i-t-a entry' '
86 git reset --hard &&
87 : >nitfol &&
88 git add -N nitfol &&
89 git commit -a -m all
90'
91
eec3e7e4
NTND
92test_expect_success 'cache-tree invalidates i-t-a paths' '
93 git reset --hard &&
94 mkdir dir &&
95 : >dir/foo &&
96 git add dir/foo &&
97 git commit -m foo &&
98
99 : >dir/bar &&
100 git add -N dir/bar &&
0231ae71 101 git diff --name-only >actual &&
78cc1a54 102 echo dir/bar >expect &&
eec3e7e4
NTND
103 test_cmp expect actual &&
104
105 git write-tree >/dev/null &&
106
0231ae71 107 git diff --name-only >actual &&
78cc1a54 108 echo dir/bar >expect &&
eec3e7e4
NTND
109 test_cmp expect actual
110'
111
c041d54a
NTND
112test_expect_success 'cache-tree does not ignore dir that has i-t-a entries' '
113 git init ita-in-dir &&
114 (
115 cd ita-in-dir &&
116 mkdir 2 &&
117 for f in 1 2/1 2/2 3
118 do
119 echo "$f" >"$f"
120 done &&
121 git add 1 2/2 3 &&
122 git add -N 2/1 &&
123 git commit -m committed &&
124 git ls-tree -r HEAD >actual &&
125 grep 2/2 actual
126 )
127'
128
6d6a782f
NTND
129test_expect_success 'cache-tree does skip dir that becomes empty' '
130 rm -fr ita-in-dir &&
131 git init ita-in-dir &&
132 (
133 cd ita-in-dir &&
134 mkdir -p 1/2/3 &&
135 echo 4 >1/2/3/4 &&
136 git add -N 1/2/3/4 &&
137 git write-tree >actual &&
138 echo $EMPTY_TREE >expected &&
139 test_cmp expected actual
140 )
141'
142
64127575
VS
143test_expect_success 'commit: ita entries ignored in empty initial commit check' '
144 git init empty-initial-commit &&
2c49f7ff 145 (
64127575 146 cd empty-initial-commit &&
2c49f7ff
NTND
147 : >one &&
148 git add -N one &&
149 test_must_fail git commit -m nothing-new-here
150 )
151'
152
018ec3c8
NTND
153test_expect_success 'commit: ita entries ignored in empty commit check' '
154 git init empty-subsequent-commit &&
155 (
156 cd empty-subsequent-commit &&
157 test_commit one &&
158 : >two &&
159 git add -N two &&
160 test_must_fail git commit -m nothing-new-here
161 )
162'
163
176ea747
NTND
164test_expect_success 'rename detection finds the right names' '
165 git init rename-detection &&
166 (
167 cd rename-detection &&
168 echo contents >first &&
169 git add first &&
170 git commit -m first &&
171 mv first third &&
172 git add -N third &&
173
174 git status | grep -v "^?" >actual.1 &&
175 test_i18ngrep "renamed: *first -> third" actual.1 &&
176
177 git status --porcelain | grep -v "^?" >actual.2 &&
178 cat >expected.2 <<-\EOF &&
179 R first -> third
180 EOF
181 test_cmp expected.2 actual.2 &&
182
62798a70 183 hash=$(git hash-object third) &&
176ea747
NTND
184 git status --porcelain=v2 | grep -v "^?" >actual.3 &&
185 cat >expected.3 <<-EOF &&
186 2 .R N... 100644 100644 100644 $hash $hash R100 third first
187 EOF
0231ae71
NTND
188 test_cmp expected.3 actual.3 &&
189
190 git diff --stat >actual.4 &&
191 cat >expected.4 <<-EOF &&
192 first => third | 0
193 1 file changed, 0 insertions(+), 0 deletions(-)
194 EOF
195 test_cmp expected.4 actual.4 &&
196
197 git diff --cached --stat >actual.5 &&
1c5e94f4 198 test_must_be_empty actual.5
0231ae71 199
176ea747
NTND
200 )
201'
202
203test_expect_success 'double rename detection in status' '
204 git init rename-detection-2 &&
205 (
206 cd rename-detection-2 &&
207 echo contents >first &&
208 git add first &&
209 git commit -m first &&
210 git mv first second &&
211 mv second third &&
212 git add -N third &&
213
214 git status | grep -v "^?" >actual.1 &&
215 test_i18ngrep "renamed: *first -> second" actual.1 &&
216 test_i18ngrep "renamed: *second -> third" actual.1 &&
217
218 git status --porcelain | grep -v "^?" >actual.2 &&
219 cat >expected.2 <<-\EOF &&
220 R first -> second
221 R second -> third
222 EOF
223 test_cmp expected.2 actual.2 &&
224
62798a70 225 hash=$(git hash-object third) &&
176ea747
NTND
226 git status --porcelain=v2 | grep -v "^?" >actual.3 &&
227 cat >expected.3 <<-EOF &&
228 2 R. N... 100644 100644 100644 $hash $hash R100 second first
229 2 .R N... 100644 100644 100644 $hash $hash R100 third second
230 EOF
231 test_cmp expected.3 actual.3
232 )
233'
234
feea6946 235test_expect_success 'i-t-a files shown as new for "diff", "diff-files"; not-new for "diff --cached"' '
0231ae71 236 git reset --hard &&
feea6946
SK
237 : >empty &&
238 content="foo" &&
239 echo "$content" >not-empty &&
240
241 hash_e=$(git hash-object empty) &&
242 hash_n=$(git hash-object not-empty) &&
feea6946
SK
243
244 cat >expect.diff_p <<-EOF &&
245 diff --git a/empty b/empty
246 new file mode 100644
247 index 0000000..$(git rev-parse --short $hash_e)
248 diff --git a/not-empty b/not-empty
249 new file mode 100644
250 index 0000000..$(git rev-parse --short $hash_n)
251 --- /dev/null
252 +++ b/not-empty
253 @@ -0,0 +1 @@
254 +$content
255 EOF
256 cat >expect.diff_s <<-EOF &&
257 create mode 100644 empty
258 create mode 100644 not-empty
259 EOF
260 cat >expect.diff_a <<-EOF &&
85953a31
JS
261 :000000 100644 0000000 0000000 A$(printf "\t")empty
262 :000000 100644 0000000 0000000 A$(printf "\t")not-empty
feea6946
SK
263 EOF
264
265 git add -N empty not-empty &&
266
267 git diff >actual &&
268 test_cmp expect.diff_p actual &&
269
0231ae71 270 git diff --summary >actual &&
feea6946
SK
271 test_cmp expect.diff_s actual &&
272
273 git diff-files -p >actual &&
274 test_cmp expect.diff_p actual &&
39425819 275
feea6946
SK
276 git diff-files --abbrev >actual &&
277 test_cmp expect.diff_a actual &&
278
279 git diff --cached >actual &&
280 test_must_be_empty actual
281'
39425819 282
8fc8f05c
NTND
283test_expect_success '"diff HEAD" includes ita as new files' '
284 git reset --hard &&
285 echo new >new-ita &&
f6c9b474 286 oid=$(git hash-object new-ita) &&
287 oid=$(git rev-parse --short $oid) &&
8fc8f05c
NTND
288 git add -N new-ita &&
289 git diff HEAD >actual &&
f6c9b474 290 cat >expected <<-EOF &&
8fc8f05c
NTND
291 diff --git a/new-ita b/new-ita
292 new file mode 100644
f6c9b474 293 index 0000000..$oid
8fc8f05c
NTND
294 --- /dev/null
295 +++ b/new-ita
296 @@ -0,0 +1 @@
297 +new
298 EOF
299 test_cmp expected actual
300'
301
cff5dc09
NTND
302test_expect_success 'apply --intent-to-add' '
303 git reset --hard &&
304 echo new >new-ita &&
305 git add -N new-ita &&
306 git diff >expected &&
307 grep "new file" expected &&
308 git reset --hard &&
309 git apply --intent-to-add expected &&
310 git diff >actual &&
311 test_cmp expected actual
312'
313
0231ae71 314test_done