3 # Copyright (c) Robin Rosenberg
5 test_description
='Test export of commits to CVS'
7 TEST_PASSES_SANITIZE_LEAK
=true
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'
22 if ! test_have_prereq NOT_ROOT
; then
23 skip_all
='When cvs is compiled with CVS_BADROOT commits as root fail'
27 CVSROOT
=$PWD/tmpcvsroot
30 export CVSROOT CVSWORK GIT_DIR
32 rm -rf "$CVSROOT" "$CVSWORK"
36 cvs
-Q co
-d "$CVSWORK" .
&&
39 git commit
-q -a -m "Initial" 2>/dev
/null ||
43 # $1 == directory, $2 == expected
44 sed -ne '/^\//p' "$1/CVS/Entries" |
sort | cut
-d/ -f2,3,5 >actual
47 test_must_be_empty actual
49 printf '%s\n' "$2" |
tr '|' '\012' >expected
50 test_cmp expected actual
54 test_expect_success
'New file' '
56 echo hello1 >A/newfile1.txt &&
57 echo hello2 >B/newfile2.txt &&
58 cp "$TEST_DIRECTORY"/test-binary-1.png C/newfile3.png &&
59 cp "$TEST_DIRECTORY"/test-binary-1.png D/newfile4.png &&
60 git add A/newfile1.txt &&
61 git add B/newfile2.txt &&
62 git add C/newfile3.png &&
63 git add D/newfile4.png &&
64 git commit -a -m "Test: New file" &&
65 id=$(git rev-list --max-count=1 HEAD) &&
67 git cvsexportcommit -c $id &&
68 check_entries A "newfile1.txt/1.1/" &&
69 check_entries B "newfile2.txt/1.1/" &&
70 check_entries C "newfile3.png/1.1/-kb" &&
71 check_entries D "newfile4.png/1.1/-kb" &&
72 test_cmp A/newfile1.txt ../A/newfile1.txt &&
73 test_cmp B/newfile2.txt ../B/newfile2.txt &&
74 test_cmp C/newfile3.png ../C/newfile3.png &&
75 test_cmp D/newfile4.png ../D/newfile4.png
79 test_expect_success
'Remove two files, add two and update two' '
80 echo Hello1 >>A/newfile1.txt &&
81 rm -f B/newfile2.txt &&
82 rm -f C/newfile3.png &&
83 echo Hello5 >E/newfile5.txt &&
84 cp "$TEST_DIRECTORY"/test-binary-2.png D/newfile4.png &&
85 cp "$TEST_DIRECTORY"/test-binary-1.png F/newfile6.png &&
86 git add E/newfile5.txt &&
87 git add F/newfile6.png &&
88 git commit -a -m "Test: Remove, add and update" &&
89 id=$(git rev-list --max-count=1 HEAD) &&
91 git cvsexportcommit -c $id &&
92 check_entries A "newfile1.txt/1.2/" &&
95 check_entries D "newfile4.png/1.2/-kb" &&
96 check_entries E "newfile5.txt/1.1/" &&
97 check_entries F "newfile6.png/1.1/-kb" &&
98 test_cmp A/newfile1.txt ../A/newfile1.txt &&
99 test_cmp D/newfile4.png ../D/newfile4.png &&
100 test_cmp E/newfile5.txt ../E/newfile5.txt &&
101 test_cmp F/newfile6.png ../F/newfile6.png
105 # Should fail (but only on the git cvsexportcommit stage)
106 test_expect_success \
107 'Fail to change binary more than one generation old' \
108 'cat F/newfile6.png >>D/newfile4.png &&
109 git commit -a -m "generatiion 1" &&
110 cat F/newfile6.png >>D/newfile4.png &&
111 git commit -a -m "generation 2" &&
112 id=$(git rev-list --max-count=1 HEAD) &&
114 test_must_fail git cvsexportcommit -c $id
117 #test_expect_success \
118 # 'Fail to remove binary file more than one generation old' \
119 # 'git reset --hard HEAD^ &&
120 # cat F/newfile6.png >>D/newfile4.png &&
121 # git commit -a -m "generation 2 (again)" &&
122 # rm -f D/newfile4.png &&
123 # git commit -a -m "generation 3" &&
124 # id=$(git rev-list --max-count=1 HEAD) &&
126 # test_must_fail git cvsexportcommit -c $id
129 # We reuse the state from two tests back here
131 # This test is here because a patch for only binary files will
132 # fail with gnu patch, so cvsexportcommit must handle that.
133 test_expect_success
'Remove only binary files' '
134 git reset --hard HEAD^^ &&
135 rm -f D/newfile4.png &&
136 git commit -a -m "test: remove only a binary file" &&
137 id=$(git rev-list --max-count=1 HEAD) &&
139 git cvsexportcommit -c $id &&
140 check_entries A "newfile1.txt/1.2/" &&
141 check_entries B "" &&
142 check_entries C "" &&
143 check_entries D "" &&
144 check_entries E "newfile5.txt/1.1/" &&
145 check_entries F "newfile6.png/1.1/-kb" &&
146 test_cmp A/newfile1.txt ../A/newfile1.txt &&
147 test_cmp E/newfile5.txt ../E/newfile5.txt &&
148 test_cmp F/newfile6.png ../F/newfile6.png
152 test_expect_success
'Remove only a text file' '
153 rm -f A/newfile1.txt &&
154 git commit -a -m "test: remove only a binary file" &&
155 id=$(git rev-list --max-count=1 HEAD) &&
157 git cvsexportcommit -c $id &&
158 check_entries A "" &&
159 check_entries B "" &&
160 check_entries C "" &&
161 check_entries D "" &&
162 check_entries E "newfile5.txt/1.1/" &&
163 check_entries F "newfile6.png/1.1/-kb" &&
164 test_cmp E/newfile5.txt ../E/newfile5.txt &&
165 test_cmp F/newfile6.png ../F/newfile6.png
169 test_expect_success
'New file with spaces in file name' '
171 echo ok then >"G g/with spaces.txt" &&
172 git add "G g/with spaces.txt" && \
173 cp "$TEST_DIRECTORY"/test-binary-1.png "G g/with spaces.png" && \
174 git add "G g/with spaces.png" &&
175 git commit -a -m "With spaces" &&
176 id=$(git rev-list --max-count=1 HEAD) &&
178 git cvsexportcommit -c $id &&
179 check_entries "G g" "with spaces.png/1.1/-kb|with spaces.txt/1.1/"
183 test_expect_success
'Update file with spaces in file name' '
184 echo Ok then >>"G g/with spaces.txt" &&
185 cat "$TEST_DIRECTORY"/test-binary-1.png >>"G g/with spaces.png" && \
186 git add "G g/with spaces.png" &&
187 git commit -a -m "Update with spaces" &&
188 id=$(git rev-list --max-count=1 HEAD) &&
190 git cvsexportcommit -c $id &&
191 check_entries "G g" "with spaces.png/1.2/-kb|with spaces.txt/1.2/"
195 # Some filesystems mangle pathnames with UTF-8 characters --
197 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/å/ä/ö" &&
199 date >"tst/$p/day" &&
200 found
=$
(find tst
-type f
-print) &&
201 test "z$found" = "ztst/$p/day" &&
205 # This test contains UTF-8 characters
206 test_expect_success
!MINGW
'File with non-ascii file name' '
207 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/å/ä/ö &&
208 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 &&
209 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 &&
210 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 &&
211 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 &&
212 git commit -a -m "Går det så går det" && \
213 id=$(git rev-list --max-count=1 HEAD) &&
215 git cvsexportcommit -v -c $id &&
217 "Å/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/å/ä/ö" \
218 "gårdetsågårdet.png/1.1/-kb|gårdetsågårdet.txt/1.1/"
226 test_expect_success
'Mismatching patch should fail' '
227 date >>"E/newfile5.txt" &&
228 git add "E/newfile5.txt" &&
229 git commit -a -m "Update one" &&
230 date >>"E/newfile5.txt" &&
231 git add "E/newfile5.txt" &&
232 git commit -a -m "Update two" &&
233 id=$(git rev-list --max-count=1 HEAD) &&
235 test_must_fail git cvsexportcommit -c $id
239 test_expect_success FILEMODE
'Retain execute bit' '
241 echo executeon >G/on &&
243 echo executeoff >G/off &&
246 git commit -a -m "Execute test" &&
248 git cvsexportcommit -c HEAD &&
254 test_expect_success
'-w option should work with relative GIT_DIR' '
256 echo foobar >W/file1.txt &&
257 echo bazzle >W/file2.txt &&
258 git add W/file1.txt &&
259 git add W/file2.txt &&
260 git commit -m "More updates" &&
261 id=$(git rev-list --max-count=1 HEAD) &&
263 GIT_DIR=. git cvsexportcommit -w "$CVSWORK" -c $id &&
264 check_entries "$CVSWORK/W" "file1.txt/1.1/|file2.txt/1.1/" &&
265 test_cmp "$CVSWORK/W/file1.txt" ../W/file1.txt &&
266 test_cmp "$CVSWORK/W/file2.txt" ../W/file2.txt
270 test_expect_success
'check files before directories' '
272 echo Notes > release-notes &&
273 git add release-notes &&
274 git commit -m "Add release notes" release-notes &&
275 id=$(git rev-parse HEAD) &&
276 git cvsexportcommit -w "$CVSWORK" -c $id &&
280 echo modified > release-notes &&
281 git add DS E/DS release-notes &&
282 git commit -m "Add two files with the same basename" &&
283 id=$(git rev-parse HEAD) &&
284 git cvsexportcommit -w "$CVSWORK" -c $id &&
285 check_entries "$CVSWORK/E" "DS/1.1/|newfile5.txt/1.1/" &&
286 check_entries "$CVSWORK" "DS/1.1/|release-notes/1.2/" &&
287 test_cmp "$CVSWORK/DS" DS &&
288 test_cmp "$CVSWORK/E/DS" E/DS &&
289 test_cmp "$CVSWORK/release-notes" release-notes
293 test_expect_success
're-commit a removed filename which remains in CVS attic' '
295 echo >attic_gremlin &&
296 cvs -Q add attic_gremlin &&
297 cvs -Q ci -m "added attic_gremlin" &&
299 cvs -Q rm attic_gremlin &&
300 cvs -Q ci -m "removed attic_gremlin") &&
302 echo > attic_gremlin &&
303 git add attic_gremlin &&
304 git commit -m "Added attic_gremlin" &&
305 git cvsexportcommit -w "$CVSWORK" -c HEAD &&
306 (cd "$CVSWORK" && cvs -Q update -d) &&
307 test -f "$CVSWORK/attic_gremlin"
310 # the state of the CVS sandbox may be indeterminate for ' space'
311 # after this test on some platforms / with some versions of CVS
312 # consider adding new tests above this point
313 test_expect_success
'commit a file with leading spaces in the name' '
315 echo space > " space" &&
317 git commit -m "Add a file with a leading space" &&
318 id=$(git rev-parse HEAD) &&
319 git cvsexportcommit -w "$CVSWORK" -c $id &&
320 check_entries "$CVSWORK" " space/1.1/|DS/1.1/|attic_gremlin/1.3/|release-notes/1.2/" &&
321 test_cmp "$CVSWORK/ space" " space"
325 test_expect_success
'use the same checkout for Git and CVS' '
329 sane_unset GIT_DIR &&
333 git commit -m "fake initial commit" &&
334 echo Hello >> " space" &&
335 git commit -m "Another change" " space" &&
336 git cvsexportcommit -W -p -u -c HEAD &&
337 grep Hello " space" &&