3 # Copyright (c) Robin Rosenberg
5 test_description
='Test export of commits to CVS'
12 say
'skipping git cvsexportcommit tests, cvs not found'
16 CVSROOT
=$
(pwd)/cvsroot
17 CVSWORK
=$
(pwd)/cvswork
19 export CVSROOT CVSWORK GIT_DIR
21 rm -rf "$CVSROOT" "$CVSWORK"
24 cvs
-Q co
-d "$CVSWORK" .
&&
27 git commit
-q -a -m "Initial" 2>/dev
/null ||
31 # $1 == directory, $2 == expected
32 grep '^/' "$1/CVS/Entries" |
sort | cut
-d/ -f2,3,5 >actual
37 printf '%s\n' "$2" |
tr '|' '\012' >expected
39 test_cmp expected actual
45 echo hello1 >A/newfile1.txt &&
46 echo hello2 >B/newfile2.txt &&
47 cp "$TEST_DIRECTORY"/test9200a.png C/newfile3.png &&
48 cp "$TEST_DIRECTORY"/test9200a.png D/newfile4.png &&
49 git add A/newfile1.txt &&
50 git add B/newfile2.txt &&
51 git add C/newfile3.png &&
52 git add D/newfile4.png &&
53 git commit -a -m "Test: New file" &&
54 id=$(git rev-list --max-count=1 HEAD) &&
56 git cvsexportcommit -c $id &&
57 check_entries A "newfile1.txt/1.1/" &&
58 check_entries B "newfile2.txt/1.1/" &&
59 check_entries C "newfile3.png/1.1/-kb" &&
60 check_entries D "newfile4.png/1.1/-kb" &&
61 diff A/newfile1.txt ../A/newfile1.txt &&
62 diff B/newfile2.txt ../B/newfile2.txt &&
63 diff C/newfile3.png ../C/newfile3.png &&
64 diff D/newfile4.png ../D/newfile4.png
68 'Remove two files, add two and update two' \
69 'echo Hello1 >>A/newfile1.txt &&
70 rm -f B/newfile2.txt &&
71 rm -f C/newfile3.png &&
72 echo Hello5 >E/newfile5.txt &&
73 cp "$TEST_DIRECTORY"/test9200b.png D/newfile4.png &&
74 cp "$TEST_DIRECTORY"/test9200a.png F/newfile6.png &&
75 git add E/newfile5.txt &&
76 git add F/newfile6.png &&
77 git commit -a -m "Test: Remove, add and update" &&
78 id=$(git rev-list --max-count=1 HEAD) &&
80 git cvsexportcommit -c $id &&
81 check_entries A "newfile1.txt/1.2/" &&
84 check_entries D "newfile4.png/1.2/-kb" &&
85 check_entries E "newfile5.txt/1.1/" &&
86 check_entries F "newfile6.png/1.1/-kb" &&
87 diff A/newfile1.txt ../A/newfile1.txt &&
88 diff D/newfile4.png ../D/newfile4.png &&
89 diff E/newfile5.txt ../E/newfile5.txt &&
90 diff F/newfile6.png ../F/newfile6.png
93 # Should fail (but only on the git cvsexportcommit stage)
95 'Fail to change binary more than one generation old' \
96 'cat F/newfile6.png >>D/newfile4.png &&
97 git commit -a -m "generatiion 1" &&
98 cat F/newfile6.png >>D/newfile4.png &&
99 git commit -a -m "generation 2" &&
100 id=$(git rev-list --max-count=1 HEAD) &&
102 test_must_fail git cvsexportcommit -c $id
105 #test_expect_success \
106 # 'Fail to remove binary file more than one generation old' \
107 # 'git reset --hard HEAD^ &&
108 # cat F/newfile6.png >>D/newfile4.png &&
109 # git commit -a -m "generation 2 (again)" &&
110 # rm -f D/newfile4.png &&
111 # git commit -a -m "generation 3" &&
112 # id=$(git rev-list --max-count=1 HEAD) &&
114 # test_must_fail git cvsexportcommit -c $id
117 # We reuse the state from two tests back here
119 # This test is here because a patch for only binary files will
120 # fail with gnu patch, so cvsexportcommit must handle that.
121 test_expect_success \
122 'Remove only binary files' \
123 'git reset --hard HEAD^^ &&
124 rm -f D/newfile4.png &&
125 git commit -a -m "test: remove only a binary file" &&
126 id=$(git rev-list --max-count=1 HEAD) &&
128 git cvsexportcommit -c $id &&
129 check_entries A "newfile1.txt/1.2/" &&
130 check_entries B "" &&
131 check_entries C "" &&
132 check_entries D "" &&
133 check_entries E "newfile5.txt/1.1/" &&
134 check_entries F "newfile6.png/1.1/-kb" &&
135 diff A/newfile1.txt ../A/newfile1.txt &&
136 diff E/newfile5.txt ../E/newfile5.txt &&
137 diff F/newfile6.png ../F/newfile6.png
140 test_expect_success \
141 'Remove only a text file' \
142 'rm -f A/newfile1.txt &&
143 git commit -a -m "test: remove only a binary file" &&
144 id=$(git rev-list --max-count=1 HEAD) &&
146 git cvsexportcommit -c $id &&
147 check_entries A "" &&
148 check_entries B "" &&
149 check_entries C "" &&
150 check_entries D "" &&
151 check_entries E "newfile5.txt/1.1/" &&
152 check_entries F "newfile6.png/1.1/-kb" &&
153 diff E/newfile5.txt ../E/newfile5.txt &&
154 diff F/newfile6.png ../F/newfile6.png
157 test_expect_success \
158 'New file with spaces in file name' \
160 echo ok then >"G g/with spaces.txt" &&
161 git add "G g/with spaces.txt" && \
162 cp "$TEST_DIRECTORY"/test9200a.png "G g/with spaces.png" && \
163 git add "G g/with spaces.png" &&
164 git commit -a -m "With spaces" &&
165 id=$(git rev-list --max-count=1 HEAD) &&
167 git cvsexportcommit -c $id &&
168 check_entries "G g" "with spaces.png/1.1/-kb|with spaces.txt/1.1/"
171 test_expect_success \
172 'Update file with spaces in file name' \
173 'echo Ok then >>"G g/with spaces.txt" &&
174 cat "$TEST_DIRECTORY"/test9200a.png >>"G g/with spaces.png" && \
175 git add "G g/with spaces.png" &&
176 git commit -a -m "Update with spaces" &&
177 id=$(git rev-list --max-count=1 HEAD) &&
179 git cvsexportcommit -c $id
180 check_entries "G g" "with spaces.png/1.2/-kb|with spaces.txt/1.2/"
183 # Some filesystems mangle pathnames with UTF-8 characters --
185 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/å/ä/ö" &&
187 date >"tst/$p/day" &&
188 found
=$
(find tst
-type f
-print) &&
189 test "z$found" = "ztst/$p/day" &&
193 # This test contains UTF-8 characters
194 test_expect_success \
195 'File with non-ascii file name' \
196 '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/å/ä/ö &&
197 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 &&
198 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 &&
199 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 &&
200 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 &&
201 git commit -a -m "Går det så går det" && \
202 id=$(git rev-list --max-count=1 HEAD) &&
204 git cvsexportcommit -v -c $id &&
206 "Å/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/å/ä/ö" \
207 "gårdetsågårdet.png/1.1/-kb|gårdetsågårdet.txt/1.1/"
214 test_expect_success \
215 'Mismatching patch should fail' \
216 'date >>"E/newfile5.txt" &&
217 git add "E/newfile5.txt" &&
218 git commit -a -m "Update one" &&
219 date >>"E/newfile5.txt" &&
220 git add "E/newfile5.txt" &&
221 git commit -a -m "Update two" &&
222 id=$(git rev-list --max-count=1 HEAD) &&
224 test_must_fail git cvsexportcommit -c $id
227 if ! test "$(git config --bool core.filemode)" = false
229 test_set_prereq FILEMODE
232 test_expect_success FILEMODE \
233 'Retain execute bit' \
235 echo executeon >G/on &&
237 echo executeoff >G/off &&
240 git commit -a -m "Execute test" &&
242 git cvsexportcommit -c HEAD
247 test_expect_success
'-w option should work with relative GIT_DIR' '
249 echo foobar >W/file1.txt &&
250 echo bazzle >W/file2.txt &&
251 git add W/file1.txt &&
252 git add W/file2.txt &&
253 git commit -m "More updates" &&
254 id=$(git rev-list --max-count=1 HEAD) &&
256 GIT_DIR=. git cvsexportcommit -w "$CVSWORK" -c $id &&
257 check_entries "$CVSWORK/W" "file1.txt/1.1/|file2.txt/1.1/" &&
258 test_cmp "$CVSWORK/W/file1.txt" ../W/file1.txt &&
259 test_cmp "$CVSWORK/W/file2.txt" ../W/file2.txt
263 test_expect_success
'check files before directories' '
265 echo Notes > release-notes &&
266 git add release-notes &&
267 git commit -m "Add release notes" release-notes &&
268 id=$(git rev-parse HEAD) &&
269 git cvsexportcommit -w "$CVSWORK" -c $id &&
273 echo modified > release-notes &&
274 git add DS E/DS release-notes &&
275 git commit -m "Add two files with the same basename" &&
276 id=$(git rev-parse HEAD) &&
277 git cvsexportcommit -w "$CVSWORK" -c $id &&
278 check_entries "$CVSWORK/E" "DS/1.1/|newfile5.txt/1.1/" &&
279 check_entries "$CVSWORK" "DS/1.1/|release-notes/1.2/" &&
280 test_cmp "$CVSWORK/DS" DS &&
281 test_cmp "$CVSWORK/E/DS" E/DS &&
282 test_cmp "$CVSWORK/release-notes" release-notes
286 test_expect_success
'commit a file with leading spaces in the name' '
288 echo space > " space" &&
290 git commit -m "Add a file with a leading space" &&
291 id=$(git rev-parse HEAD) &&
292 git cvsexportcommit -w "$CVSWORK" -c $id &&
293 check_entries "$CVSWORK" " space/1.1/|DS/1.1/|release-notes/1.2/" &&
294 test_cmp "$CVSWORK/ space" " space"
298 test_expect_success
'use the same checkout for Git and CVS' '
306 git commit -m "fake initial commit" &&
307 echo Hello >> " space" &&
308 git commit -m "Another change" " space" &&
309 git cvsexportcommit -W -p -u -c HEAD &&
310 grep Hello " space" &&