3 # Copyright (c) Robin Rosenberg
5 test_description
='Test export of commits to CVS'
12 say
'skipping git cvsexportcommit tests, cvs not found'
17 CVSROOT
=$
(pwd)/cvsroot
18 CVSWORK
=$
(pwd)/cvswork
20 export CVSROOT CVSWORK GIT_DIR
22 rm -rf "$CVSROOT" "$CVSWORK"
25 cvs
-Q co
-d "$CVSWORK" .
&&
28 git commit
-q -a -m "Initial" 2>/dev
/null ||
32 # $1 == directory, $2 == expected
33 grep '^/' "$1/CVS/Entries" |
sort | cut
-d/ -f2,3,5 >actual
38 printf '%s\n' "$2" |
tr '|' '\012' >expected
40 test_cmp expected actual
46 echo hello1 >A/newfile1.txt &&
47 echo hello2 >B/newfile2.txt &&
48 cp "$TEST_DIRECTORY"/test9200a.png C/newfile3.png &&
49 cp "$TEST_DIRECTORY"/test9200a.png D/newfile4.png &&
50 git add A/newfile1.txt &&
51 git add B/newfile2.txt &&
52 git add C/newfile3.png &&
53 git add D/newfile4.png &&
54 git commit -a -m "Test: New file" &&
55 id=$(git rev-list --max-count=1 HEAD) &&
57 git cvsexportcommit -c $id &&
58 check_entries A "newfile1.txt/1.1/" &&
59 check_entries B "newfile2.txt/1.1/" &&
60 check_entries C "newfile3.png/1.1/-kb" &&
61 check_entries D "newfile4.png/1.1/-kb" &&
62 diff A/newfile1.txt ../A/newfile1.txt &&
63 diff B/newfile2.txt ../B/newfile2.txt &&
64 diff C/newfile3.png ../C/newfile3.png &&
65 diff D/newfile4.png ../D/newfile4.png
69 'Remove two files, add two and update two' \
70 'echo Hello1 >>A/newfile1.txt &&
71 rm -f B/newfile2.txt &&
72 rm -f C/newfile3.png &&
73 echo Hello5 >E/newfile5.txt &&
74 cp "$TEST_DIRECTORY"/test9200b.png D/newfile4.png &&
75 cp "$TEST_DIRECTORY"/test9200a.png F/newfile6.png &&
76 git add E/newfile5.txt &&
77 git add F/newfile6.png &&
78 git commit -a -m "Test: Remove, add and update" &&
79 id=$(git rev-list --max-count=1 HEAD) &&
81 git cvsexportcommit -c $id &&
82 check_entries A "newfile1.txt/1.2/" &&
85 check_entries D "newfile4.png/1.2/-kb" &&
86 check_entries E "newfile5.txt/1.1/" &&
87 check_entries F "newfile6.png/1.1/-kb" &&
88 diff A/newfile1.txt ../A/newfile1.txt &&
89 diff D/newfile4.png ../D/newfile4.png &&
90 diff E/newfile5.txt ../E/newfile5.txt &&
91 diff F/newfile6.png ../F/newfile6.png
94 # Should fail (but only on the git cvsexportcommit stage)
96 'Fail to change binary more than one generation old' \
97 'cat F/newfile6.png >>D/newfile4.png &&
98 git commit -a -m "generatiion 1" &&
99 cat F/newfile6.png >>D/newfile4.png &&
100 git commit -a -m "generation 2" &&
101 id=$(git rev-list --max-count=1 HEAD) &&
103 test_must_fail git cvsexportcommit -c $id
106 #test_expect_success \
107 # 'Fail to remove binary file more than one generation old' \
108 # 'git reset --hard HEAD^ &&
109 # cat F/newfile6.png >>D/newfile4.png &&
110 # git commit -a -m "generation 2 (again)" &&
111 # rm -f D/newfile4.png &&
112 # git commit -a -m "generation 3" &&
113 # id=$(git rev-list --max-count=1 HEAD) &&
115 # test_must_fail git cvsexportcommit -c $id
118 # We reuse the state from two tests back here
120 # This test is here because a patch for only binary files will
121 # fail with gnu patch, so cvsexportcommit must handle that.
122 test_expect_success \
123 'Remove only binary files' \
124 'git reset --hard HEAD^^ &&
125 rm -f D/newfile4.png &&
126 git commit -a -m "test: remove only a binary file" &&
127 id=$(git rev-list --max-count=1 HEAD) &&
129 git cvsexportcommit -c $id &&
130 check_entries A "newfile1.txt/1.2/" &&
131 check_entries B "" &&
132 check_entries C "" &&
133 check_entries D "" &&
134 check_entries E "newfile5.txt/1.1/" &&
135 check_entries F "newfile6.png/1.1/-kb" &&
136 diff A/newfile1.txt ../A/newfile1.txt &&
137 diff E/newfile5.txt ../E/newfile5.txt &&
138 diff F/newfile6.png ../F/newfile6.png
141 test_expect_success \
142 'Remove only a text file' \
143 'rm -f A/newfile1.txt &&
144 git commit -a -m "test: remove only a binary file" &&
145 id=$(git rev-list --max-count=1 HEAD) &&
147 git cvsexportcommit -c $id &&
148 check_entries A "" &&
149 check_entries B "" &&
150 check_entries C "" &&
151 check_entries D "" &&
152 check_entries E "newfile5.txt/1.1/" &&
153 check_entries F "newfile6.png/1.1/-kb" &&
154 diff E/newfile5.txt ../E/newfile5.txt &&
155 diff F/newfile6.png ../F/newfile6.png
158 test_expect_success \
159 'New file with spaces in file name' \
161 echo ok then >"G g/with spaces.txt" &&
162 git add "G g/with spaces.txt" && \
163 cp "$TEST_DIRECTORY"/test9200a.png "G g/with spaces.png" && \
164 git add "G g/with spaces.png" &&
165 git commit -a -m "With spaces" &&
166 id=$(git rev-list --max-count=1 HEAD) &&
168 git cvsexportcommit -c $id &&
169 check_entries "G g" "with spaces.png/1.1/-kb|with spaces.txt/1.1/"
172 test_expect_success \
173 'Update file with spaces in file name' \
174 'echo Ok then >>"G g/with spaces.txt" &&
175 cat "$TEST_DIRECTORY"/test9200a.png >>"G g/with spaces.png" && \
176 git add "G g/with spaces.png" &&
177 git commit -a -m "Update with spaces" &&
178 id=$(git rev-list --max-count=1 HEAD) &&
180 git cvsexportcommit -c $id
181 check_entries "G g" "with spaces.png/1.2/-kb|with spaces.txt/1.2/"
184 # Some filesystems mangle pathnames with UTF-8 characters --
186 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/å/ä/ö" &&
188 date >"tst/$p/day" &&
189 found
=$
(find tst
-type f
-print) &&
190 test "z$found" = "ztst/$p/day" &&
194 # This test contains UTF-8 characters
195 test_expect_success \
196 'File with non-ascii file name' \
197 '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/å/ä/ö &&
198 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 &&
199 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 &&
200 cp "$TEST_DIRECTORY"/test9200a.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 &&
201 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 &&
202 git commit -a -m "Går det så går det" && \
203 id=$(git rev-list --max-count=1 HEAD) &&
205 git cvsexportcommit -v -c $id &&
207 "Å/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 "gårdetsågårdet.png/1.1/-kb|gårdetsågårdet.txt/1.1/"
215 test_expect_success \
216 'Mismatching patch should fail' \
217 'date >>"E/newfile5.txt" &&
218 git add "E/newfile5.txt" &&
219 git commit -a -m "Update one" &&
220 date >>"E/newfile5.txt" &&
221 git add "E/newfile5.txt" &&
222 git commit -a -m "Update two" &&
223 id=$(git rev-list --max-count=1 HEAD) &&
225 test_must_fail git cvsexportcommit -c $id
228 if ! test "$(git config --bool core.filemode)" = false
230 test_set_prereq FILEMODE
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
'commit a file with leading spaces in the name' '
289 echo space > " space" &&
291 git commit -m "Add a file with a leading space" &&
292 id=$(git rev-parse HEAD) &&
293 git cvsexportcommit -w "$CVSWORK" -c $id &&
294 check_entries "$CVSWORK" " space/1.1/|DS/1.1/|release-notes/1.2/" &&
295 test_cmp "$CVSWORK/ space" " space"
299 test_expect_success
'use the same checkout for Git and CVS' '
307 git commit -m "fake initial commit" &&
308 echo Hello >> " space" &&
309 git commit -m "Another change" " space" &&
310 git cvsexportcommit -W -p -u -c HEAD &&
311 grep Hello " space" &&