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 ok;;
30 *) echo fail; git ls-files --stage xfoo1; (exit 1);;
33 test "$no_symlinks" ||
{
34 test_expect_success
'git add: filemode=0 should not get confused by symlink' '
38 case "`git ls-files --stage xfoo1`" in
39 120000" "*xfoo1) echo ok;;
40 *) echo fail; git ls-files --stage xfoo1; (exit 1);;
46 'git update-index --add: Test that executable bit is not used...' \
47 'git config core.filemode 0 &&
50 git update-index --add xfoo2 &&
51 case "`git ls-files --stage xfoo2`" in
52 100644" "*xfoo2) echo ok;;
53 *) echo fail; git ls-files --stage xfoo2; (exit 1);;
56 test "$no_symlinks" ||
{
57 test_expect_success
'git add: filemode=0 should not get confused by symlink' '
60 git update-index --add xfoo2 &&
61 case "`git ls-files --stage xfoo2`" in
62 120000" "*xfoo2) echo ok;;
63 *) echo fail; git ls-files --stage xfoo2; (exit 1);;
68 'git update-index --add: Test that executable bit is not used...' \
69 'git config core.filemode 0 &&
71 git update-index --add xfoo3 &&
72 case "`git ls-files --stage xfoo3`" in
73 120000" "*xfoo3) echo ok;;
74 *) echo fail; git ls-files --stage xfoo3; (exit 1);;
78 test_expect_success
'.gitignore test setup' '
79 echo "*.ig" >.gitignore &&
82 >c.if/c.if && >c.if/c.ig &&
83 >d.ig/d.if && >d.ig/d.ig
86 test_expect_success
'.gitignore is honored' '
88 ! git ls-files | grep "\\.ig"
91 test_expect_success
'error out when attempting to add ignored ones without -f' '
93 ! git ls-files | grep "\\.ig"
96 test_expect_success
'error out when attempting to add ignored ones without -f' '
98 ! git ls-files | grep "\\.ig"
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
112 touch 1/2/a
1/3/b
1/2/c
113 test_expect_success
'check correct prefix detection' '
114 git add 1/2/a 1/3/b 1/2/c
117 test_expect_success
'git add with filemode=0, symlinks=0, and unmerged entries' '
121 echo "100755 $(git hash-object -w stage$s) $s file"
122 echo "120000 $(printf $s | git hash-object -w -t blob --stdin) $s symlink"
123 done | git update-index --index-info &&
124 git config core.filemode 0 &&
125 git config core.symlinks 0 &&
127 echo new > symlink &&
128 git add file symlink &&
129 git ls-files --stage | grep "^100755 .* 0 file$" &&
130 git ls-files --stage | grep "^120000 .* 0 symlink$"
133 test_expect_success
'git add with filemode=0, symlinks=0 prefers stage 2 over stage 1' '
134 git rm --cached -f file symlink &&
136 echo "100644 $(git hash-object -w stage1) 1 file"
137 echo "100755 $(git hash-object -w stage2) 2 file"
138 echo "100644 $(printf 1 | git hash-object -w -t blob --stdin) 1 symlink"
139 echo "120000 $(printf 2 | git hash-object -w -t blob --stdin) 2 symlink"
140 ) | git update-index --index-info &&
141 git config core.filemode 0 &&
142 git config core.symlinks 0 &&
144 echo new > symlink &&
145 git add file symlink &&
146 git ls-files --stage | grep "^100755 .* 0 file$" &&
147 git ls-files --stage | grep "^120000 .* 0 symlink$"
150 test_expect_success
'git add --refresh' '
151 >foo && git add foo && git commit -a -m "commit all" &&
152 test -z "`git diff-index HEAD -- foo`" &&
153 git read-tree HEAD &&
154 case "`git diff-index HEAD -- foo`" in
155 :100644" "*"M foo") echo ok;;
156 *) echo fail; (exit 1);;
158 git add --refresh -- foo &&
159 test -z "`git diff-index HEAD -- foo`"