SubmittingPatches: mention doc-diff
[git/raj.git] / t / t2203-add-intent.sh
blobe7a400b4c77a822a49365e4049fbe68b059d23ee
1 #!/bin/sh
3 test_description='Intent to add'
5 . ./test-lib.sh
7 test_expect_success 'intent to add' '
8 test_commit 1 &&
9 git rm 1.t &&
10 echo hello >1.t &&
11 echo hello >file &&
12 echo hello >elif &&
13 git add -N file &&
14 git add elif &&
15 git add -N 1.t
18 test_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
28 test_expect_success 'git status with porcelain v2' '
29 git status --porcelain=v2 | grep -v "^?" >actual &&
30 nam1=$(echo 1 | git hash-object --stdin) &&
31 nam2=$(git hash-object elif) &&
32 cat >expect <<-EOF &&
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
36 EOF
37 test_cmp expect actual
40 test_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
47 test_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
54 test_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
61 test_expect_success 'i-t-a entry is simply ignored' '
62 test_tick &&
63 git commit -a -m initial &&
64 git reset --hard &&
66 echo xyzzy >rezrov &&
67 echo frotz >nitfol &&
68 git add rezrov &&
69 git add -N nitfol &&
70 git commit -m second &&
71 test $(git ls-tree HEAD -- nitfol | wc -l) = 0 &&
72 test $(git diff --name-only HEAD -- nitfol | wc -l) = 1 &&
73 test $(git diff --name-only -- nitfol | wc -l) = 1
76 test_expect_success 'can commit with an unrelated i-t-a entry in index' '
77 git reset --hard &&
78 echo bozbar >rezrov &&
79 echo frotz >nitfol &&
80 git add rezrov &&
81 git add -N nitfol &&
82 git commit -m partial rezrov
85 test_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
92 test_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 &&
99 : >dir/bar &&
100 git add -N dir/bar &&
101 git diff --name-only >actual &&
102 echo dir/bar >expect &&
103 test_cmp expect actual &&
105 git write-tree >/dev/null &&
107 git diff --name-only >actual &&
108 echo dir/bar >expect &&
109 test_cmp expect actual
112 test_expect_success 'cache-tree does not ignore dir that has i-t-a entries' '
113 git init ita-in-dir &&
115 cd ita-in-dir &&
116 mkdir 2 &&
117 for f in 1 2/1 2/2 3
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
129 test_expect_success 'cache-tree does skip dir that becomes empty' '
130 rm -fr ita-in-dir &&
131 git init ita-in-dir &&
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
143 test_expect_success 'commit: ita entries ignored in empty initial commit check' '
144 git init empty-initial-commit &&
146 cd empty-initial-commit &&
147 : >one &&
148 git add -N one &&
149 test_must_fail git commit -m nothing-new-here
153 test_expect_success 'commit: ita entries ignored in empty commit check' '
154 git init empty-subsequent-commit &&
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
164 test_expect_success 'rename detection finds the right names' '
165 git init rename-detection &&
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 &&
174 git status | grep -v "^?" >actual.1 &&
175 test_i18ngrep "renamed: *first -> third" actual.1 &&
177 git status --porcelain | grep -v "^?" >actual.2 &&
178 cat >expected.2 <<-\EOF &&
179 R first -> third
181 test_cmp expected.2 actual.2 &&
183 hash=$(git hash-object third) &&
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
188 test_cmp expected.3 actual.3 &&
190 git diff --stat >actual.4 &&
191 cat >expected.4 <<-EOF &&
192 first => third | 0
193 1 file changed, 0 insertions(+), 0 deletions(-)
195 test_cmp expected.4 actual.4 &&
197 git diff --cached --stat >actual.5 &&
198 : >expected.5 &&
199 test_cmp expected.5 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_i18ngrep "renamed: *first -> second" actual.1 &&
217 test_i18ngrep "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 'diff-files/diff-cached shows ita as new/not-new files' '
237 git reset --hard &&
238 echo new >new-ita &&
239 git add -N new-ita &&
240 git diff --summary >actual &&
241 echo " create mode 100644 new-ita" >expected &&
242 test_cmp expected actual &&
243 git diff --cached --summary >actual2 &&
244 : >expected2 &&
245 test_cmp expected2 actual2
249 test_expect_success '"diff HEAD" includes ita as new files' '
250 git reset --hard &&
251 echo new >new-ita &&
252 git add -N new-ita &&
253 git diff HEAD >actual &&
254 cat >expected <<-\EOF &&
255 diff --git a/new-ita b/new-ita
256 new file mode 100644
257 index 0000000..3e75765
258 --- /dev/null
259 +++ b/new-ita
260 @@ -0,0 +1 @@
261 +new
263 test_cmp expected actual
266 test_expect_success 'apply --intent-to-add' '
267 git reset --hard &&
268 echo new >new-ita &&
269 git add -N new-ita &&
270 git diff >expected &&
271 grep "new file" expected &&
272 git reset --hard &&
273 git apply --intent-to-add expected &&
274 git diff >actual &&
275 test_cmp expected actual
278 test_done