t / t9200-git-cvsexportcommit.shon commit Merge branch 'dm/add-i-edit-abort' (2e2e91d)
   1#!/bin/sh
   2#
   3# Copyright (c) Robin Rosenberg
   4#
   5test_description='Test export of commits to CVS'
   6
   7. ./test-lib.sh
   8
   9cvs >/dev/null 2>&1
  10if test $? -ne 1
  11then
  12    test_expect_success 'skipping git cvsexportcommit tests, cvs not found' :
  13    test_done
  14    exit
  15fi
  16
  17CVSROOT=$(pwd)/cvsroot
  18CVSWORK=$(pwd)/cvswork
  19GIT_DIR=$(pwd)/.git
  20export CVSROOT CVSWORK GIT_DIR
  21
  22rm -rf "$CVSROOT" "$CVSWORK"
  23mkdir "$CVSROOT" &&
  24cvs init &&
  25cvs -Q co -d "$CVSWORK" . &&
  26echo >empty &&
  27git add empty &&
  28git commit -q -a -m "Initial" 2>/dev/null ||
  29exit 1
  30
  31check_entries () {
  32        # $1 == directory, $2 == expected
  33        grep '^/' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
  34        if test -z "$2"
  35        then
  36                >expected
  37        else
  38                printf '%s\n' "$2" | tr '|' '\012' >expected
  39        fi
  40        test_cmp expected actual
  41}
  42
  43test_expect_success \
  44    'New file' \
  45    'mkdir A B C D E F &&
  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) &&
  56     (cd "$CVSWORK" &&
  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
  66     )'
  67
  68test_expect_success \
  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) &&
  80     (cd "$CVSWORK" &&
  81     git cvsexportcommit -c $id &&
  82     check_entries A "newfile1.txt/1.2/" &&
  83     check_entries B "" &&
  84     check_entries C "" &&
  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
  92     )'
  93
  94# Should fail (but only on the git cvsexportcommit stage)
  95test_expect_success \
  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) &&
 102     (cd "$CVSWORK" &&
 103     test_must_fail git cvsexportcommit -c $id
 104     )'
 105
 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) &&
 114#     (cd "$CVSWORK" &&
 115#     test_must_fail git cvsexportcommit -c $id
 116#     )'
 117
 118# We reuse the state from two tests back here
 119
 120# This test is here because a patch for only binary files will
 121# fail with gnu patch, so cvsexportcommit must handle that.
 122test_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) &&
 128     (cd "$CVSWORK" &&
 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
 139     )'
 140
 141test_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) &&
 146     (cd "$CVSWORK" &&
 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
 156     )'
 157
 158test_expect_success \
 159     'New file with spaces in file name' \
 160     'mkdir "G g" &&
 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) &&
 167      (cd "$CVSWORK" &&
 168      git cvsexportcommit -c $id &&
 169      check_entries "G g" "with spaces.png/1.1/-kb|with spaces.txt/1.1/"
 170      )'
 171
 172test_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) &&
 179      (cd "$CVSWORK" &&
 180      git cvsexportcommit -c $id
 181      check_entries "G g" "with spaces.png/1.2/-kb|with spaces.txt/1.2/"
 182      )'
 183
 184# Some filesystems mangle pathnames with UTF-8 characters --
 185# check and skip
 186if 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        mkdir -p "tst/$p" &&
 188        date >"tst/$p/day" &&
 189        found=$(find tst -type f -print) &&
 190        test "z$found" = "ztst/$p/day" &&
 191        rm -fr tst
 192then
 193
 194# This test contains UTF-8 characters
 195test_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) &&
 204      (cd "$CVSWORK" &&
 205      git cvsexportcommit -v -c $id &&
 206      check_entries \
 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/"
 209      )'
 210
 211fi
 212
 213rm -fr tst
 214
 215test_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) &&
 224      (cd "$CVSWORK" &&
 225      test_must_fail git cvsexportcommit -c $id
 226      )'
 227
 228case "$(git config --bool core.filemode)" in
 229false)
 230        ;;
 231*)
 232test_expect_success \
 233     'Retain execute bit' \
 234     'mkdir G &&
 235      echo executeon >G/on &&
 236      chmod +x G/on &&
 237      echo executeoff >G/off &&
 238      git add G/on &&
 239      git add G/off &&
 240      git commit -a -m "Execute test" &&
 241      (cd "$CVSWORK" &&
 242      git cvsexportcommit -c HEAD
 243      test -x G/on &&
 244      ! test -x G/off
 245      )'
 246        ;;
 247esac
 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 'commit a file with leading spaces in the name' '
 289
 290        echo space > " space" &&
 291        git add " space" &&
 292        git commit -m "Add a file with a leading space" &&
 293        id=$(git rev-parse HEAD) &&
 294        git cvsexportcommit -w "$CVSWORK" -c $id &&
 295        check_entries "$CVSWORK" " space/1.1/|DS/1.1/|release-notes/1.2/" &&
 296        test_cmp "$CVSWORK/ space" " space"
 297
 298'
 299
 300test_expect_success 'use the same checkout for Git and CVS' '
 301
 302        (mkdir shared &&
 303         cd shared &&
 304         unset GIT_DIR &&
 305         cvs co . &&
 306         git init &&
 307         git add " space" &&
 308         git commit -m "fake initial commit" &&
 309         echo Hello >> " space" &&
 310         git commit -m "Another change" " space" &&
 311         git cvsexportcommit -W -p -u -c HEAD &&
 312         grep Hello " space" &&
 313         git diff-files)
 314
 315'
 316
 317test_done