Merge commit 'junio/next' into next
[git/platforms/storm.git] / t / t3700-add.sh
blob79cb00d1e8a683029c1079934059bb416c19a019
1 #!/bin/sh
3 # Copyright (c) 2006 Carl D. Worth
6 test_description='Test of git add, including the -- option.'
8 . ./test-lib.sh
10 test_expect_success \
11 'Test of git add' \
12 'touch foo && git add foo'
14 test_expect_success \
15 'Post-check that foo is in the index' \
16 'git ls-files foo | grep foo'
18 test_expect_success \
19 'Test that "git add -- -q" works' \
20 'touch -- -q && git add -- -q'
22 test_expect_success \
23 'git add: Test that executable bit is not used if core.filemode=0' \
24 'git config core.filemode 0 &&
25 echo foo >xfoo1 &&
26 chmod 755 xfoo1 &&
27 git add xfoo1 &&
28 case "`git ls-files --stage xfoo1`" in
29 100644" "*xfoo1) echo ok;;
30 *) echo fail; git ls-files --stage xfoo1; (exit 1);;
31 esac'
33 test "$no_symlinks" || {
34 test_expect_success 'git add: filemode=0 should not get confused by symlink' '
35 rm -f xfoo1 &&
36 ln -s foo xfoo1 &&
37 git add xfoo1 &&
38 case "`git ls-files --stage xfoo1`" in
39 120000" "*xfoo1) echo ok;;
40 *) echo fail; git ls-files --stage xfoo1; (exit 1);;
41 esac
45 test_expect_success \
46 'git update-index --add: Test that executable bit is not used...' \
47 'git config core.filemode 0 &&
48 echo foo >xfoo2 &&
49 chmod 755 xfoo2 &&
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);;
54 esac'
56 test "$no_symlinks" || {
57 test_expect_success 'git add: filemode=0 should not get confused by symlink' '
58 rm -f xfoo2 &&
59 ln -s foo xfoo2 &&
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);;
64 esac
67 test_expect_success \
68 'git update-index --add: Test that executable bit is not used...' \
69 'git config core.filemode 0 &&
70 ln -s xfoo2 xfoo3 &&
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);;
75 esac'
78 test_expect_success '.gitignore test setup' '
79 echo "*.ig" >.gitignore &&
80 mkdir c.if d.ig &&
81 >a.ig && >b.if &&
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' '
87 git add . &&
88 ! (git ls-files | grep "\\.ig")
91 test_expect_success 'error out when attempting to add ignored ones without -f' '
92 ! git add a.?? &&
93 ! (git ls-files | grep "\\.ig")
96 test_expect_success 'error out when attempting to add ignored ones without -f' '
97 ! git add d.?? &&
98 ! (git ls-files | grep "\\.ig")
101 test_expect_success 'add ignored ones with -f' '
102 git add -f a.?? &&
103 git ls-files --error-unmatch a.ig
106 test_expect_success 'add ignored ones with -f' '
107 git add -f d.??/* &&
108 git ls-files --error-unmatch d.ig/d.if d.ig/d.ig
111 test_expect_success 'add ignored ones with -f' '
112 rm -f .git/index &&
113 git add -f d.?? &&
114 git ls-files --error-unmatch d.ig/d.if d.ig/d.ig
117 test_expect_success '.gitignore with subdirectory' '
119 rm -f .git/index &&
120 mkdir -p sub/dir &&
121 echo "!dir/a.*" >sub/.gitignore &&
122 >sub/a.ig &&
123 >sub/dir/a.ig &&
124 git add sub/dir &&
125 git ls-files --error-unmatch sub/dir/a.ig &&
126 rm -f .git/index &&
128 cd sub/dir &&
129 git add .
130 ) &&
131 git ls-files --error-unmatch sub/dir/a.ig
134 mkdir 1 1/2 1/3
135 touch 1/2/a 1/3/b 1/2/c
136 test_expect_success 'check correct prefix detection' '
137 rm -f .git/index &&
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' '
142 for s in 1 2 3
144 echo $s > stage$s
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 &&
150 echo new > file &&
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 &&
167 echo new > file &&
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 ok;;
180 *) echo fail; (exit 1);;
181 esac &&
182 git add --refresh -- foo &&
183 test -z "`git diff-index HEAD -- foo`"
186 test_expect_success 'git add should fail atomically upon an unreadable file' '
187 git reset --hard &&
188 date >foo1 &&
189 date >foo2 &&
190 chmod 0 foo2 &&
191 test_must_fail git add --verbose . &&
192 ! ( git ls-files foo1 | grep foo1 )
195 rm -f foo2
197 test_expect_success 'git add --ignore-errors' '
198 git reset --hard &&
199 date >foo1 &&
200 date >foo2 &&
201 chmod 0 foo2 &&
202 test_must_fail git add --verbose --ignore-errors . &&
203 git ls-files foo1 | grep foo1
206 rm -f foo2
208 test_expect_success 'git add (add.ignore-errors)' '
209 git config add.ignore-errors 1 &&
210 git reset --hard &&
211 date >foo1 &&
212 date >foo2 &&
213 chmod 0 foo2 &&
214 test_must_fail git add --verbose . &&
215 git ls-files foo1 | grep foo1
217 rm -f foo2
219 test_expect_success 'git add (add.ignore-errors = false)' '
220 git config add.ignore-errors 0 &&
221 git reset --hard &&
222 date >foo1 &&
223 date >foo2 &&
224 chmod 0 foo2 &&
225 test_must_fail git add --verbose . &&
226 ! ( git ls-files foo1 | grep foo1 )
229 test_done