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