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