3 # Copyright (c) Robin Rosenberg
5 test_description='Test export of commits to CVS'
8 . "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh
10 if ! test_have_prereq PERL; then
11 skip_all='skipping git cvsexportcommit tests, perl not available'
18 skip_all='skipping git cvsexportcommit tests, cvs not found'
25 export CVSROOT CVSWORK GIT_DIR
27 rm -rf "$CVSROOT" "$CVSWORK"
30 cvs -Q co -d "$CVSWORK" . &&
33 git commit -q -a -m "Initial" 2>/dev/null ||
37 # $1 == directory, $2 == expected
38 grep '^/' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
43 printf '%s\n' "$2" | tr '|' '\012' >expected
45 test_cmp expected actual
51 echo hello1 >A/newfile1.txt &&
52 echo hello2 >B/newfile2.txt &&
53 cp "$TEST_DIRECTORY"/test-binary-1.png C/newfile3.png &&
54 cp "$TEST_DIRECTORY"/test-binary-1.png D/newfile4.png &&
55 git add A/newfile1.txt &&
56 git add B/newfile2.txt &&
57 git add C/newfile3.png &&
58 git add D/newfile4.png &&
59 git commit -a -m "Test: New file" &&
60 id=$(git rev-list --max-count=1 HEAD) &&
62 git cvsexportcommit -c $id &&
63 check_entries A "newfile1.txt/1.1/" &&
64 check_entries B "newfile2.txt/1.1/" &&
65 check_entries C "newfile3.png/1.1/-kb" &&
66 check_entries D "newfile4.png/1.1/-kb" &&
67 test_cmp A/newfile1.txt ../A/newfile1.txt &&
68 test_cmp B/newfile2.txt ../B/newfile2.txt &&
69 test_cmp C/newfile3.png ../C/newfile3.png &&
70 test_cmp D/newfile4.png ../D/newfile4.png
74 'Remove two files, add two and update two' \
75 'echo Hello1 >>A/newfile1.txt &&
76 rm -f B/newfile2.txt &&
77 rm -f C/newfile3.png &&
78 echo Hello5 >E/newfile5.txt &&
79 cp "$TEST_DIRECTORY"/test-binary-2.png D/newfile4.png &&
80 cp "$TEST_DIRECTORY"/test-binary-1.png F/newfile6.png &&
81 git add E/newfile5.txt &&
82 git add F/newfile6.png &&
83 git commit -a -m "Test: Remove, add and update" &&
84 id=$(git rev-list --max-count=1 HEAD) &&
86 git cvsexportcommit -c $id &&
87 check_entries A "newfile1.txt/1.2/" &&
90 check_entries D "newfile4.png/1.2/-kb" &&
91 check_entries E "newfile5.txt/1.1/" &&
92 check_entries F "newfile6.png/1.1/-kb" &&
93 test_cmp A/newfile1.txt ../A/newfile1.txt &&
94 test_cmp D/newfile4.png ../D/newfile4.png &&
95 test_cmp E/newfile5.txt ../E/newfile5.txt &&
96 test_cmp F/newfile6.png ../F/newfile6.png
99 # Should fail (but only on the git cvsexportcommit stage)
100 test_expect_success \
101 'Fail to change binary more than one generation old' \
102 'cat F/newfile6.png >>D/newfile4.png &&
103 git commit -a -m "generatiion 1" &&
104 cat F/newfile6.png >>D/newfile4.png &&
105 git commit -a -m "generation 2" &&
106 id=$(git rev-list --max-count=1 HEAD) &&
108 test_must_fail git cvsexportcommit -c $id
111 #test_expect_success \
112 # 'Fail to remove binary file more than one generation old' \
113 # 'git reset --hard HEAD^ &&
114 # cat F/newfile6.png >>D/newfile4.png &&
115 # git commit -a -m "generation 2 (again)" &&
116 # rm -f D/newfile4.png &&
117 # git commit -a -m "generation 3" &&
118 # id=$(git rev-list --max-count=1 HEAD) &&
120 # test_must_fail git cvsexportcommit -c $id
123 # We reuse the state from two tests back here
125 # This test is here because a patch for only binary files will
126 # fail with gnu patch, so cvsexportcommit must handle that.
127 test_expect_success \
128 'Remove only binary files' \
129 'git reset --hard HEAD^^ &&
130 rm -f D/newfile4.png &&
131 git commit -a -m "test: remove only a binary file" &&
132 id=$(git rev-list --max-count=1 HEAD) &&
134 git cvsexportcommit -c $id &&
135 check_entries A "newfile1.txt/1.2/" &&
136 check_entries B "" &&
137 check_entries C "" &&
138 check_entries D "" &&
139 check_entries E "newfile5.txt/1.1/" &&
140 check_entries F "newfile6.png/1.1/-kb" &&
141 test_cmp A/newfile1.txt ../A/newfile1.txt &&
142 test_cmp E/newfile5.txt ../E/newfile5.txt &&
143 test_cmp F/newfile6.png ../F/newfile6.png
146 test_expect_success \
147 'Remove only a text file' \
148 'rm -f A/newfile1.txt &&
149 git commit -a -m "test: remove only a binary file" &&
150 id=$(git rev-list --max-count=1 HEAD) &&
152 git cvsexportcommit -c $id &&
153 check_entries A "" &&
154 check_entries B "" &&
155 check_entries C "" &&
156 check_entries D "" &&
157 check_entries E "newfile5.txt/1.1/" &&
158 check_entries F "newfile6.png/1.1/-kb" &&
159 test_cmp E/newfile5.txt ../E/newfile5.txt &&
160 test_cmp F/newfile6.png ../F/newfile6.png
163 test_expect_success \
164 'New file with spaces in file name' \
166 echo ok then >"G g/with spaces.txt" &&
167 git add "G g/with spaces.txt" && \
168 cp "$TEST_DIRECTORY"/test-binary-1.png "G g/with spaces.png" && \
169 git add "G g/with spaces.png" &&
170 git commit -a -m "With spaces" &&
171 id=$(git rev-list --max-count=1 HEAD) &&
173 git cvsexportcommit -c $id &&
174 check_entries "G g" "with spaces.png/1.1/-kb|with spaces.txt/1.1/"
177 test_expect_success \
178 'Update file with spaces in file name' \
179 'echo Ok then >>"G g/with spaces.txt" &&
180 cat "$TEST_DIRECTORY"/test-binary-1.png >>"G g/with spaces.png" && \
181 git add "G g/with spaces.png" &&
182 git commit -a -m "Update with spaces" &&
183 id=$(git rev-list --max-count=1 HEAD) &&
185 git cvsexportcommit -c $id
186 check_entries "G g" "with spaces.png/1.2/-kb|with spaces.txt/1.2/"
189 # Some filesystems mangle pathnames with UTF-8 characters --
191 if p="Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö" &&
193 date >"tst/$p/day" &&
194 found=$(find tst -type f -print) &&
195 test "z$found" = "ztst/$p/day" &&
199 # This test contains UTF-8 characters
200 test_expect_success \
201 'File with non-ascii file name' \
202 'mkdir -p Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö &&
203 echo Foo >Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.txt &&
204 git add Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.txt &&
205 cp "$TEST_DIRECTORY"/test-binary-1.png Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.png &&
206 git add Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.png &&
207 git commit -a -m "Går det så går det" && \
208 id=$(git rev-list --max-count=1 HEAD) &&
210 git cvsexportcommit -v -c $id &&
212 "Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö" \
213 "gårdetsågårdet.png/1.1/-kb|gårdetsågårdet.txt/1.1/"
220 test_expect_success \
221 'Mismatching patch should fail' \
222 'date >>"E/newfile5.txt" &&
223 git add "E/newfile5.txt" &&
224 git commit -a -m "Update one" &&
225 date >>"E/newfile5.txt" &&
226 git add "E/newfile5.txt" &&
227 git commit -a -m "Update two" &&
228 id=$(git rev-list --max-count=1 HEAD) &&
230 test_must_fail git cvsexportcommit -c $id
233 test_expect_success FILEMODE \
234 'Retain execute bit' \
236 echo executeon >G/on &&
238 echo executeoff >G/off &&
241 git commit -a -m "Execute test" &&
243 git cvsexportcommit -c HEAD
248 test_expect_success '-w option should work with relative GIT_DIR' '
250 echo foobar >W/file1.txt &&
251 echo bazzle >W/file2.txt &&
252 git add W/file1.txt &&
253 git add W/file2.txt &&
254 git commit -m "More updates" &&
255 id=$(git rev-list --max-count=1 HEAD) &&
257 GIT_DIR=. git cvsexportcommit -w "$CVSWORK" -c $id &&
258 check_entries "$CVSWORK/W" "file1.txt/1.1/|file2.txt/1.1/" &&
259 test_cmp "$CVSWORK/W/file1.txt" ../W/file1.txt &&
260 test_cmp "$CVSWORK/W/file2.txt" ../W/file2.txt
264 test_expect_success 'check files before directories' '
266 echo Notes > release-notes &&
267 git add release-notes &&
268 git commit -m "Add release notes" release-notes &&
269 id=$(git rev-parse HEAD) &&
270 git cvsexportcommit -w "$CVSWORK" -c $id &&
274 echo modified > release-notes &&
275 git add DS E/DS release-notes &&
276 git commit -m "Add two files with the same basename" &&
277 id=$(git rev-parse HEAD) &&
278 git cvsexportcommit -w "$CVSWORK" -c $id &&
279 check_entries "$CVSWORK/E" "DS/1.1/|newfile5.txt/1.1/" &&
280 check_entries "$CVSWORK" "DS/1.1/|release-notes/1.2/" &&
281 test_cmp "$CVSWORK/DS" DS &&
282 test_cmp "$CVSWORK/E/DS" E/DS &&
283 test_cmp "$CVSWORK/release-notes" release-notes
287 test_expect_success 're-commit a removed filename which remains in CVS attic' '
290 echo >attic_gremlin &&
291 cvs -Q add attic_gremlin &&
292 cvs -Q ci -m "added attic_gremlin" &&
294 cvs -Q rm attic_gremlin &&
295 cvs -Q ci -m "removed attic_gremlin") &&
297 echo > attic_gremlin &&
298 git add attic_gremlin &&
299 git commit -m "Added attic_gremlin" &&
300 git cvsexportcommit -w "$CVSWORK" -c HEAD &&
301 (cd "$CVSWORK"; cvs -Q update -d) &&
302 test -f "$CVSWORK/attic_gremlin"
305 # the state of the CVS sandbox may be indeterminate for ' space'
306 # after this test on some platforms / with some versions of CVS
307 # consider adding new tests above this point
308 test_expect_success 'commit a file with leading spaces in the name' '
310 echo space > " space" &&
312 git commit -m "Add a file with a leading space" &&
313 id=$(git rev-parse HEAD) &&
314 git cvsexportcommit -w "$CVSWORK" -c $id &&
315 check_entries "$CVSWORK" " space/1.1/|DS/1.1/|attic_gremlin/1.3/|release-notes/1.2/" &&
316 test_cmp "$CVSWORK/ space" " space"
320 test_expect_success 'use the same checkout for Git and CVS' '
328 git commit -m "fake initial commit" &&
329 echo Hello >> " space" &&
330 git commit -m "Another change" " space" &&
331 git cvsexportcommit -W -p -u -c HEAD &&
332 grep Hello " space" &&