3 # Copyright (c) 2006 Carl D. Worth
6 test_description='Test of git add, including the -- option.'
12 'touch foo && git add foo'
15 'Post-check that foo is in the index' \
16 'git ls-files foo | grep foo'
19 'Test that "git add -- -q" works' \
20 'touch -- -q && git add -- -q'
23 'git add: Test that executable bit is not used if core.filemode=0' \
24 'git config core.filemode 0 &&
28 case "`git ls-files --stage xfoo1`" in
29 100644" "*xfoo1) echo pass;;
30 *) echo fail; git ls-files --stage xfoo1; (exit 1);;
33 test_expect_success 'git add: filemode=0 should not get confused by symlink' '
35 test_ln_s_add foo xfoo1 &&
36 case "`git ls-files --stage xfoo1`" in
37 120000" "*xfoo1) echo pass;;
38 *) echo fail; git ls-files --stage xfoo1; (exit 1);;
43 'git update-index --add: Test that executable bit is not used...' \
44 'git config core.filemode 0 &&
47 git update-index --add xfoo2 &&
48 case "`git ls-files --stage xfoo2`" in
49 100644" "*xfoo2) echo pass;;
50 *) echo fail; git ls-files --stage xfoo2; (exit 1);;
53 test_expect_success 'git add: filemode=0 should not get confused by symlink' '
55 test_ln_s_add foo xfoo2 &&
56 case "`git ls-files --stage xfoo2`" in
57 120000" "*xfoo2) echo pass;;
58 *) echo fail; git ls-files --stage xfoo2; (exit 1);;
63 'git update-index --add: Test that executable bit is not used...' \
64 'git config core.filemode 0 &&
65 test_ln_s_add xfoo2 xfoo3 && # runs git update-index --add
66 case "`git ls-files --stage xfoo3`" in
67 120000" "*xfoo3) echo pass;;
68 *) echo fail; git ls-files --stage xfoo3; (exit 1);;
71 test_expect_success '.gitignore test setup' '
72 echo "*.ig" >.gitignore &&
75 >c.if/c.if && >c.if/c.ig &&
76 >d.ig/d.if && >d.ig/d.ig
79 test_expect_success '.gitignore is honored' '
81 ! (git ls-files | grep "\\.ig")
84 test_expect_success 'error out when attempting to add ignored ones without -f' '
85 test_must_fail git add a.?? &&
86 ! (git ls-files | grep "\\.ig")
89 test_expect_success 'error out when attempting to add ignored ones without -f' '
90 test_must_fail git add d.?? &&
91 ! (git ls-files | grep "\\.ig")
94 test_expect_success 'error out when attempting to add ignored ones but add others' '
96 test_must_fail git add a.?? &&
97 ! (git ls-files | grep "\\.ig") &&
98 (git ls-files | grep a.if)
101 test_expect_success 'add ignored ones with -f' '
103 git ls-files --error-unmatch a.ig
106 test_expect_success 'add ignored ones with -f' '
108 git ls-files --error-unmatch d.ig/d.if d.ig/d.ig
111 test_expect_success 'add ignored ones with -f' '
114 git ls-files --error-unmatch d.ig/d.if d.ig/d.ig
117 test_expect_success '.gitignore with subdirectory' '
121 echo "!dir/a.*" >sub/.gitignore &&
125 git ls-files --error-unmatch sub/dir/a.ig &&
131 git ls-files --error-unmatch sub/dir/a.ig
135 touch 1/2/a 1/3/b 1/2/c
136 test_expect_success 'check correct prefix detection' '
138 git add 1/2/a 1/3/b 1/2/c
141 test_expect_success 'git add with filemode=0, symlinks=0, and unmerged entries' '
145 echo "100755 $(git hash-object -w stage$s) $s file"
146 echo "120000 $(printf $s | git hash-object -w -t blob --stdin) $s symlink"
147 done | git update-index --index-info &&
148 git config core.filemode 0 &&
149 git config core.symlinks 0 &&
151 echo new > symlink &&
152 git add file symlink &&
153 git ls-files --stage | grep "^100755 .* 0 file$" &&
154 git ls-files --stage | grep "^120000 .* 0 symlink$"
157 test_expect_success 'git add with filemode=0, symlinks=0 prefers stage 2 over stage 1' '
158 git rm --cached -f file symlink &&
160 echo "100644 $(git hash-object -w stage1) 1 file"
161 echo "100755 $(git hash-object -w stage2) 2 file"
162 echo "100644 $(printf 1 | git hash-object -w -t blob --stdin) 1 symlink"
163 echo "120000 $(printf 2 | git hash-object -w -t blob --stdin) 2 symlink"
164 ) | git update-index --index-info &&
165 git config core.filemode 0 &&
166 git config core.symlinks 0 &&
168 echo new > symlink &&
169 git add file symlink &&
170 git ls-files --stage | grep "^100755 .* 0 file$" &&
171 git ls-files --stage | grep "^120000 .* 0 symlink$"
174 test_expect_success 'git add --refresh' '
175 >foo && git add foo && git commit -a -m "commit all" &&
176 test -z "`git diff-index HEAD -- foo`" &&
177 git read-tree HEAD &&
178 case "`git diff-index HEAD -- foo`" in
179 :100644" "*"M foo") echo pass;;
180 *) echo fail; (exit 1);;
182 git add --refresh -- foo &&
183 test -z "`git diff-index HEAD -- foo`"
186 test_expect_success 'git add --refresh with pathspec' '
188 echo >foo && echo >bar && echo >baz &&
189 git add foo bar baz && H=$(git rev-parse :foo) && git rm -f foo &&
190 echo "100644 $H 3 foo" | git update-index --index-info &&
191 test-chmtime -60 bar baz &&
193 git add --refresh bar >actual &&
194 test_cmp expect actual &&
196 git diff-files --name-only >actual &&
201 test_expect_success POSIXPERM,SANITY 'git add should fail atomically upon an unreadable file' '
206 test_must_fail git add --verbose . &&
207 ! ( git ls-files foo1 | grep foo1 )
212 test_expect_success POSIXPERM,SANITY 'git add --ignore-errors' '
217 test_must_fail git add --verbose --ignore-errors . &&
218 git ls-files foo1 | grep foo1
223 test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors)' '
224 git config add.ignore-errors 1 &&
229 test_must_fail git add --verbose . &&
230 git ls-files foo1 | grep foo1
234 test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors = false)' '
235 git config add.ignore-errors 0 &&
240 test_must_fail git add --verbose . &&
241 ! ( git ls-files foo1 | grep foo1 )
245 test_expect_success POSIXPERM,SANITY '--no-ignore-errors overrides config' '
246 git config add.ignore-errors 1 &&
251 test_must_fail git add --verbose --no-ignore-errors . &&
252 ! ( git ls-files foo1 | grep foo1 ) &&
253 git config add.ignore-errors 0
257 test_expect_success BSLASHPSPEC "git add 'fo\\[ou\\]bar' ignores foobar" '
259 touch fo\[ou\]bar foobar &&
260 git add '\''fo\[ou\]bar'\'' &&
261 git ls-files fo\[ou\]bar | fgrep fo\[ou\]bar &&
262 ! ( git ls-files foobar | grep foobar )
265 test_expect_success 'git add to resolve conflicts on otherwise ignored path' '
267 H=$(git rev-parse :1/2/a) &&
269 echo "100644 $H 1 track-this"
270 echo "100644 $H 3 track-this"
271 ) | git update-index --index-info &&
272 echo track-this >>.gitignore &&
273 echo resolved >track-this &&
277 test_expect_success '"add non-existent" should fail' '
278 test_must_fail git add non-existent &&
279 ! (git ls-files | grep "non-existent")
282 test_expect_success 'git add -A on empty repo does not error out' '
292 test_expect_success '"git add ." in empty repo' '
301 test_expect_success 'git add --dry-run of existing changed file' "
302 echo new >>track-this &&
303 git add --dry-run track-this >actual 2>&1 &&
304 echo \"add 'track-this'\" | test_cmp - actual
307 test_expect_success 'git add --dry-run of non-existing file' "
308 echo ignored-file >>.gitignore &&
309 test_must_fail git add --dry-run track-this ignored-file >actual 2>&1
312 test_expect_success 'git add --dry-run of an existing file output' "
313 echo \"fatal: pathspec 'ignored-file' did not match any files\" >expect &&
314 test_i18ncmp expect actual
317 cat >expect.err <<\EOF
318 The following paths are ignored by one of your .gitignore files:
320 Use -f if you really want to add them.
322 cat >expect.out <<\EOF
326 test_expect_success 'git add --dry-run --ignore-missing of non-existing file' '
327 test_must_fail git add --dry-run --ignore-missing track-this ignored-file >actual.out 2>actual.err
330 test_expect_success 'git add --dry-run --ignore-missing of non-existing file output' '
331 test_i18ncmp expect.out actual.out &&
332 test_i18ncmp expect.err actual.err