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