t / t9200-git-cvsexportcommit.shon commit git-svn: remove support for the svn command-line client (b9c8518)
   1#!/bin/bash
   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
  17export CVSROOT=$(pwd)/cvsroot
  18export CVSWORK=$(pwd)/cvswork
  19rm -rf "$CVSROOT" "$CVSWORK"
  20mkdir "$CVSROOT" &&
  21cvs init &&
  22cvs -Q co -d "$CVSWORK" . &&
  23export GIT_DIR=$(pwd)/.git &&
  24echo >empty &&
  25git add empty &&
  26git commit -a -m "Initial" 2>/dev/null ||
  27exit 1
  28
  29test_expect_success \
  30    'New file' \
  31    'mkdir A B C D E F &&
  32     echo hello1 >A/newfile1.txt &&
  33     echo hello2 >B/newfile2.txt &&
  34     cp ../test9200a.png C/newfile3.png &&
  35     cp ../test9200a.png D/newfile4.png &&
  36     git add A/newfile1.txt &&
  37     git add B/newfile2.txt &&
  38     git add C/newfile3.png &&
  39     git add D/newfile4.png &&
  40     git commit -a -m "Test: New file" &&
  41     id=$(git rev-list --max-count=1 HEAD) &&
  42     (cd "$CVSWORK" &&
  43     git cvsexportcommit -c $id &&
  44     test "$(echo $(sort A/CVS/Entries|cut -d/ -f2,3,5))" = "newfile1.txt/1.1/" &&
  45     test "$(echo $(sort B/CVS/Entries|cut -d/ -f2,3,5))" = "newfile2.txt/1.1/" &&
  46     test "$(echo $(sort C/CVS/Entries|cut -d/ -f2,3,5))" = "newfile3.png/1.1/-kb" &&
  47     test "$(echo $(sort D/CVS/Entries|cut -d/ -f2,3,5))" = "newfile4.png/1.1/-kb" &&
  48     diff A/newfile1.txt ../A/newfile1.txt &&
  49     diff B/newfile2.txt ../B/newfile2.txt &&
  50     diff C/newfile3.png ../C/newfile3.png &&
  51     diff D/newfile4.png ../D/newfile4.png
  52     )'
  53
  54test_expect_success \
  55    'Remove two files, add two and update two' \
  56    'echo Hello1 >>A/newfile1.txt &&
  57     rm -f B/newfile2.txt &&
  58     rm -f C/newfile3.png &&
  59     echo Hello5  >E/newfile5.txt &&
  60     cp ../test9200b.png D/newfile4.png &&
  61     cp ../test9200a.png F/newfile6.png &&
  62     git add E/newfile5.txt &&
  63     git add F/newfile6.png &&
  64     git commit -a -m "Test: Remove, add and update" &&
  65     id=$(git rev-list --max-count=1 HEAD) &&
  66     (cd "$CVSWORK" &&
  67     git cvsexportcommit -c $id &&
  68     test "$(echo $(sort A/CVS/Entries|cut -d/ -f2,3,5))" = "newfile1.txt/1.2/" &&
  69     test "$(echo $(sort B/CVS/Entries|cut -d/ -f2,3,5))" = "" &&
  70     test "$(echo $(sort C/CVS/Entries|cut -d/ -f2,3,5))" = "" &&
  71     test "$(echo $(sort D/CVS/Entries|cut -d/ -f2,3,5))" = "newfile4.png/1.2/-kb" &&
  72     test "$(echo $(sort E/CVS/Entries|cut -d/ -f2,3,5))" = "newfile5.txt/1.1/" &&
  73     test "$(echo $(sort F/CVS/Entries|cut -d/ -f2,3,5))" = "newfile6.png/1.1/-kb" &&
  74     diff A/newfile1.txt ../A/newfile1.txt &&
  75     diff D/newfile4.png ../D/newfile4.png &&
  76     diff E/newfile5.txt ../E/newfile5.txt &&
  77     diff F/newfile6.png ../F/newfile6.png
  78     )'
  79
  80# Should fail (but only on the git-cvsexportcommit stage)
  81test_expect_success \
  82    'Fail to change binary more than one generation old' \
  83    'cat F/newfile6.png >>D/newfile4.png &&
  84     git commit -a -m "generatiion 1" &&
  85     cat F/newfile6.png >>D/newfile4.png &&
  86     git commit -a -m "generation 2" &&
  87     id=$(git rev-list --max-count=1 HEAD) &&
  88     (cd "$CVSWORK" &&
  89     ! git cvsexportcommit -c $id
  90     )'
  91
  92#test_expect_success \
  93#    'Fail to remove binary file more than one generation old' \
  94#    'git reset --hard HEAD^ &&
  95#     cat F/newfile6.png >>D/newfile4.png &&
  96#     git commit -a -m "generation 2 (again)" &&
  97#     rm -f D/newfile4.png &&
  98#     git commit -a -m "generation 3" &&
  99#     id=$(git rev-list --max-count=1 HEAD) &&
 100#     (cd "$CVSWORK" &&
 101#     ! git cvsexportcommit -c $id
 102#     )'
 103
 104# We reuse the state from two tests back here
 105
 106# This test is here because a patch for only binary files will
 107# fail with gnu patch, so cvsexportcommit must handle that.
 108test_expect_success \
 109    'Remove only binary files' \
 110    'git reset --hard HEAD^^ &&
 111     rm -f D/newfile4.png &&
 112     git commit -a -m "test: remove only a binary file" &&
 113     id=$(git rev-list --max-count=1 HEAD) &&
 114     (cd "$CVSWORK" &&
 115     git cvsexportcommit -c $id &&
 116     test "$(echo $(sort A/CVS/Entries|cut -d/ -f2,3,5))" = "newfile1.txt/1.2/" &&
 117     test "$(echo $(sort B/CVS/Entries|cut -d/ -f2,3,5))" = "" &&
 118     test "$(echo $(sort C/CVS/Entries|cut -d/ -f2,3,5))" = "" &&
 119     test "$(echo $(sort D/CVS/Entries|cut -d/ -f2,3,5))" = "" &&
 120     test "$(echo $(sort E/CVS/Entries|cut -d/ -f2,3,5))" = "newfile5.txt/1.1/" &&
 121     test "$(echo $(sort F/CVS/Entries|cut -d/ -f2,3,5))" = "newfile6.png/1.1/-kb" &&
 122     diff A/newfile1.txt ../A/newfile1.txt &&
 123     diff E/newfile5.txt ../E/newfile5.txt &&
 124     diff F/newfile6.png ../F/newfile6.png
 125     )'
 126
 127test_expect_success \
 128    'Remove only a text file' \
 129    'rm -f A/newfile1.txt &&
 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     test "$(echo $(sort A/CVS/Entries|cut -d/ -f2,3,5))" = "" &&
 135     test "$(echo $(sort B/CVS/Entries|cut -d/ -f2,3,5))" = "" &&
 136     test "$(echo $(sort C/CVS/Entries|cut -d/ -f2,3,5))" = "" &&
 137     test "$(echo $(sort D/CVS/Entries|cut -d/ -f2,3,5))" = "" &&
 138     test "$(echo $(sort E/CVS/Entries|cut -d/ -f2,3,5))" = "newfile5.txt/1.1/" &&
 139     test "$(echo $(sort F/CVS/Entries|cut -d/ -f2,3,5))" = "newfile6.png/1.1/-kb" &&
 140     diff E/newfile5.txt ../E/newfile5.txt &&
 141     diff F/newfile6.png ../F/newfile6.png
 142     )'
 143
 144test_expect_success \
 145     'New file with spaces in file name' \
 146     'mkdir "G g" &&
 147      echo ok then >"G g/with spaces.txt" &&
 148      git add "G g/with spaces.txt" && \
 149      cp ../test9200a.png "G g/with spaces.png" && \
 150      git add "G g/with spaces.png" &&
 151      git commit -a -m "With spaces" &&
 152      id=$(git rev-list --max-count=1 HEAD) &&
 153      (cd "$CVSWORK" &&
 154      git-cvsexportcommit -c $id &&
 155      test "$(echo $(sort "G g/CVS/Entries"|cut -d/ -f2,3,5))" = "with spaces.png/1.1/-kb with spaces.txt/1.1/"
 156      )'
 157
 158test_expect_success \
 159     'Update file with spaces in file name' \
 160     'echo Ok then >>"G g/with spaces.txt" &&
 161      cat ../test9200a.png >>"G g/with spaces.png" && \
 162      git add "G g/with spaces.png" &&
 163      git commit -a -m "Update with spaces" &&
 164      id=$(git rev-list --max-count=1 HEAD) &&
 165      (cd "$CVSWORK" &&
 166      git-cvsexportcommit -c $id
 167      test "$(echo $(sort "G g/CVS/Entries"|cut -d/ -f2,3,5))" = "with spaces.png/1.2/-kb with spaces.txt/1.2/"
 168      )'
 169
 170# This test contains ISO-8859-1 characters
 171test_expect_success \
 172     'File with non-ascii file name' \
 173     '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/å/ä/ö &&
 174      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 &&
 175      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 &&
 176      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 &&
 177      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 &&
 178      git commit -a -m "Går det så går det" && \
 179      id=$(git rev-list --max-count=1 HEAD) &&
 180      (cd "$CVSWORK" &&
 181      git-cvsexportcommit -v -c $id &&
 182      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/"
 183      )'
 184
 185test_expect_success \
 186     'Mismatching patch should fail' \
 187     'date >>"E/newfile5.txt" &&
 188      git add "E/newfile5.txt" &&
 189      git commit -a -m "Update one" &&
 190      date >>"E/newfile5.txt" &&
 191      git add "E/newfile5.txt" &&
 192      git commit -a -m "Update two" &&
 193      id=$(git rev-list --max-count=1 HEAD) &&
 194      (cd "$CVSWORK" &&
 195      ! git-cvsexportcommit -c $id
 196      )'
 197
 198test_expect_success \
 199     'Retain execute bit' \
 200     'mkdir G &&
 201      echo executeon >G/on &&
 202      chmod +x G/on &&
 203      echo executeoff >G/off &&
 204      git add G/on &&
 205      git add G/off &&
 206      git commit -a -m "Execute test" &&
 207      (cd "$CVSWORK" &&
 208      git-cvsexportcommit -c HEAD
 209      test -x G/on &&
 210      ! test -x G/off
 211      )'
 212
 213test_done