t9200-git-cvsexportcommit.sh 10.5 KB
Newer Older
1
#!/bin/sh
2 3 4
#
# Copyright (c) Robin Rosenberg
#
5
test_description='Test export of commits to CVS'
6 7 8

. ./test-lib.sh

9
if ! test_have_prereq PERL; then
10
	skip_all='skipping git cvsexportcommit tests, perl not available'
11 12 13
	test_done
fi

14 15 16
cvs >/dev/null 2>&1
if test $? -ne 1
then
17
    skip_all='skipping git cvsexportcommit tests, cvs not found'
18 19 20
    test_done
fi

21
CVSROOT=$PWD/tmpcvsroot
22 23
CVSWORK=$PWD/cvswork
GIT_DIR=$PWD/.git
24 25
export CVSROOT CVSWORK GIT_DIR

26
rm -rf "$CVSROOT" "$CVSWORK"
27

28
cvs init &&
29
test -d "$CVSROOT" &&
30 31 32
cvs -Q co -d "$CVSWORK" . &&
echo >empty &&
git add empty &&
33
git commit -q -a -m "Initial" 2>/dev/null ||
34 35
exit 1

36 37 38 39 40 41 42 43 44
check_entries () {
	# $1 == directory, $2 == expected
	grep '^/' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
	if test -z "$2"
	then
		>expected
	else
		printf '%s\n' "$2" | tr '|' '\012' >expected
	fi
45
	test_cmp expected actual
46 47
}

48 49 50 51 52
test_expect_success \
    'New file' \
    'mkdir A B C D E F &&
     echo hello1 >A/newfile1.txt &&
     echo hello2 >B/newfile2.txt &&
53 54
     cp "$TEST_DIRECTORY"/test-binary-1.png C/newfile3.png &&
     cp "$TEST_DIRECTORY"/test-binary-1.png D/newfile4.png &&
55 56 57 58 59 60 61 62
     git add A/newfile1.txt &&
     git add B/newfile2.txt &&
     git add C/newfile3.png &&
     git add D/newfile4.png &&
     git commit -a -m "Test: New file" &&
     id=$(git rev-list --max-count=1 HEAD) &&
     (cd "$CVSWORK" &&
     git cvsexportcommit -c $id &&
63 64 65 66
     check_entries A "newfile1.txt/1.1/" &&
     check_entries B "newfile2.txt/1.1/" &&
     check_entries C "newfile3.png/1.1/-kb" &&
     check_entries D "newfile4.png/1.1/-kb" &&
67 68 69 70
     test_cmp A/newfile1.txt ../A/newfile1.txt &&
     test_cmp B/newfile2.txt ../B/newfile2.txt &&
     test_cmp C/newfile3.png ../C/newfile3.png &&
     test_cmp D/newfile4.png ../D/newfile4.png
71 72 73 74 75 76 77 78
     )'

test_expect_success \
    'Remove two files, add two and update two' \
    'echo Hello1 >>A/newfile1.txt &&
     rm -f B/newfile2.txt &&
     rm -f C/newfile3.png &&
     echo Hello5  >E/newfile5.txt &&
79 80
     cp "$TEST_DIRECTORY"/test-binary-2.png D/newfile4.png &&
     cp "$TEST_DIRECTORY"/test-binary-1.png F/newfile6.png &&
81 82 83 84 85 86
     git add E/newfile5.txt &&
     git add F/newfile6.png &&
     git commit -a -m "Test: Remove, add and update" &&
     id=$(git rev-list --max-count=1 HEAD) &&
     (cd "$CVSWORK" &&
     git cvsexportcommit -c $id &&
87 88 89 90 91 92
     check_entries A "newfile1.txt/1.2/" &&
     check_entries B "" &&
     check_entries C "" &&
     check_entries D "newfile4.png/1.2/-kb" &&
     check_entries E "newfile5.txt/1.1/" &&
     check_entries F "newfile6.png/1.1/-kb" &&
93 94 95 96
     test_cmp A/newfile1.txt ../A/newfile1.txt &&
     test_cmp D/newfile4.png ../D/newfile4.png &&
     test_cmp E/newfile5.txt ../E/newfile5.txt &&
     test_cmp F/newfile6.png ../F/newfile6.png
97 98
     )'

99
# Should fail (but only on the git cvsexportcommit stage)
100 101 102 103 104 105 106 107
test_expect_success \
    'Fail to change binary more than one generation old' \
    'cat F/newfile6.png >>D/newfile4.png &&
     git commit -a -m "generatiion 1" &&
     cat F/newfile6.png >>D/newfile4.png &&
     git commit -a -m "generation 2" &&
     id=$(git rev-list --max-count=1 HEAD) &&
     (cd "$CVSWORK" &&
108
     test_must_fail git cvsexportcommit -c $id
109 110
     )'

111 112 113 114 115 116 117 118 119
#test_expect_success \
#    'Fail to remove binary file more than one generation old' \
#    'git reset --hard HEAD^ &&
#     cat F/newfile6.png >>D/newfile4.png &&
#     git commit -a -m "generation 2 (again)" &&
#     rm -f D/newfile4.png &&
#     git commit -a -m "generation 3" &&
#     id=$(git rev-list --max-count=1 HEAD) &&
#     (cd "$CVSWORK" &&
120
#     test_must_fail git cvsexportcommit -c $id
121
#     )'
122 123 124 125 126 127 128

# We reuse the state from two tests back here

# This test is here because a patch for only binary files will
# fail with gnu patch, so cvsexportcommit must handle that.
test_expect_success \
    'Remove only binary files' \
129
    'git reset --hard HEAD^^ &&
130 131 132 133 134
     rm -f D/newfile4.png &&
     git commit -a -m "test: remove only a binary file" &&
     id=$(git rev-list --max-count=1 HEAD) &&
     (cd "$CVSWORK" &&
     git cvsexportcommit -c $id &&
135 136 137 138 139 140
     check_entries A "newfile1.txt/1.2/" &&
     check_entries B "" &&
     check_entries C "" &&
     check_entries D "" &&
     check_entries E "newfile5.txt/1.1/" &&
     check_entries F "newfile6.png/1.1/-kb" &&
141 142 143
     test_cmp A/newfile1.txt ../A/newfile1.txt &&
     test_cmp E/newfile5.txt ../E/newfile5.txt &&
     test_cmp F/newfile6.png ../F/newfile6.png
144 145 146 147 148 149 150 151 152
     )'

test_expect_success \
    'Remove only a text file' \
    'rm -f A/newfile1.txt &&
     git commit -a -m "test: remove only a binary file" &&
     id=$(git rev-list --max-count=1 HEAD) &&
     (cd "$CVSWORK" &&
     git cvsexportcommit -c $id &&
153 154 155 156 157 158
     check_entries A "" &&
     check_entries B "" &&
     check_entries C "" &&
     check_entries D "" &&
     check_entries E "newfile5.txt/1.1/" &&
     check_entries F "newfile6.png/1.1/-kb" &&
159 160
     test_cmp E/newfile5.txt ../E/newfile5.txt &&
     test_cmp F/newfile6.png ../F/newfile6.png
161 162
     )'

163 164 165 166 167
test_expect_success \
     'New file with spaces in file name' \
     'mkdir "G g" &&
      echo ok then >"G g/with spaces.txt" &&
      git add "G g/with spaces.txt" && \
168
      cp "$TEST_DIRECTORY"/test-binary-1.png "G g/with spaces.png" && \
169 170 171 172
      git add "G g/with spaces.png" &&
      git commit -a -m "With spaces" &&
      id=$(git rev-list --max-count=1 HEAD) &&
      (cd "$CVSWORK" &&
173
      git cvsexportcommit -c $id &&
174
      check_entries "G g" "with spaces.png/1.1/-kb|with spaces.txt/1.1/"
175 176 177 178 179
      )'

test_expect_success \
     'Update file with spaces in file name' \
     'echo Ok then >>"G g/with spaces.txt" &&
180
      cat "$TEST_DIRECTORY"/test-binary-1.png >>"G g/with spaces.png" && \
181 182 183 184
      git add "G g/with spaces.png" &&
      git commit -a -m "Update with spaces" &&
      id=$(git rev-list --max-count=1 HEAD) &&
      (cd "$CVSWORK" &&
185
      git cvsexportcommit -c $id
186
      check_entries "G g" "with spaces.png/1.2/-kb|with spaces.txt/1.2/"
187 188
      )'

189 190 191 192 193 194 195 196 197 198
# Some filesystems mangle pathnames with UTF-8 characters --
# check and skip
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/å/ä/ö" &&
	mkdir -p "tst/$p" &&
	date >"tst/$p/day" &&
	found=$(find tst -type f -print) &&
	test "z$found" = "ztst/$p/day" &&
	rm -fr tst
then

199
# This test contains UTF-8 characters
200 201
test_expect_success \
     'File with non-ascii file name' \
202 203 204
     '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/å/ä/ö &&
      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 &&
      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 207
      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 &&
      git commit -a -m "Går det så går det" && \
208 209
      id=$(git rev-list --max-count=1 HEAD) &&
      (cd "$CVSWORK" &&
210
      git cvsexportcommit -v -c $id &&
211 212 213
      check_entries \
      "Å/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/1.1/-kb|gårdetsågårdet.txt/1.1/"
214 215
      )'

216 217 218 219
fi

rm -fr tst

220 221 222 223 224 225 226 227 228 229
test_expect_success \
     'Mismatching patch should fail' \
     'date >>"E/newfile5.txt" &&
      git add "E/newfile5.txt" &&
      git commit -a -m "Update one" &&
      date >>"E/newfile5.txt" &&
      git add "E/newfile5.txt" &&
      git commit -a -m "Update two" &&
      id=$(git rev-list --max-count=1 HEAD) &&
      (cd "$CVSWORK" &&
230
      test_must_fail git cvsexportcommit -c $id
231 232
      )'

233
test_expect_success FILEMODE \
234 235 236 237 238 239 240 241 242
     'Retain execute bit' \
     'mkdir G &&
      echo executeon >G/on &&
      chmod +x G/on &&
      echo executeoff >G/off &&
      git add G/on &&
      git add G/off &&
      git commit -a -m "Execute test" &&
      (cd "$CVSWORK" &&
243
      git cvsexportcommit -c HEAD
244 245 246
      test -x G/on &&
      ! test -x G/off
      )'
247

248
test_expect_success '-w option should work with relative GIT_DIR' '
249 250 251 252 253 254 255 256 257 258
      mkdir W &&
      echo foobar >W/file1.txt &&
      echo bazzle >W/file2.txt &&
      git add W/file1.txt &&
      git add W/file2.txt &&
      git commit -m "More updates" &&
      id=$(git rev-list --max-count=1 HEAD) &&
      (cd "$GIT_DIR" &&
      GIT_DIR=. git cvsexportcommit -w "$CVSWORK" -c $id &&
      check_entries "$CVSWORK/W" "file1.txt/1.1/|file2.txt/1.1/" &&
259 260
      test_cmp "$CVSWORK/W/file1.txt" ../W/file1.txt &&
      test_cmp "$CVSWORK/W/file2.txt" ../W/file2.txt
261 262 263
      )
'

264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
test_expect_success 'check files before directories' '

	echo Notes > release-notes &&
	git add release-notes &&
	git commit -m "Add release notes" release-notes &&
	id=$(git rev-parse HEAD) &&
	git cvsexportcommit -w "$CVSWORK" -c $id &&

	echo new > DS &&
	echo new > E/DS &&
	echo modified > release-notes &&
	git add DS E/DS release-notes &&
	git commit -m "Add two files with the same basename" &&
	id=$(git rev-parse HEAD) &&
	git cvsexportcommit -w "$CVSWORK" -c $id &&
	check_entries "$CVSWORK/E" "DS/1.1/|newfile5.txt/1.1/" &&
	check_entries "$CVSWORK" "DS/1.1/|release-notes/1.2/" &&
281 282 283
	test_cmp "$CVSWORK/DS" DS &&
	test_cmp "$CVSWORK/E/DS" E/DS &&
	test_cmp "$CVSWORK/release-notes" release-notes
284 285 286

'

287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
test_expect_success 're-commit a removed filename which remains in CVS attic' '

    (cd "$CVSWORK" &&
     echo >attic_gremlin &&
     cvs -Q add attic_gremlin &&
     cvs -Q ci -m "added attic_gremlin" &&
     rm attic_gremlin &&
     cvs -Q rm attic_gremlin &&
     cvs -Q ci -m "removed attic_gremlin") &&

    echo > attic_gremlin &&
    git add attic_gremlin &&
    git commit -m "Added attic_gremlin" &&
	git cvsexportcommit -w "$CVSWORK" -c HEAD &&
    (cd "$CVSWORK"; cvs -Q update -d) &&
    test -f "$CVSWORK/attic_gremlin"
'

# the state of the CVS sandbox may be indeterminate for ' space'
# after this test on some platforms / with some versions of CVS
# consider adding new tests above this point
308 309 310 311 312 313 314
test_expect_success 'commit a file with leading spaces in the name' '

	echo space > " space" &&
	git add " space" &&
	git commit -m "Add a file with a leading space" &&
	id=$(git rev-parse HEAD) &&
	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"
317 318 319

'

320 321 322 323
test_expect_success 'use the same checkout for Git and CVS' '

	(mkdir shared &&
	 cd shared &&
324
	 sane_unset GIT_DIR &&
325 326 327 328 329 330 331 332 333 334 335 336
	 cvs co . &&
	 git init &&
	 git add " space" &&
	 git commit -m "fake initial commit" &&
	 echo Hello >> " space" &&
	 git commit -m "Another change" " space" &&
	 git cvsexportcommit -W -p -u -c HEAD &&
	 grep Hello " space" &&
	 git diff-files)

'

337
test_done