Code

Update jk/maint-strbuf-missing-init to builtin/ rename
[git.git] / t / t9200-git-cvsexportcommit.sh
1 #!/bin/sh
2 #
3 # Copyright (c) Robin Rosenberg
4 #
5 test_description='Test export of commits to CVS'
7 . ./test-lib.sh
9 if ! test_have_prereq PERL; then
10         say 'skipping git cvsexportcommit tests, perl not available'
11         test_done
12 fi
14 cvs >/dev/null 2>&1
15 if test $? -ne 1
16 then
17     say 'skipping git cvsexportcommit tests, cvs not found'
18     test_done
19 fi
21 CVSROOT=$(pwd)/cvsroot
22 CVSWORK=$(pwd)/cvswork
23 GIT_DIR=$(pwd)/.git
24 export CVSROOT CVSWORK GIT_DIR
26 rm -rf "$CVSROOT" "$CVSWORK"
27 mkdir "$CVSROOT" &&
28 cvs init &&
29 cvs -Q co -d "$CVSWORK" . &&
30 echo >empty &&
31 git add empty &&
32 git commit -q -a -m "Initial" 2>/dev/null ||
33 exit 1
35 check_entries () {
36         # $1 == directory, $2 == expected
37         grep '^/' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
38         if test -z "$2"
39         then
40                 >expected
41         else
42                 printf '%s\n' "$2" | tr '|' '\012' >expected
43         fi
44         test_cmp expected actual
45 }
47 test_expect_success \
48     'New file' \
49     'mkdir A B C D E F &&
50      echo hello1 >A/newfile1.txt &&
51      echo hello2 >B/newfile2.txt &&
52      cp "$TEST_DIRECTORY"/test9200a.png C/newfile3.png &&
53      cp "$TEST_DIRECTORY"/test9200a.png D/newfile4.png &&
54      git add A/newfile1.txt &&
55      git add B/newfile2.txt &&
56      git add C/newfile3.png &&
57      git add D/newfile4.png &&
58      git commit -a -m "Test: New file" &&
59      id=$(git rev-list --max-count=1 HEAD) &&
60      (cd "$CVSWORK" &&
61      git cvsexportcommit -c $id &&
62      check_entries A "newfile1.txt/1.1/" &&
63      check_entries B "newfile2.txt/1.1/" &&
64      check_entries C "newfile3.png/1.1/-kb" &&
65      check_entries D "newfile4.png/1.1/-kb" &&
66      diff A/newfile1.txt ../A/newfile1.txt &&
67      diff B/newfile2.txt ../B/newfile2.txt &&
68      diff C/newfile3.png ../C/newfile3.png &&
69      diff D/newfile4.png ../D/newfile4.png
70      )'
72 test_expect_success \
73     'Remove two files, add two and update two' \
74     'echo Hello1 >>A/newfile1.txt &&
75      rm -f B/newfile2.txt &&
76      rm -f C/newfile3.png &&
77      echo Hello5  >E/newfile5.txt &&
78      cp "$TEST_DIRECTORY"/test9200b.png D/newfile4.png &&
79      cp "$TEST_DIRECTORY"/test9200a.png F/newfile6.png &&
80      git add E/newfile5.txt &&
81      git add F/newfile6.png &&
82      git commit -a -m "Test: Remove, add and update" &&
83      id=$(git rev-list --max-count=1 HEAD) &&
84      (cd "$CVSWORK" &&
85      git cvsexportcommit -c $id &&
86      check_entries A "newfile1.txt/1.2/" &&
87      check_entries B "" &&
88      check_entries C "" &&
89      check_entries D "newfile4.png/1.2/-kb" &&
90      check_entries E "newfile5.txt/1.1/" &&
91      check_entries F "newfile6.png/1.1/-kb" &&
92      diff A/newfile1.txt ../A/newfile1.txt &&
93      diff D/newfile4.png ../D/newfile4.png &&
94      diff E/newfile5.txt ../E/newfile5.txt &&
95      diff F/newfile6.png ../F/newfile6.png
96      )'
98 # Should fail (but only on the git cvsexportcommit stage)
99 test_expect_success \
100     'Fail to change binary more than one generation old' \
101     'cat F/newfile6.png >>D/newfile4.png &&
102      git commit -a -m "generatiion 1" &&
103      cat F/newfile6.png >>D/newfile4.png &&
104      git commit -a -m "generation 2" &&
105      id=$(git rev-list --max-count=1 HEAD) &&
106      (cd "$CVSWORK" &&
107      test_must_fail git cvsexportcommit -c $id
108      )'
110 #test_expect_success \
111 #    'Fail to remove binary file more than one generation old' \
112 #    'git reset --hard HEAD^ &&
113 #     cat F/newfile6.png >>D/newfile4.png &&
114 #     git commit -a -m "generation 2 (again)" &&
115 #     rm -f D/newfile4.png &&
116 #     git commit -a -m "generation 3" &&
117 #     id=$(git rev-list --max-count=1 HEAD) &&
118 #     (cd "$CVSWORK" &&
119 #     test_must_fail git cvsexportcommit -c $id
120 #     )'
122 # We reuse the state from two tests back here
124 # This test is here because a patch for only binary files will
125 # fail with gnu patch, so cvsexportcommit must handle that.
126 test_expect_success \
127     'Remove only binary files' \
128     'git reset --hard HEAD^^ &&
129      rm -f D/newfile4.png &&
130      git commit -a -m "test: remove only a binary file" &&
131      id=$(git rev-list --max-count=1 HEAD) &&
132      (cd "$CVSWORK" &&
133      git cvsexportcommit -c $id &&
134      check_entries A "newfile1.txt/1.2/" &&
135      check_entries B "" &&
136      check_entries C "" &&
137      check_entries D "" &&
138      check_entries E "newfile5.txt/1.1/" &&
139      check_entries F "newfile6.png/1.1/-kb" &&
140      diff A/newfile1.txt ../A/newfile1.txt &&
141      diff E/newfile5.txt ../E/newfile5.txt &&
142      diff F/newfile6.png ../F/newfile6.png
143      )'
145 test_expect_success \
146     'Remove only a text file' \
147     'rm -f A/newfile1.txt &&
148      git commit -a -m "test: remove only a binary file" &&
149      id=$(git rev-list --max-count=1 HEAD) &&
150      (cd "$CVSWORK" &&
151      git cvsexportcommit -c $id &&
152      check_entries A "" &&
153      check_entries B "" &&
154      check_entries C "" &&
155      check_entries D "" &&
156      check_entries E "newfile5.txt/1.1/" &&
157      check_entries F "newfile6.png/1.1/-kb" &&
158      diff E/newfile5.txt ../E/newfile5.txt &&
159      diff F/newfile6.png ../F/newfile6.png
160      )'
162 test_expect_success \
163      'New file with spaces in file name' \
164      'mkdir "G g" &&
165       echo ok then >"G g/with spaces.txt" &&
166       git add "G g/with spaces.txt" && \
167       cp "$TEST_DIRECTORY"/test9200a.png "G g/with spaces.png" && \
168       git add "G g/with spaces.png" &&
169       git commit -a -m "With spaces" &&
170       id=$(git rev-list --max-count=1 HEAD) &&
171       (cd "$CVSWORK" &&
172       git cvsexportcommit -c $id &&
173       check_entries "G g" "with spaces.png/1.1/-kb|with spaces.txt/1.1/"
174       )'
176 test_expect_success \
177      'Update file with spaces in file name' \
178      'echo Ok then >>"G g/with spaces.txt" &&
179       cat "$TEST_DIRECTORY"/test9200a.png >>"G g/with spaces.png" && \
180       git add "G g/with spaces.png" &&
181       git commit -a -m "Update with spaces" &&
182       id=$(git rev-list --max-count=1 HEAD) &&
183       (cd "$CVSWORK" &&
184       git cvsexportcommit -c $id
185       check_entries "G g" "with spaces.png/1.2/-kb|with spaces.txt/1.2/"
186       )'
188 # Some filesystems mangle pathnames with UTF-8 characters --
189 # check and skip
190 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/å/ä/ö" &&
191         mkdir -p "tst/$p" &&
192         date >"tst/$p/day" &&
193         found=$(find tst -type f -print) &&
194         test "z$found" = "ztst/$p/day" &&
195         rm -fr tst
196 then
198 # This test contains UTF-8 characters
199 test_expect_success \
200      'File with non-ascii file name' \
201      '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/å/ä/ö &&
202       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 &&
203       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 &&
204       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 &&
205       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 &&
206       git commit -a -m "Går det så går det" && \
207       id=$(git rev-list --max-count=1 HEAD) &&
208       (cd "$CVSWORK" &&
209       git cvsexportcommit -v -c $id &&
210       check_entries \
211       "Å/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/å/ä/ö" \
212       "gårdetsågårdet.png/1.1/-kb|gårdetsågårdet.txt/1.1/"
213       )'
215 fi
217 rm -fr tst
219 test_expect_success \
220      'Mismatching patch should fail' \
221      'date >>"E/newfile5.txt" &&
222       git add "E/newfile5.txt" &&
223       git commit -a -m "Update one" &&
224       date >>"E/newfile5.txt" &&
225       git add "E/newfile5.txt" &&
226       git commit -a -m "Update two" &&
227       id=$(git rev-list --max-count=1 HEAD) &&
228       (cd "$CVSWORK" &&
229       test_must_fail git cvsexportcommit -c $id
230       )'
232 if ! test "$(git config --bool core.filemode)" = false
233 then
234         test_set_prereq FILEMODE
235 fi
237 test_expect_success FILEMODE \
238      'Retain execute bit' \
239      'mkdir G &&
240       echo executeon >G/on &&
241       chmod +x G/on &&
242       echo executeoff >G/off &&
243       git add G/on &&
244       git add G/off &&
245       git commit -a -m "Execute test" &&
246       (cd "$CVSWORK" &&
247       git cvsexportcommit -c HEAD
248       test -x G/on &&
249       ! test -x G/off
250       )'
252 test_expect_success '-w option should work with relative GIT_DIR' '
253       mkdir W &&
254       echo foobar >W/file1.txt &&
255       echo bazzle >W/file2.txt &&
256       git add W/file1.txt &&
257       git add W/file2.txt &&
258       git commit -m "More updates" &&
259       id=$(git rev-list --max-count=1 HEAD) &&
260       (cd "$GIT_DIR" &&
261       GIT_DIR=. git cvsexportcommit -w "$CVSWORK" -c $id &&
262       check_entries "$CVSWORK/W" "file1.txt/1.1/|file2.txt/1.1/" &&
263       test_cmp "$CVSWORK/W/file1.txt" ../W/file1.txt &&
264       test_cmp "$CVSWORK/W/file2.txt" ../W/file2.txt
265       )
268 test_expect_success 'check files before directories' '
270         echo Notes > release-notes &&
271         git add release-notes &&
272         git commit -m "Add release notes" release-notes &&
273         id=$(git rev-parse HEAD) &&
274         git cvsexportcommit -w "$CVSWORK" -c $id &&
276         echo new > DS &&
277         echo new > E/DS &&
278         echo modified > release-notes &&
279         git add DS E/DS release-notes &&
280         git commit -m "Add two files with the same basename" &&
281         id=$(git rev-parse HEAD) &&
282         git cvsexportcommit -w "$CVSWORK" -c $id &&
283         check_entries "$CVSWORK/E" "DS/1.1/|newfile5.txt/1.1/" &&
284         check_entries "$CVSWORK" "DS/1.1/|release-notes/1.2/" &&
285         test_cmp "$CVSWORK/DS" DS &&
286         test_cmp "$CVSWORK/E/DS" E/DS &&
287         test_cmp "$CVSWORK/release-notes" release-notes
291 test_expect_success 're-commit a removed filename which remains in CVS attic' '
293     (cd "$CVSWORK" &&
294      echo >attic_gremlin &&
295      cvs -Q add attic_gremlin &&
296      cvs -Q ci -m "added attic_gremlin" &&
297      rm attic_gremlin &&
298      cvs -Q rm attic_gremlin &&
299      cvs -Q ci -m "removed attic_gremlin") &&
301     echo > attic_gremlin &&
302     git add attic_gremlin &&
303     git commit -m "Added attic_gremlin" &&
304         git cvsexportcommit -w "$CVSWORK" -c HEAD &&
305     (cd "$CVSWORK"; cvs -Q update -d) &&
306     test -f "$CVSWORK/attic_gremlin"
309 # the state of the CVS sandbox may be indeterminate for ' space'
310 # after this test on some platforms / with some versions of CVS
311 # consider adding new tests above this point
312 test_expect_success 'commit a file with leading spaces in the name' '
314         echo space > " space" &&
315         git add " space" &&
316         git commit -m "Add a file with a leading space" &&
317         id=$(git rev-parse HEAD) &&
318         git cvsexportcommit -w "$CVSWORK" -c $id &&
319         check_entries "$CVSWORK" " space/1.1/|DS/1.1/|attic_gremlin/1.3/|release-notes/1.2/" &&
320         test_cmp "$CVSWORK/ space" " space"
324 test_expect_success 'use the same checkout for Git and CVS' '
326         (mkdir shared &&
327          cd shared &&
328          unset GIT_DIR &&
329          cvs co . &&
330          git init &&
331          git add " space" &&
332          git commit -m "fake initial commit" &&
333          echo Hello >> " space" &&
334          git commit -m "Another change" " space" &&
335          git cvsexportcommit -W -p -u -c HEAD &&
336          grep Hello " space" &&
337          git diff-files)
341 test_done