allow git-am to run in a subdirectory
[git/peff.git] / t / t3700-add.sh
blob287e058e3766df129dcde82aeddecac59b46e2a6
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_expect_success 'git add: filemode=0 should not get confused by symlink' '
34 rm -f xfoo1 &&
35 ln -s foo xfoo1 &&
36 git add xfoo1 &&
37 case "`git ls-files --stage xfoo1`" in
38 120000" "*xfoo1) echo ok;;
39 *) echo fail; git ls-files --stage xfoo1; (exit 1);;
40 esac
43 test_expect_success \
44 'git update-index --add: Test that executable bit is not used...' \
45 'git config core.filemode 0 &&
46 echo foo >xfoo2 &&
47 chmod 755 xfoo2 &&
48 git update-index --add xfoo2 &&
49 case "`git ls-files --stage xfoo2`" in
50 100644" "*xfoo2) echo ok;;
51 *) echo fail; git ls-files --stage xfoo2; (exit 1);;
52 esac'
54 test_expect_success 'git add: filemode=0 should not get confused by symlink' '
55 rm -f xfoo2 &&
56 ln -s foo xfoo2 &&
57 git update-index --add xfoo2 &&
58 case "`git ls-files --stage xfoo2`" in
59 120000" "*xfoo2) echo ok;;
60 *) echo fail; git ls-files --stage xfoo2; (exit 1);;
61 esac
64 test_expect_success \
65 'git update-index --add: Test that executable bit is not used...' \
66 'git config core.filemode 0 &&
67 ln -s xfoo2 xfoo3 &&
68 git update-index --add xfoo3 &&
69 case "`git ls-files --stage xfoo3`" in
70 120000" "*xfoo3) echo ok;;
71 *) echo fail; git ls-files --stage xfoo3; (exit 1);;
72 esac'
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
82 test_expect_success '.gitignore is honored' '
83 git add . &&
84 ! git ls-files | grep "\\.ig"
87 test_expect_success 'error out when attempting to add ignored ones without -f' '
88 ! git add a.?? &&
89 ! git ls-files | grep "\\.ig"
92 test_expect_success 'error out when attempting to add ignored ones without -f' '
93 ! git add d.?? &&
94 ! git ls-files | grep "\\.ig"
97 test_expect_success 'add ignored ones with -f' '
98 git add -f a.?? &&
99 git ls-files --error-unmatch a.ig
102 test_expect_success 'add ignored ones with -f' '
103 git add -f d.??/* &&
104 git ls-files --error-unmatch d.ig/d.if d.ig/d.ig
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
113 test_expect_success '.gitignore with subdirectory' '
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 &&
124 cd sub/dir &&
125 git add .
126 ) &&
127 git ls-files --error-unmatch sub/dir/a.ig
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' '
133 rm -f .git/index &&
134 git add 1/2/a 1/3/b 1/2/c
137 test_expect_success 'git add with filemode=0, symlinks=0, and unmerged entries' '
138 for s in 1 2 3
140 echo $s > stage$s
141 echo "100755 $(git hash-object -w stage$s) $s file"
142 echo "120000 $(printf $s | git hash-object -w -t blob --stdin) $s symlink"
143 done | git update-index --index-info &&
144 git config core.filemode 0 &&
145 git config core.symlinks 0 &&
146 echo new > file &&
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$"
153 test_expect_success 'git add with filemode=0, symlinks=0 prefers stage 2 over stage 1' '
154 git rm --cached -f file symlink &&
156 echo "100644 $(git hash-object -w stage1) 1 file"
157 echo "100755 $(git hash-object -w stage2) 2 file"
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"
160 ) | git update-index --index-info &&
161 git config core.filemode 0 &&
162 git config core.symlinks 0 &&
163 echo new > file &&
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$"
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`"
182 test_done