t / t9100-git-svn-basic.shon commit Merge branch 'master' into np/dreflog (d77ee72)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Eric Wong
   4#
   5
   6test_description='git-svn basic tests'
   7GIT_SVN_LC_ALL=$LC_ALL
   8
   9case "$LC_ALL" in
  10*.UTF-8)
  11        have_utf8=t
  12        ;;
  13*)
  14        have_utf8=
  15        ;;
  16esac
  17
  18. ./lib-git-svn.sh
  19
  20echo 'define NO_SVN_TESTS to skip git-svn tests'
  21
  22test_expect_success \
  23    'initialize git-svn' "
  24        mkdir import &&
  25        cd import &&
  26        echo foo > foo &&
  27        ln -s foo foo.link
  28        mkdir -p dir/a/b/c/d/e &&
  29        echo 'deep dir' > dir/a/b/c/d/e/file &&
  30        mkdir bar &&
  31        echo 'zzz' > bar/zzz &&
  32        echo '#!/bin/sh' > exec.sh &&
  33        chmod +x exec.sh &&
  34        svn import -m 'import for git-svn' . $svnrepo >/dev/null &&
  35        cd .. &&
  36        rm -rf import &&
  37        git-svn init $svnrepo"
  38
  39test_expect_success \
  40    'import an SVN revision into git' \
  41    'git-svn fetch'
  42
  43test_expect_success "checkout from svn" "svn co $svnrepo '$SVN_TREE'"
  44
  45name='try a deep --rmdir with a commit'
  46test_expect_success "$name" "
  47        git checkout -f -b mybranch remotes/git-svn &&
  48        mv dir/a/b/c/d/e/file dir/file &&
  49        cp dir/file file &&
  50        git update-index --add --remove dir/a/b/c/d/e/file dir/file file &&
  51        git commit -m '$name' &&
  52        git-svn set-tree --find-copies-harder --rmdir \
  53                remotes/git-svn..mybranch &&
  54        svn up '$SVN_TREE' &&
  55        test -d '$SVN_TREE'/dir && test ! -d '$SVN_TREE'/dir/a"
  56
  57
  58name='detect node change from file to directory #1'
  59test_expect_failure "$name" "
  60        mkdir dir/new_file &&
  61        mv dir/file dir/new_file/file &&
  62        mv dir/new_file dir/file &&
  63        git update-index --remove dir/file &&
  64        git update-index --add dir/file/file &&
  65        git commit -m '$name'  &&
  66        git-svn set-tree --find-copies-harder --rmdir \
  67                remotes/git-svn..mybranch" || true
  68
  69
  70name='detect node change from directory to file #1'
  71test_expect_failure "$name" "
  72        rm -rf dir '$GIT_DIR'/index &&
  73        git checkout -f -b mybranch2 remotes/git-svn &&
  74        mv bar/zzz zzz &&
  75        rm -rf bar &&
  76        mv zzz bar &&
  77        git update-index --remove -- bar/zzz &&
  78        git update-index --add -- bar &&
  79        git commit -m '$name' &&
  80        git-svn set-tree --find-copies-harder --rmdir \
  81                remotes/git-svn..mybranch2" || true
  82
  83
  84name='detect node change from file to directory #2'
  85test_expect_failure "$name" "
  86        rm -f '$GIT_DIR'/index &&
  87        git checkout -f -b mybranch3 remotes/git-svn &&
  88        rm bar/zzz &&
  89        git-update-index --remove bar/zzz &&
  90        mkdir bar/zzz &&
  91        echo yyy > bar/zzz/yyy &&
  92        git-update-index --add bar/zzz/yyy &&
  93        git commit -m '$name' &&
  94        git-svn set-tree --find-copies-harder --rmdir \
  95                remotes/git-svn..mybranch3" || true
  96
  97
  98name='detect node change from directory to file #2'
  99test_expect_failure "$name" "
 100        rm -f '$GIT_DIR'/index &&
 101        git checkout -f -b mybranch4 remotes/git-svn &&
 102        rm -rf dir &&
 103        git update-index --remove -- dir/file &&
 104        touch dir &&
 105        echo asdf > dir &&
 106        git update-index --add -- dir &&
 107        git commit -m '$name' &&
 108        git-svn set-tree --find-copies-harder --rmdir \
 109                remotes/git-svn..mybranch4" || true
 110
 111
 112name='remove executable bit from a file'
 113test_expect_success "$name" "
 114        rm -f '$GIT_DIR'/index &&
 115        git checkout -f -b mybranch5 remotes/git-svn &&
 116        chmod -x exec.sh &&
 117        git update-index exec.sh &&
 118        git commit -m '$name' &&
 119        git-svn set-tree --find-copies-harder --rmdir \
 120                remotes/git-svn..mybranch5 &&
 121        svn up '$SVN_TREE' &&
 122        test ! -x '$SVN_TREE'/exec.sh"
 123
 124
 125name='add executable bit back file'
 126test_expect_success "$name" "
 127        chmod +x exec.sh &&
 128        git update-index exec.sh &&
 129        git commit -m '$name' &&
 130        git-svn set-tree --find-copies-harder --rmdir \
 131                remotes/git-svn..mybranch5 &&
 132        svn up '$SVN_TREE' &&
 133        test -x '$SVN_TREE'/exec.sh"
 134
 135
 136name='executable file becomes a symlink to bar/zzz (file)'
 137test_expect_success "$name" "
 138        rm exec.sh &&
 139        ln -s bar/zzz exec.sh &&
 140        git update-index exec.sh &&
 141        git commit -m '$name' &&
 142        git-svn set-tree --find-copies-harder --rmdir \
 143                remotes/git-svn..mybranch5 &&
 144        svn up '$SVN_TREE' &&
 145        test -L '$SVN_TREE'/exec.sh"
 146
 147name='new symlink is added to a file that was also just made executable'
 148
 149test_expect_success "$name" "
 150        chmod +x bar/zzz &&
 151        ln -s bar/zzz exec-2.sh &&
 152        git update-index --add bar/zzz exec-2.sh &&
 153        git commit -m '$name' &&
 154        git-svn set-tree --find-copies-harder --rmdir \
 155                remotes/git-svn..mybranch5 &&
 156        svn up '$SVN_TREE' &&
 157        test -x '$SVN_TREE'/bar/zzz &&
 158        test -L '$SVN_TREE'/exec-2.sh"
 159
 160name='modify a symlink to become a file'
 161test_expect_success "$name" "
 162        echo git help > help || true &&
 163        rm exec-2.sh &&
 164        cp help exec-2.sh &&
 165        git update-index exec-2.sh &&
 166        git commit -m '$name' &&
 167        git-svn set-tree --find-copies-harder --rmdir \
 168                remotes/git-svn..mybranch5 &&
 169        svn up '$SVN_TREE' &&
 170        test -f '$SVN_TREE'/exec-2.sh &&
 171        test ! -L '$SVN_TREE'/exec-2.sh &&
 172        diff -u help $SVN_TREE/exec-2.sh"
 173
 174if test "$have_utf8" = t
 175then
 176        name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL"
 177        LC_ALL="$GIT_SVN_LC_ALL"
 178        export LC_ALL
 179        test_expect_success "$name" "
 180                echo '# hello' >> exec-2.sh &&
 181                git update-index exec-2.sh &&
 182                git commit -m 'éï∏' &&
 183                git-svn set-tree HEAD"
 184        unset LC_ALL
 185else
 186        echo "UTF-8 locale not set, test skipped ($GIT_SVN_LC_ALL)"
 187fi
 188
 189name='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
 190GIT_SVN_ID=alt
 191export GIT_SVN_ID
 192test_expect_success "$name" \
 193    "git-svn init $svnrepo && git-svn fetch &&
 194     git-rev-list --pretty=raw remotes/git-svn | grep ^tree | uniq > a &&
 195     git-rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b &&
 196     diff -u a b"
 197
 198name='check imported tree checksums expected tree checksums'
 199rm -f expected
 200if test "$have_utf8" = t
 201then
 202        echo tree bf522353586b1b883488f2bc73dab0d9f774b9a9 > expected
 203fi
 204cat >> expected <<\EOF
 205tree 83654bb36f019ae4fe77a0171f81075972087624
 206tree 031b8d557afc6fea52894eaebb45bec52f1ba6d1
 207tree 0b094cbff17168f24c302e297f55bfac65eb8bd3
 208tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
 209tree 56a30b966619b863674f5978696f4a3594f2fca9
 210tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
 211tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4
 212EOF
 213
 214echo tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 >> expected
 215
 216test_expect_success "$name" "diff -u a expected"
 217
 218test_done