]>
Commit | Line | Data |
---|---|---|
60ace879 CW |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2006 Carl D. Worth | |
4 | # | |
5 | ||
5be60078 | 6 | test_description='Test of git add, including the -- option.' |
60ace879 CW |
7 | |
8 | . ./test-lib.sh | |
9 | ||
10 | test_expect_success \ | |
5be60078 JH |
11 | 'Test of git add' \ |
12 | 'touch foo && git add foo' | |
60ace879 CW |
13 | |
14 | test_expect_success \ | |
15 | 'Post-check that foo is in the index' \ | |
5be60078 | 16 | 'git ls-files foo | grep foo' |
60ace879 CW |
17 | |
18 | test_expect_success \ | |
5be60078 JH |
19 | 'Test that "git add -- -q" works' \ |
20 | 'touch -- -q && git add -- -q' | |
60ace879 | 21 | |
fd28b34a | 22 | test_expect_success \ |
5be60078 | 23 | 'git add: Test that executable bit is not used if core.filemode=0' \ |
e0d10e1c | 24 | 'git config core.filemode 0 && |
fd28b34a SP |
25 | echo foo >xfoo1 && |
26 | chmod 755 xfoo1 && | |
5be60078 JH |
27 | git add xfoo1 && |
28 | case "`git ls-files --stage xfoo1`" in | |
fd28b34a | 29 | 100644" "*xfoo1) echo ok;; |
5be60078 | 30 | *) echo fail; git ls-files --stage xfoo1; (exit 1);; |
fd28b34a SP |
31 | esac' |
32 | ||
704a3143 | 33 | test_expect_success SYMLINKS 'git add: filemode=0 should not get confused by symlink' ' |
185c975f JH |
34 | rm -f xfoo1 && |
35 | ln -s foo xfoo1 && | |
5be60078 JH |
36 | git add xfoo1 && |
37 | case "`git ls-files --stage xfoo1`" in | |
185c975f | 38 | 120000" "*xfoo1) echo ok;; |
5be60078 | 39 | *) echo fail; git ls-files --stage xfoo1; (exit 1);; |
185c975f JH |
40 | esac |
41 | ' | |
42 | ||
fd28b34a | 43 | test_expect_success \ |
5be60078 | 44 | 'git update-index --add: Test that executable bit is not used...' \ |
e0d10e1c | 45 | 'git config core.filemode 0 && |
fd28b34a SP |
46 | echo foo >xfoo2 && |
47 | chmod 755 xfoo2 && | |
5be60078 JH |
48 | git update-index --add xfoo2 && |
49 | case "`git ls-files --stage xfoo2`" in | |
fd28b34a | 50 | 100644" "*xfoo2) echo ok;; |
5be60078 | 51 | *) echo fail; git ls-files --stage xfoo2; (exit 1);; |
2bbaaed9 JH |
52 | esac' |
53 | ||
704a3143 | 54 | test_expect_success SYMLINKS 'git add: filemode=0 should not get confused by symlink' ' |
185c975f JH |
55 | rm -f xfoo2 && |
56 | ln -s foo xfoo2 && | |
57 | git update-index --add xfoo2 && | |
5be60078 | 58 | case "`git ls-files --stage xfoo2`" in |
185c975f | 59 | 120000" "*xfoo2) echo ok;; |
5be60078 | 60 | *) echo fail; git ls-files --stage xfoo2; (exit 1);; |
185c975f JH |
61 | esac |
62 | ' | |
63 | ||
704a3143 | 64 | test_expect_success SYMLINKS \ |
5be60078 | 65 | 'git update-index --add: Test that executable bit is not used...' \ |
e0d10e1c | 66 | 'git config core.filemode 0 && |
2bbaaed9 | 67 | ln -s xfoo2 xfoo3 && |
5be60078 JH |
68 | git update-index --add xfoo3 && |
69 | case "`git ls-files --stage xfoo3`" in | |
2bbaaed9 | 70 | 120000" "*xfoo3) echo ok;; |
5be60078 | 71 | *) echo fail; git ls-files --stage xfoo3; (exit 1);; |
fd28b34a SP |
72 | esac' |
73 | ||
4d06f8ac JH |
74 | test_expect_success '.gitignore test setup' ' |
75 | echo "*.ig" >.gitignore && | |
76 | mkdir c.if d.ig && | |
77 | >a.ig && >b.if && | |
78 | >c.if/c.if && >c.if/c.ig && | |
79 | >d.ig/d.if && >d.ig/d.ig | |
80 | ' | |
81 | ||
82 | test_expect_success '.gitignore is honored' ' | |
5be60078 | 83 | git add . && |
bbf08124 | 84 | ! (git ls-files | grep "\\.ig") |
4d06f8ac JH |
85 | ' |
86 | ||
87 | test_expect_success 'error out when attempting to add ignored ones without -f' ' | |
d492b31c | 88 | test_must_fail git add a.?? && |
bbf08124 | 89 | ! (git ls-files | grep "\\.ig") |
4d06f8ac JH |
90 | ' |
91 | ||
92 | test_expect_success 'error out when attempting to add ignored ones without -f' ' | |
d492b31c | 93 | test_must_fail git add d.?? && |
bbf08124 | 94 | ! (git ls-files | grep "\\.ig") |
4d06f8ac JH |
95 | ' |
96 | ||
97 | test_expect_success 'add ignored ones with -f' ' | |
5be60078 JH |
98 | git add -f a.?? && |
99 | git ls-files --error-unmatch a.ig | |
4d06f8ac JH |
100 | ' |
101 | ||
102 | test_expect_success 'add ignored ones with -f' ' | |
5be60078 JH |
103 | git add -f d.??/* && |
104 | git ls-files --error-unmatch d.ig/d.if d.ig/d.ig | |
4d06f8ac JH |
105 | ' |
106 | ||
41a7aa58 JH |
107 | test_expect_success 'add ignored ones with -f' ' |
108 | rm -f .git/index && | |
109 | git add -f d.?? && | |
110 | git ls-files --error-unmatch d.ig/d.if d.ig/d.ig | |
111 | ' | |
112 | ||
113 | test_expect_success '.gitignore with subdirectory' ' | |
114 | ||
115 | rm -f .git/index && | |
116 | mkdir -p sub/dir && | |
117 | echo "!dir/a.*" >sub/.gitignore && | |
118 | >sub/a.ig && | |
119 | >sub/dir/a.ig && | |
120 | git add sub/dir && | |
121 | git ls-files --error-unmatch sub/dir/a.ig && | |
122 | rm -f .git/index && | |
123 | ( | |
124 | cd sub/dir && | |
125 | git add . | |
126 | ) && | |
127 | git ls-files --error-unmatch sub/dir/a.ig | |
128 | ' | |
129 | ||
c7f34c18 JS |
130 | mkdir 1 1/2 1/3 |
131 | touch 1/2/a 1/3/b 1/2/c | |
132 | test_expect_success 'check correct prefix detection' ' | |
41a7aa58 | 133 | rm -f .git/index && |
c7f34c18 JS |
134 | git add 1/2/a 1/3/b 1/2/c |
135 | ' | |
136 | ||
05dcd698 | 137 | test_expect_success 'git add with filemode=0, symlinks=0, and unmerged entries' ' |
20314271 JS |
138 | for s in 1 2 3 |
139 | do | |
05dcd698 | 140 | echo $s > stage$s |
20314271 | 141 | echo "100755 $(git hash-object -w stage$s) $s file" |
05dcd698 | 142 | echo "120000 $(printf $s | git hash-object -w -t blob --stdin) $s symlink" |
20314271 JS |
143 | done | git update-index --index-info && |
144 | git config core.filemode 0 && | |
05dcd698 | 145 | git config core.symlinks 0 && |
20314271 | 146 | echo new > file && |
05dcd698 JS |
147 | echo new > symlink && |
148 | git add file symlink && | |
149 | git ls-files --stage | grep "^100755 .* 0 file$" && | |
150 | git ls-files --stage | grep "^120000 .* 0 symlink$" | |
20314271 JS |
151 | ' |
152 | ||
05dcd698 JS |
153 | test_expect_success 'git add with filemode=0, symlinks=0 prefers stage 2 over stage 1' ' |
154 | git rm --cached -f file symlink && | |
20314271 JS |
155 | ( |
156 | echo "100644 $(git hash-object -w stage1) 1 file" | |
157 | echo "100755 $(git hash-object -w stage2) 2 file" | |
a697ec69 JH |
158 | echo "100644 $(printf 1 | git hash-object -w -t blob --stdin) 1 symlink" |
159 | echo "120000 $(printf 2 | git hash-object -w -t blob --stdin) 2 symlink" | |
20314271 JS |
160 | ) | git update-index --index-info && |
161 | git config core.filemode 0 && | |
05dcd698 | 162 | git config core.symlinks 0 && |
20314271 | 163 | echo new > file && |
05dcd698 JS |
164 | echo new > symlink && |
165 | git add file symlink && | |
166 | git ls-files --stage | grep "^100755 .* 0 file$" && | |
167 | git ls-files --stage | grep "^120000 .* 0 symlink$" | |
20314271 JS |
168 | ' |
169 | ||
d616813d AJ |
170 | test_expect_success 'git add --refresh' ' |
171 | >foo && git add foo && git commit -a -m "commit all" && | |
172 | test -z "`git diff-index HEAD -- foo`" && | |
173 | git read-tree HEAD && | |
174 | case "`git diff-index HEAD -- foo`" in | |
175 | :100644" "*"M foo") echo ok;; | |
176 | *) echo fail; (exit 1);; | |
177 | esac && | |
178 | git add --refresh -- foo && | |
179 | test -z "`git diff-index HEAD -- foo`" | |
180 | ' | |
181 | ||
ee9fb68c | 182 | test_expect_success POSIXPERM 'git add should fail atomically upon an unreadable file' ' |
89597436 AR |
183 | git reset --hard && |
184 | date >foo1 && | |
185 | date >foo2 && | |
186 | chmod 0 foo2 && | |
187 | test_must_fail git add --verbose . && | |
188 | ! ( git ls-files foo1 | grep foo1 ) | |
189 | ' | |
190 | ||
191 | rm -f foo2 | |
192 | ||
ee9fb68c | 193 | test_expect_success POSIXPERM 'git add --ignore-errors' ' |
89597436 AR |
194 | git reset --hard && |
195 | date >foo1 && | |
196 | date >foo2 && | |
197 | chmod 0 foo2 && | |
198 | test_must_fail git add --verbose --ignore-errors . && | |
199 | git ls-files foo1 | grep foo1 | |
200 | ' | |
201 | ||
202 | rm -f foo2 | |
203 | ||
ee9fb68c | 204 | test_expect_success POSIXPERM 'git add (add.ignore-errors)' ' |
dad25e4a AR |
205 | git config add.ignore-errors 1 && |
206 | git reset --hard && | |
207 | date >foo1 && | |
208 | date >foo2 && | |
209 | chmod 0 foo2 && | |
210 | test_must_fail git add --verbose . && | |
211 | git ls-files foo1 | grep foo1 | |
212 | ' | |
213 | rm -f foo2 | |
214 | ||
ee9fb68c | 215 | test_expect_success POSIXPERM 'git add (add.ignore-errors = false)' ' |
dad25e4a AR |
216 | git config add.ignore-errors 0 && |
217 | git reset --hard && | |
218 | date >foo1 && | |
219 | date >foo2 && | |
220 | chmod 0 foo2 && | |
221 | test_must_fail git add --verbose . && | |
222 | ! ( git ls-files foo1 | grep foo1 ) | |
223 | ' | |
ed342fde SB |
224 | rm -f foo2 |
225 | ||
1ab012cf | 226 | test_expect_success POSIXPERM '--no-ignore-errors overrides config' ' |
ed342fde SB |
227 | git config add.ignore-errors 1 && |
228 | git reset --hard && | |
229 | date >foo1 && | |
230 | date >foo2 && | |
231 | chmod 0 foo2 && | |
232 | test_must_fail git add --verbose --no-ignore-errors . && | |
233 | ! ( git ls-files foo1 | grep foo1 ) && | |
234 | git config add.ignore-errors 0 | |
235 | ' | |
236 | rm -f foo2 | |
dad25e4a | 237 | |
6fd1106a | 238 | test_expect_success BSLASHPSPEC "git add 'fo\\[ou\\]bar' ignores foobar" ' |
ea335b56 | 239 | git reset --hard && |
8134a003 AR |
240 | touch fo\[ou\]bar foobar && |
241 | git add '\''fo\[ou\]bar'\'' && | |
87539416 | 242 | git ls-files fo\[ou\]bar | fgrep fo\[ou\]bar && |
ea335b56 KB |
243 | ! ( git ls-files foobar | grep foobar ) |
244 | ' | |
245 | ||
6e4f981f JK |
246 | test_expect_success 'git add to resolve conflicts on otherwise ignored path' ' |
247 | git reset --hard && | |
248 | H=$(git rev-parse :1/2/a) && | |
249 | ( | |
250 | echo "100644 $H 1 track-this" | |
251 | echo "100644 $H 3 track-this" | |
252 | ) | git update-index --index-info && | |
253 | echo track-this >>.gitignore && | |
254 | echo resolved >track-this && | |
255 | git add track-this | |
256 | ' | |
257 | ||
1e7ef746 CP |
258 | test_expect_success '"add non-existent" should fail' ' |
259 | test_must_fail git add non-existent && | |
260 | ! (git ls-files | grep "non-existent") | |
261 | ' | |
262 | ||
60ace879 | 263 | test_done |