t / t9100-git-svn-basic.shon commit mingw: mark t9100's test cases with appropriate prereqs (bcb11f1)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Eric Wong
   4#
   5
   6test_description='git svn basic tests'
   7GIT_SVN_LC_ALL=${LC_ALL:-$LANG}
   8
   9. ./lib-git-svn.sh
  10
  11say 'define NO_SVN_TESTS to skip git svn tests'
  12
  13case "$GIT_SVN_LC_ALL" in
  14*.UTF-8)
  15        test_set_prereq UTF8
  16        ;;
  17*)
  18        say "# UTF-8 locale not set, some tests skipped ($GIT_SVN_LC_ALL)"
  19        ;;
  20esac
  21
  22test_expect_success \
  23    'initialize git svn' '
  24        mkdir import &&
  25        (
  26                cd import &&
  27                echo foo >foo &&
  28                ln -s foo foo.link
  29                mkdir -p dir/a/b/c/d/e &&
  30                echo "deep dir" >dir/a/b/c/d/e/file &&
  31                mkdir bar &&
  32                echo "zzz" >bar/zzz &&
  33                write_script exec.sh </dev/null &&
  34                svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null
  35        ) &&
  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_cmd 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_success "$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        test_must_fail git svn set-tree --find-copies-harder --rmdir \
  67                ${remotes_git_svn}..mybranch
  68"
  69
  70
  71name='detect node change from directory to file #1'
  72test_expect_success "$name" '
  73        rm -rf dir "$GIT_DIR"/index &&
  74        git checkout -f -b mybranch2 ${remotes_git_svn} &&
  75        mv bar/zzz zzz &&
  76        rm -rf bar &&
  77        mv zzz bar &&
  78        git update-index --remove -- bar/zzz &&
  79        git update-index --add -- bar &&
  80        git commit -m "$name" &&
  81        test_must_fail git svn set-tree --find-copies-harder --rmdir \
  82                ${remotes_git_svn}..mybranch2
  83'
  84
  85
  86name='detect node change from file to directory #2'
  87test_expect_success "$name" '
  88        rm -f "$GIT_DIR"/index &&
  89        git checkout -f -b mybranch3 ${remotes_git_svn} &&
  90        rm bar/zzz &&
  91        git update-index --remove bar/zzz &&
  92        mkdir bar/zzz &&
  93        echo yyy > bar/zzz/yyy &&
  94        git update-index --add bar/zzz/yyy &&
  95        git commit -m "$name" &&
  96        git svn set-tree --find-copies-harder --rmdir \
  97                ${remotes_git_svn}..mybranch3 &&
  98        svn_cmd up "$SVN_TREE" &&
  99        test -d "$SVN_TREE"/bar/zzz &&
 100        test -e "$SVN_TREE"/bar/zzz/yyy
 101'
 102
 103name='detect node change from directory to file #2'
 104test_expect_success "$name" '
 105        rm -f "$GIT_DIR"/index &&
 106        git checkout -f -b mybranch4 ${remotes_git_svn} &&
 107        rm -rf dir &&
 108        git update-index --remove -- dir/file &&
 109        touch dir &&
 110        echo asdf > dir &&
 111        git update-index --add -- dir &&
 112        git commit -m "$name" &&
 113        test_must_fail git svn set-tree --find-copies-harder --rmdir \
 114                ${remotes_git_svn}..mybranch4
 115'
 116
 117
 118name='remove executable bit from a file'
 119test_expect_success POSIXPERM "$name" '
 120        rm -f "$GIT_DIR"/index &&
 121        git checkout -f -b mybranch5 ${remotes_git_svn} &&
 122        chmod -x exec.sh &&
 123        git update-index exec.sh &&
 124        git commit -m "$name" &&
 125        git svn set-tree --find-copies-harder --rmdir \
 126                ${remotes_git_svn}..mybranch5 &&
 127        svn_cmd up "$SVN_TREE" &&
 128        test ! -x "$SVN_TREE"/exec.sh'
 129
 130
 131name='add executable bit back file'
 132test_expect_success POSIXPERM "$name" '
 133        chmod +x exec.sh &&
 134        git update-index exec.sh &&
 135        git commit -m "$name" &&
 136        git svn set-tree --find-copies-harder --rmdir \
 137                ${remotes_git_svn}..mybranch5 &&
 138        svn_cmd up "$SVN_TREE" &&
 139        test -x "$SVN_TREE"/exec.sh'
 140
 141
 142name='executable file becomes a symlink to file'
 143test_expect_success SYMLINKS "$name" '
 144        rm exec.sh &&
 145        ln -s file exec.sh &&
 146        git update-index exec.sh &&
 147        git commit -m "$name" &&
 148        git svn set-tree --find-copies-harder --rmdir \
 149                ${remotes_git_svn}..mybranch5 &&
 150        svn_cmd up "$SVN_TREE" &&
 151        test -h "$SVN_TREE"/exec.sh'
 152
 153name='new symlink is added to a file that was also just made executable'
 154
 155test_expect_success POSIXPERM,SYMLINKS "$name" '
 156        chmod +x file &&
 157        ln -s file exec-2.sh &&
 158        git update-index --add file exec-2.sh &&
 159        git commit -m "$name" &&
 160        git svn set-tree --find-copies-harder --rmdir \
 161                ${remotes_git_svn}..mybranch5 &&
 162        svn_cmd up "$SVN_TREE" &&
 163        test -x "$SVN_TREE"/file &&
 164        test -h "$SVN_TREE"/exec-2.sh'
 165
 166name='modify a symlink to become a file'
 167test_expect_success POSIXPERM,SYMLINKS "$name" '
 168        echo git help >help &&
 169        rm exec-2.sh &&
 170        cp help exec-2.sh &&
 171        git update-index exec-2.sh &&
 172        git commit -m "$name" &&
 173        git svn set-tree --find-copies-harder --rmdir \
 174                ${remotes_git_svn}..mybranch5 &&
 175        svn_cmd up "$SVN_TREE" &&
 176        test -f "$SVN_TREE"/exec-2.sh &&
 177        test ! -h "$SVN_TREE"/exec-2.sh &&
 178        test_cmp help "$SVN_TREE"/exec-2.sh'
 179
 180name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL"
 181LC_ALL="$GIT_SVN_LC_ALL"
 182export LC_ALL
 183# This test relies on the previous test, hence requires POSIXPERM,SYMLINKS
 184test_expect_success UTF8,POSIXPERM,SYMLINKS "$name" "
 185        echo '# hello' >> exec-2.sh &&
 186        git update-index exec-2.sh &&
 187        git commit -m 'éï∏' &&
 188        git svn set-tree HEAD"
 189unset LC_ALL
 190
 191name='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
 192GIT_SVN_ID=alt
 193export GIT_SVN_ID
 194test_expect_success "$name" \
 195    'git svn init "$svnrepo" && git svn fetch &&
 196     git rev-list --pretty=raw ${remotes_git_svn} | grep ^tree | uniq > a &&
 197     git rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b &&
 198     test_cmp a b'
 199
 200name='check imported tree checksums expected tree checksums'
 201rm -f expected
 202if test_have_prereq UTF8
 203then
 204        echo tree dc68b14b733e4ec85b04ab6f712340edc5dc936e > expected
 205fi
 206cat >> expected <<\EOF
 207tree c3322890dcf74901f32d216f05c5044f670ce632
 208tree d3ccd5035feafd17b030c5732e7808cc49122853
 209tree d03e1630363d4881e68929d532746b20b0986b83
 210tree 149d63cd5878155c846e8c55d7d8487de283f89e
 211tree 312b76e4f64ce14893aeac8591eb3960b065e247
 212tree 149d63cd5878155c846e8c55d7d8487de283f89e
 213tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
 214tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4
 215EOF
 216
 217test_expect_success POSIXPERM,SYMLINKS "$name" "test_cmp a expected"
 218
 219test_expect_success 'exit if remote refs are ambigious' "
 220        git config --add svn-remote.svn.fetch \
 221                              bar:refs/${remotes_git_svn} &&
 222        test_must_fail git svn migrate
 223"
 224
 225test_expect_success 'exit if init-ing a would clobber a URL' '
 226        svnadmin create "${PWD}/svnrepo2" &&
 227        svn mkdir -m "mkdir bar" "${svnrepo}2/bar" &&
 228        git config --unset svn-remote.svn.fetch \
 229                                "^bar:refs/${remotes_git_svn}$" &&
 230        test_must_fail git svn init "${svnrepo}2/bar"
 231        '
 232
 233test_expect_success \
 234  'init allows us to connect to another directory in the same repo' '
 235        git svn init --minimize-url -i bar "$svnrepo/bar" &&
 236        git config --get svn-remote.svn.fetch \
 237                              "^bar:refs/remotes/bar$" &&
 238        git config --get svn-remote.svn.fetch \
 239                              "^:refs/${remotes_git_svn}$"
 240        '
 241
 242test_expect_success 'dcommit $rev does not clobber current branch' '
 243        git svn fetch -i bar &&
 244        git checkout -b my-bar refs/remotes/bar &&
 245        echo 1 > foo &&
 246        git add foo &&
 247        git commit -m "change 1" &&
 248        echo 2 > foo &&
 249        git add foo &&
 250        git commit -m "change 2" &&
 251        old_head=$(git rev-parse HEAD) &&
 252        git svn dcommit -i bar HEAD^ &&
 253        test $old_head = $(git rev-parse HEAD) &&
 254        test refs/heads/my-bar = $(git symbolic-ref HEAD) &&
 255        git log refs/remotes/bar | grep "change 1" &&
 256        ! git log refs/remotes/bar | grep "change 2" &&
 257        git checkout master &&
 258        git branch -D my-bar
 259        '
 260
 261test_expect_success 'able to dcommit to a subdirectory' "
 262        git svn fetch -i bar &&
 263        git checkout -b my-bar refs/remotes/bar &&
 264        echo abc > d &&
 265        git update-index --add d &&
 266        git commit -m '/bar/d should be in the log' &&
 267        git svn dcommit -i bar &&
 268        test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\" &&
 269        mkdir newdir &&
 270        echo new > newdir/dir &&
 271        git update-index --add newdir/dir &&
 272        git commit -m 'add a new directory' &&
 273        git svn dcommit -i bar &&
 274        test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\" &&
 275        echo foo >> newdir/dir &&
 276        git update-index newdir/dir &&
 277        git commit -m 'modify a file in new directory' &&
 278        git svn dcommit -i bar &&
 279        test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\"
 280        "
 281
 282test_expect_success 'dcommit should not fail with a touched file' '
 283        test_commit "commit-new-file-foo2" foo2 &&
 284        test-chmtime =-60 foo &&
 285        git svn dcommit
 286'
 287
 288test_expect_success 'rebase should not fail with a touched file' '
 289        test-chmtime =-60 foo &&
 290        git svn rebase
 291'
 292
 293test_expect_success 'able to set-tree to a subdirectory' "
 294        echo cba > d &&
 295        git update-index d &&
 296        git commit -m 'update /bar/d' &&
 297        git svn set-tree -i bar HEAD &&
 298        test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\"
 299        "
 300
 301test_expect_success 'git-svn works in a bare repository' '
 302        mkdir bare-repo &&
 303        ( cd bare-repo &&
 304        git init --bare &&
 305        GIT_DIR=. git svn init "$svnrepo" &&
 306        git svn fetch ) &&
 307        rm -rf bare-repo
 308        '
 309test_expect_success 'git-svn works in in a repository with a gitdir: link' '
 310        mkdir worktree gitdir &&
 311        ( cd worktree &&
 312        git svn init "$svnrepo" &&
 313        git init --separate-git-dir ../gitdir &&
 314        git svn fetch ) &&
 315        rm -rf worktree gitdir
 316        '
 317
 318test_done