t7800: improve test descriptions with empty arguments
[alt-git.git] / t / t2203-add-intent.sh
blob8fa44a92a277f414018d3f71731f791ec4b4f490
1 #!/bin/sh
3 test_description='Intent to add'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_expect_success 'intent to add' '
9 test_commit 1 &&
10 git rm 1.t &&
11 echo hello >1.t &&
12 echo hello >file &&
13 echo hello >elif &&
14 git add -N file &&
15 git add elif &&
16 git add -N 1.t
19 test_expect_success 'git status' '
20 git status --porcelain | grep -v actual >actual &&
21 cat >expect <<-\EOF &&
22 DA 1.t
23 A elif
24 A file
25 EOF
26 test_cmp expect actual
29 test_expect_success 'git status with porcelain v2' '
30 git status --porcelain=v2 | grep -v "^?" >actual &&
31 nam1=$(echo 1 | git hash-object --stdin) &&
32 nam2=$(git hash-object elif) &&
33 cat >expect <<-EOF &&
34 1 DA N... 100644 000000 100644 $nam1 $ZERO_OID 1.t
35 1 A. N... 000000 100644 100644 $ZERO_OID $nam2 elif
36 1 .A N... 000000 000000 100644 $ZERO_OID $ZERO_OID file
37 EOF
38 test_cmp expect actual
41 test_expect_success 'check result of "add -N"' '
42 git ls-files -s file >actual &&
43 empty=$(git hash-object --stdin </dev/null) &&
44 echo "100644 $empty 0 file" >expect &&
45 test_cmp expect actual
48 test_expect_success 'intent to add is just an ordinary empty blob' '
49 git add -u &&
50 git ls-files -s file >actual &&
51 git ls-files -s elif | sed -e "s/elif/file/" >expect &&
52 test_cmp expect actual
55 test_expect_success 'intent to add does not clobber existing paths' '
56 git add -N file elif &&
57 empty=$(git hash-object --stdin </dev/null) &&
58 git ls-files -s >actual &&
59 ! grep "$empty" actual
62 test_expect_success 'i-t-a entry is simply ignored' '
63 test_tick &&
64 git commit -a -m initial &&
65 git reset --hard &&
67 echo xyzzy >rezrov &&
68 echo frotz >nitfol &&
69 git add rezrov &&
70 git add -N nitfol &&
71 git commit -m second &&
72 test $(git ls-tree HEAD -- nitfol | wc -l) = 0 &&
73 test $(git diff --name-only HEAD -- nitfol | wc -l) = 1 &&
74 test $(git diff --name-only -- nitfol | wc -l) = 1
77 test_expect_success 'can commit with an unrelated i-t-a entry in index' '
78 git reset --hard &&
79 echo bozbar >rezrov &&
80 echo frotz >nitfol &&
81 git add rezrov &&
82 git add -N nitfol &&
83 git commit -m partial rezrov
86 test_expect_success 'can "commit -a" with an i-t-a entry' '
87 git reset --hard &&
88 : >nitfol &&
89 git add -N nitfol &&
90 git commit -a -m all
93 test_expect_success 'cache-tree invalidates i-t-a paths' '
94 git reset --hard &&
95 mkdir dir &&
96 : >dir/foo &&
97 git add dir/foo &&
98 git commit -m foo &&
100 : >dir/bar &&
101 git add -N dir/bar &&
102 git diff --name-only >actual &&
103 echo dir/bar >expect &&
104 test_cmp expect actual &&
106 git write-tree >/dev/null &&
108 git diff --name-only >actual &&
109 echo dir/bar >expect &&
110 test_cmp expect actual
113 test_expect_success 'cache-tree does not ignore dir that has i-t-a entries' '
114 git init ita-in-dir &&
116 cd ita-in-dir &&
117 mkdir 2 &&
118 for f in 1 2/1 2/2 3
120 echo "$f" >"$f" || return 1
121 done &&
122 git add 1 2/2 3 &&
123 git add -N 2/1 &&
124 git commit -m committed &&
125 git ls-tree -r HEAD >actual &&
126 grep 2/2 actual
130 test_expect_success 'cache-tree does skip dir that becomes empty' '
131 rm -fr ita-in-dir &&
132 git init ita-in-dir &&
134 cd ita-in-dir &&
135 mkdir -p 1/2/3 &&
136 echo 4 >1/2/3/4 &&
137 git add -N 1/2/3/4 &&
138 git write-tree >actual &&
139 echo $EMPTY_TREE >expected &&
140 test_cmp expected actual
144 test_expect_success 'commit: ita entries ignored in empty initial commit check' '
145 git init empty-initial-commit &&
147 cd empty-initial-commit &&
148 : >one &&
149 git add -N one &&
150 test_must_fail git commit -m nothing-new-here
154 test_expect_success 'commit: ita entries ignored in empty commit check' '
155 git init empty-subsequent-commit &&
157 cd empty-subsequent-commit &&
158 test_commit one &&
159 : >two &&
160 git add -N two &&
161 test_must_fail git commit -m nothing-new-here
165 test_expect_success 'rename detection finds the right names' '
166 git init rename-detection &&
168 cd rename-detection &&
169 echo contents >first &&
170 git add first &&
171 git commit -m first &&
172 mv first third &&
173 git add -N third &&
175 git status | grep -v "^?" >actual.1 &&
176 test_grep "renamed: *first -> third" actual.1 &&
178 git status --porcelain | grep -v "^?" >actual.2 &&
179 cat >expected.2 <<-\EOF &&
180 R first -> third
182 test_cmp expected.2 actual.2 &&
184 hash=$(git hash-object third) &&
185 git status --porcelain=v2 | grep -v "^?" >actual.3 &&
186 cat >expected.3 <<-EOF &&
187 2 .R N... 100644 100644 100644 $hash $hash R100 third first
189 test_cmp expected.3 actual.3 &&
191 git diff --stat >actual.4 &&
192 cat >expected.4 <<-EOF &&
193 first => third | 0
194 1 file changed, 0 insertions(+), 0 deletions(-)
196 test_cmp expected.4 actual.4 &&
198 git diff --cached --stat >actual.5 &&
199 test_must_be_empty actual.5
204 test_expect_success 'double rename detection in status' '
205 git init rename-detection-2 &&
207 cd rename-detection-2 &&
208 echo contents >first &&
209 git add first &&
210 git commit -m first &&
211 git mv first second &&
212 mv second third &&
213 git add -N third &&
215 git status | grep -v "^?" >actual.1 &&
216 test_grep "renamed: *first -> second" actual.1 &&
217 test_grep "renamed: *second -> third" actual.1 &&
219 git status --porcelain | grep -v "^?" >actual.2 &&
220 cat >expected.2 <<-\EOF &&
221 R first -> second
222 R second -> third
224 test_cmp expected.2 actual.2 &&
226 hash=$(git hash-object third) &&
227 git status --porcelain=v2 | grep -v "^?" >actual.3 &&
228 cat >expected.3 <<-EOF &&
229 2 R. N... 100644 100644 100644 $hash $hash R100 second first
230 2 .R N... 100644 100644 100644 $hash $hash R100 third second
232 test_cmp expected.3 actual.3
236 test_expect_success 'i-t-a files shown as new for "diff", "diff-files"; not-new for "diff --cached"' '
237 git reset --hard &&
238 : >empty &&
239 content="foo" &&
240 echo "$content" >not-empty &&
242 hash_e=$(git hash-object empty) &&
243 hash_n=$(git hash-object not-empty) &&
245 cat >expect.diff_p <<-EOF &&
246 diff --git a/empty b/empty
247 new file mode 100644
248 index 0000000..$(git rev-parse --short $hash_e)
249 diff --git a/not-empty b/not-empty
250 new file mode 100644
251 index 0000000..$(git rev-parse --short $hash_n)
252 --- /dev/null
253 +++ b/not-empty
254 @@ -0,0 +1 @@
255 +$content
257 cat >expect.diff_s <<-EOF &&
258 create mode 100644 empty
259 create mode 100644 not-empty
261 cat >expect.diff_a <<-EOF &&
262 :000000 100644 0000000 0000000 A$(printf "\t")empty
263 :000000 100644 0000000 0000000 A$(printf "\t")not-empty
266 git add -N empty not-empty &&
268 git diff >actual &&
269 test_cmp expect.diff_p actual &&
271 git diff --summary >actual &&
272 test_cmp expect.diff_s actual &&
274 git diff-files -p >actual &&
275 test_cmp expect.diff_p actual &&
277 git diff-files --abbrev >actual &&
278 test_cmp expect.diff_a actual &&
280 git diff --cached >actual &&
281 test_must_be_empty actual
284 test_expect_success '"diff HEAD" includes ita as new files' '
285 git reset --hard &&
286 echo new >new-ita &&
287 oid=$(git hash-object new-ita) &&
288 oid=$(git rev-parse --short $oid) &&
289 git add -N new-ita &&
290 git diff HEAD >actual &&
291 cat >expected <<-EOF &&
292 diff --git a/new-ita b/new-ita
293 new file mode 100644
294 index 0000000..$oid
295 --- /dev/null
296 +++ b/new-ita
297 @@ -0,0 +1 @@
298 +new
300 test_cmp expected actual
303 test_expect_success 'apply --intent-to-add' '
304 git reset --hard &&
305 echo new >new-ita &&
306 git add -N new-ita &&
307 git diff >expected &&
308 grep "new file" expected &&
309 git reset --hard &&
310 git apply --intent-to-add expected &&
311 git diff >actual &&
312 test_cmp expected actual
315 test_done