t / t9200-git-cvsexportcommit.shon commit Merge branch 'ar/wildcardpush' (684a93d)
   1#!/bin/sh
   2#
   3# Copyright (c) Robin Rosenberg
   4#
   5test_description='CVS export comit. '
   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
  31test_expect_success \
  32    'New file' \
  33    'mkdir A B C D E F &&
  34     echo hello1 >A/newfile1.txt &&
  35     echo hello2 >B/newfile2.txt &&
  36     cp ../test9200a.png C/newfile3.png &&
  37     cp ../test9200a.png D/newfile4.png &&
  38     git add A/newfile1.txt &&
  39     git add B/newfile2.txt &&
  40     git add C/newfile3.png &&
  41     git add D/newfile4.png &&
  42     git commit -a -m "Test: New file" &&
  43     id=$(git rev-list --max-count=1 HEAD) &&
  44     (cd "$CVSWORK" &&
  45     git cvsexportcommit -c $id &&
  46     test "$(echo $(sort A/CVS/Entries|cut -d/ -f2,3,5))" = "newfile1.txt/1.1/" &&
  47     test "$(echo $(sort B/CVS/Entries|cut -d/ -f2,3,5))" = "newfile2.txt/1.1/" &&
  48     test "$(echo $(sort C/CVS/Entries|cut -d/ -f2,3,5))" = "newfile3.png/1.1/-kb" &&
  49     test "$(echo $(sort D/CVS/Entries|cut -d/ -f2,3,5))" = "newfile4.png/1.1/-kb" &&
  50     diff A/newfile1.txt ../A/newfile1.txt &&
  51     diff B/newfile2.txt ../B/newfile2.txt &&
  52     diff C/newfile3.png ../C/newfile3.png &&
  53     diff D/newfile4.png ../D/newfile4.png
  54     )'
  55
  56test_expect_success \
  57    'Remove two files, add two and update two' \
  58    'echo Hello1 >>A/newfile1.txt &&
  59     rm -f B/newfile2.txt &&
  60     rm -f C/newfile3.png &&
  61     echo Hello5  >E/newfile5.txt &&
  62     cp ../test9200b.png D/newfile4.png &&
  63     cp ../test9200a.png F/newfile6.png &&
  64     git add E/newfile5.txt &&
  65     git add F/newfile6.png &&
  66     git commit -a -m "Test: Remove, add and update" &&
  67     id=$(git rev-list --max-count=1 HEAD) &&
  68     (cd "$CVSWORK" &&
  69     git cvsexportcommit -c $id &&
  70     test "$(echo $(sort A/CVS/Entries|cut -d/ -f2,3,5))" = "newfile1.txt/1.2/" &&
  71     test "$(echo $(sort B/CVS/Entries|cut -d/ -f2,3,5))" = "" &&
  72     test "$(echo $(sort C/CVS/Entries|cut -d/ -f2,3,5))" = "" &&
  73     test "$(echo $(sort D/CVS/Entries|cut -d/ -f2,3,5))" = "newfile4.png/1.2/-kb" &&
  74     test "$(echo $(sort E/CVS/Entries|cut -d/ -f2,3,5))" = "newfile5.txt/1.1/" &&
  75     test "$(echo $(sort F/CVS/Entries|cut -d/ -f2,3,5))" = "newfile6.png/1.1/-kb" &&
  76     diff A/newfile1.txt ../A/newfile1.txt &&
  77     diff D/newfile4.png ../D/newfile4.png &&
  78     diff E/newfile5.txt ../E/newfile5.txt &&
  79     diff F/newfile6.png ../F/newfile6.png
  80     )'
  81
  82# Should fail (but only on the git-cvsexportcommit stage)
  83test_expect_success \
  84    'Fail to change binary more than one generation old' \
  85    'cat F/newfile6.png >>D/newfile4.png &&
  86     git commit -a -m "generatiion 1" &&
  87     cat F/newfile6.png >>D/newfile4.png &&
  88     git commit -a -m "generation 2" &&
  89     id=$(git rev-list --max-count=1 HEAD) &&
  90     (cd "$CVSWORK" &&
  91     ! git cvsexportcommit -c $id
  92     )'
  93
  94#test_expect_success \
  95#    'Fail to remove binary file more than one generation old' \
  96#    'git reset --hard HEAD^ &&
  97#     cat F/newfile6.png >>D/newfile4.png &&
  98#     git commit -a -m "generation 2 (again)" &&
  99#     rm -f D/newfile4.png &&
 100#     git commit -a -m "generation 3" &&
 101#     id=$(git rev-list --max-count=1 HEAD) &&
 102#     (cd "$CVSWORK" &&
 103#     ! git cvsexportcommit -c $id
 104#     )'
 105
 106# We reuse the state from two tests back here
 107
 108# This test is here because a patch for only binary files will
 109# fail with gnu patch, so cvsexportcommit must handle that.
 110test_expect_success \
 111    'Remove only binary files' \
 112    'git reset --hard HEAD^^ &&
 113     rm -f D/newfile4.png &&
 114     git commit -a -m "test: remove only a binary file" &&
 115     id=$(git rev-list --max-count=1 HEAD) &&
 116     (cd "$CVSWORK" &&
 117     git cvsexportcommit -c $id &&
 118     test "$(echo $(sort A/CVS/Entries|cut -d/ -f2,3,5))" = "newfile1.txt/1.2/" &&
 119     test "$(echo $(sort B/CVS/Entries|cut -d/ -f2,3,5))" = "" &&
 120     test "$(echo $(sort C/CVS/Entries|cut -d/ -f2,3,5))" = "" &&
 121     test "$(echo $(sort D/CVS/Entries|cut -d/ -f2,3,5))" = "" &&
 122     test "$(echo $(sort E/CVS/Entries|cut -d/ -f2,3,5))" = "newfile5.txt/1.1/" &&
 123     test "$(echo $(sort F/CVS/Entries|cut -d/ -f2,3,5))" = "newfile6.png/1.1/-kb" &&
 124     diff A/newfile1.txt ../A/newfile1.txt &&
 125     diff E/newfile5.txt ../E/newfile5.txt &&
 126     diff F/newfile6.png ../F/newfile6.png
 127     )'
 128
 129test_expect_success \
 130    'Remove only a text file' \
 131    'rm -f A/newfile1.txt &&
 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     test "$(echo $(sort A/CVS/Entries|cut -d/ -f2,3,5))" = "" &&
 137     test "$(echo $(sort B/CVS/Entries|cut -d/ -f2,3,5))" = "" &&
 138     test "$(echo $(sort C/CVS/Entries|cut -d/ -f2,3,5))" = "" &&
 139     test "$(echo $(sort D/CVS/Entries|cut -d/ -f2,3,5))" = "" &&
 140     test "$(echo $(sort E/CVS/Entries|cut -d/ -f2,3,5))" = "newfile5.txt/1.1/" &&
 141     test "$(echo $(sort F/CVS/Entries|cut -d/ -f2,3,5))" = "newfile6.png/1.1/-kb" &&
 142     diff E/newfile5.txt ../E/newfile5.txt &&
 143     diff F/newfile6.png ../F/newfile6.png
 144     )'
 145
 146test_expect_success \
 147     'New file with spaces in file name' \
 148     'mkdir "G g" &&
 149      echo ok then >"G g/with spaces.txt" &&
 150      git add "G g/with spaces.txt" && \
 151      cp ../test9200a.png "G g/with spaces.png" && \
 152      git add "G g/with spaces.png" &&
 153      git commit -a -m "With spaces" &&
 154      id=$(git rev-list --max-count=1 HEAD) &&
 155      (cd "$CVSWORK" &&
 156      git-cvsexportcommit -c $id &&
 157      test "$(echo $(sort "G g/CVS/Entries"|cut -d/ -f2,3,5))" = "with spaces.png/1.1/-kb with spaces.txt/1.1/"
 158      )'
 159
 160test_expect_success \
 161     'Update file with spaces in file name' \
 162     'echo Ok then >>"G g/with spaces.txt" &&
 163      cat ../test9200a.png >>"G g/with spaces.png" && \
 164      git add "G g/with spaces.png" &&
 165      git commit -a -m "Update with spaces" &&
 166      id=$(git rev-list --max-count=1 HEAD) &&
 167      (cd "$CVSWORK" &&
 168      git-cvsexportcommit -c $id
 169      test "$(echo $(sort "G g/CVS/Entries"|cut -d/ -f2,3,5))" = "with spaces.png/1.2/-kb with spaces.txt/1.2/"
 170      )'
 171
 172# Some filesystems mangle pathnames with UTF-8 characters --
 173# check and skip
 174if 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/å/ä/ö" &&
 175        mkdir -p "tst/$p" &&
 176        date >"tst/$p/day" &&
 177        found=$(find tst -type f -print) &&
 178        test "z$found" = "ztst/$p/day" &&
 179        rm -fr tst
 180then
 181
 182# This test contains UTF-8 characters
 183test_expect_success \
 184     'File with non-ascii file name' \
 185     '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/å/ä/ö &&
 186      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 &&
 187      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 &&
 188      cp ../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 &&
 189      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 &&
 190      git commit -a -m "Går det så går det" && \
 191      id=$(git rev-list --max-count=1 HEAD) &&
 192      (cd "$CVSWORK" &&
 193      git-cvsexportcommit -v -c $id &&
 194      test "$(echo $(sort Å/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/å/ä/ö/CVS/Entries|cut -d/ -f2,3,5))" = "gårdetsågårdet.png/1.1/-kb gårdetsågårdet.txt/1.1/"
 195      )'
 196
 197fi
 198
 199rm -fr tst
 200
 201test_expect_success \
 202     'Mismatching patch should fail' \
 203     'date >>"E/newfile5.txt" &&
 204      git add "E/newfile5.txt" &&
 205      git commit -a -m "Update one" &&
 206      date >>"E/newfile5.txt" &&
 207      git add "E/newfile5.txt" &&
 208      git commit -a -m "Update two" &&
 209      id=$(git rev-list --max-count=1 HEAD) &&
 210      (cd "$CVSWORK" &&
 211      ! git-cvsexportcommit -c $id
 212      )'
 213
 214case "$(git repo-config --bool core.filemode)" in
 215false)
 216        ;;
 217*)
 218test_expect_success \
 219     'Retain execute bit' \
 220     'mkdir G &&
 221      echo executeon >G/on &&
 222      chmod +x G/on &&
 223      echo executeoff >G/off &&
 224      git add G/on &&
 225      git add G/off &&
 226      git commit -a -m "Execute test" &&
 227      (cd "$CVSWORK" &&
 228      git-cvsexportcommit -c HEAD
 229      test -x G/on &&
 230      ! test -x G/off
 231      )'
 232        ;;
 233esac
 234
 235test_done