3 # Copyright (c) 2006 Eric Wong
 
   6 test_description='git svn basic tests'
 
   7 GIT_SVN_LC_ALL=${LC_ALL:-$LANG}
 
  11 case "$GIT_SVN_LC_ALL" in
 
  16         say "# UTF-8 locale not set, some tests skipped ($GIT_SVN_LC_ALL)"
 
  20 test_expect_success 'git svn --version works anywhere' '
 
  21         nongit git svn --version
 
  24 test_expect_success 'git svn help works anywhere' '
 
  29     'initialize git svn' '
 
  35                 mkdir -p dir/a/b/c/d/e &&
 
  36                 echo "deep dir" >dir/a/b/c/d/e/file &&
 
  38                 echo "zzz" >bar/zzz &&
 
  39                 echo "#!/bin/sh" >exec.sh &&
 
  41                 svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null
 
  44         git svn init "$svnrepo"'
 
  47     'import an SVN revision into git' \
 
  50 test_expect_success "checkout from svn" 'svn co "$svnrepo" "$SVN_TREE"'
 
  52 name='try a deep --rmdir with a commit'
 
  53 test_expect_success "$name" '
 
  54         git checkout -f -b mybranch remotes/git-svn &&
 
  55         mv dir/a/b/c/d/e/file dir/file &&
 
  57         git update-index --add --remove dir/a/b/c/d/e/file dir/file file &&
 
  58         git commit -m "$name" &&
 
  59         git svn set-tree --find-copies-harder --rmdir \
 
  60                 remotes/git-svn..mybranch &&
 
  61         svn_cmd up "$SVN_TREE" &&
 
  62         test -d "$SVN_TREE"/dir && test ! -d "$SVN_TREE"/dir/a'
 
  65 name='detect node change from file to directory #1'
 
  66 test_expect_success "$name" "
 
  68         mv dir/file dir/new_file/file &&
 
  69         mv dir/new_file dir/file &&
 
  70         git update-index --remove dir/file &&
 
  71         git update-index --add dir/file/file &&
 
  72         git commit -m '$name' &&
 
  73         test_must_fail git svn set-tree --find-copies-harder --rmdir \
 
  74                 remotes/git-svn..mybranch
 
  78 name='detect node change from directory to file #1'
 
  79 test_expect_success "$name" '
 
  80         rm -rf dir "$GIT_DIR"/index &&
 
  81         git checkout -f -b mybranch2 remotes/git-svn &&
 
  85         git update-index --remove -- bar/zzz &&
 
  86         git update-index --add -- bar &&
 
  87         git commit -m "$name" &&
 
  88         test_must_fail git svn set-tree --find-copies-harder --rmdir \
 
  89                 remotes/git-svn..mybranch2
 
  93 name='detect node change from file to directory #2'
 
  94 test_expect_success "$name" '
 
  95         rm -f "$GIT_DIR"/index &&
 
  96         git checkout -f -b mybranch3 remotes/git-svn &&
 
  98         git update-index --remove bar/zzz &&
 
 100         echo yyy > bar/zzz/yyy &&
 
 101         git update-index --add bar/zzz/yyy &&
 
 102         git commit -m "$name" &&
 
 103         git svn set-tree --find-copies-harder --rmdir \
 
 104                 remotes/git-svn..mybranch3 &&
 
 105         svn_cmd up "$SVN_TREE" &&
 
 106         test -d "$SVN_TREE"/bar/zzz &&
 
 107         test -e "$SVN_TREE"/bar/zzz/yyy
 
 110 name='detect node change from directory to file #2'
 
 111 test_expect_success "$name" '
 
 112         rm -f "$GIT_DIR"/index &&
 
 113         git checkout -f -b mybranch4 remotes/git-svn &&
 
 115         git update-index --remove -- dir/file &&
 
 118         git update-index --add -- dir &&
 
 119         git commit -m "$name" &&
 
 120         test_must_fail git svn set-tree --find-copies-harder --rmdir \
 
 121                 remotes/git-svn..mybranch4
 
 125 name='remove executable bit from a file'
 
 126 test_expect_success POSIXPERM "$name" '
 
 127         rm -f "$GIT_DIR"/index &&
 
 128         git checkout -f -b mybranch5 remotes/git-svn &&
 
 130         git update-index exec.sh &&
 
 131         git commit -m "$name" &&
 
 132         git svn set-tree --find-copies-harder --rmdir \
 
 133                 remotes/git-svn..mybranch5 &&
 
 134         svn_cmd up "$SVN_TREE" &&
 
 135         test ! -x "$SVN_TREE"/exec.sh'
 
 138 name='add executable bit back file'
 
 139 test_expect_success POSIXPERM "$name" '
 
 141         git update-index exec.sh &&
 
 142         git commit -m "$name" &&
 
 143         git svn set-tree --find-copies-harder --rmdir \
 
 144                 remotes/git-svn..mybranch5 &&
 
 145         svn_cmd up "$SVN_TREE" &&
 
 146         test -x "$SVN_TREE"/exec.sh'
 
 149 name='executable file becomes a symlink to file'
 
 150 test_expect_success SYMLINKS "$name" '
 
 152         ln -s file exec.sh &&
 
 153         git update-index exec.sh &&
 
 154         git commit -m "$name" &&
 
 155         git svn set-tree --find-copies-harder --rmdir \
 
 156                 remotes/git-svn..mybranch5 &&
 
 157         svn_cmd up "$SVN_TREE" &&
 
 158         test -h "$SVN_TREE"/exec.sh'
 
 160 name='new symlink is added to a file that was also just made executable'
 
 162 test_expect_success POSIXPERM,SYMLINKS "$name" '
 
 164         ln -s file exec-2.sh &&
 
 165         git update-index --add file exec-2.sh &&
 
 166         git commit -m "$name" &&
 
 167         git svn set-tree --find-copies-harder --rmdir \
 
 168                 remotes/git-svn..mybranch5 &&
 
 169         svn_cmd up "$SVN_TREE" &&
 
 170         test -x "$SVN_TREE"/file &&
 
 171         test -h "$SVN_TREE"/exec-2.sh'
 
 173 name='modify a symlink to become a file'
 
 174 test_expect_success POSIXPERM,SYMLINKS "$name" '
 
 175         echo git help >help &&
 
 178         git update-index exec-2.sh &&
 
 179         git commit -m "$name" &&
 
 180         git svn set-tree --find-copies-harder --rmdir \
 
 181                 remotes/git-svn..mybranch5 &&
 
 182         svn_cmd up "$SVN_TREE" &&
 
 183         test -f "$SVN_TREE"/exec-2.sh &&
 
 184         test ! -h "$SVN_TREE"/exec-2.sh &&
 
 185         test_cmp help "$SVN_TREE"/exec-2.sh'
 
 187 name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL"
 
 188 LC_ALL="$GIT_SVN_LC_ALL"
 
 190 # This test relies on the previous test, hence requires POSIXPERM,SYMLINKS
 
 191 test_expect_success UTF8,POSIXPERM,SYMLINKS "$name" "
 
 192         echo '# hello' >> exec-2.sh &&
 
 193         git update-index exec-2.sh &&
 
 194         git commit -m 'éï∏' &&
 
 195         git svn set-tree HEAD"
 
 198 name='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
 
 201 test_expect_success "$name" \
 
 202     'git svn init "$svnrepo" && git svn fetch &&
 
 203      git rev-list --pretty=raw remotes/git-svn | grep ^tree | uniq > a &&
 
 204      git rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b &&
 
 207 name='check imported tree checksums expected tree checksums'
 
 209 if test_have_prereq UTF8
 
 211         echo tree dc68b14b733e4ec85b04ab6f712340edc5dc936e > expected
 
 213 cat >> expected <<\EOF
 
 214 tree c3322890dcf74901f32d216f05c5044f670ce632
 
 215 tree d3ccd5035feafd17b030c5732e7808cc49122853
 
 216 tree d03e1630363d4881e68929d532746b20b0986b83
 
 217 tree 149d63cd5878155c846e8c55d7d8487de283f89e
 
 218 tree 312b76e4f64ce14893aeac8591eb3960b065e247
 
 219 tree 149d63cd5878155c846e8c55d7d8487de283f89e
 
 220 tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
 
 221 tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4
 
 224 test_expect_success POSIXPERM,SYMLINKS "$name" "test_cmp expected a"
 
 226 test_expect_success 'exit if remote refs are ambigious' '
 
 227         git config --add svn-remote.svn.fetch \
 
 228                 bar:refs/remotes/git-svn &&
 
 229         test_must_fail git svn migrate
 
 232 test_expect_success 'exit if init-ing a would clobber a URL' '
 
 233         svnadmin create "${PWD}/svnrepo2" &&
 
 234         svn mkdir -m "mkdir bar" "${svnrepo}2/bar" &&
 
 235         git config --unset svn-remote.svn.fetch \
 
 236                 "^bar:refs/remotes/git-svn$" &&
 
 237         test_must_fail git svn init "${svnrepo}2/bar"
 
 240 test_expect_success \
 
 241   'init allows us to connect to another directory in the same repo' '
 
 242         git svn init --minimize-url -i bar "$svnrepo/bar" &&
 
 243         git config --get svn-remote.svn.fetch \
 
 244                               "^bar:refs/remotes/bar$" &&
 
 245         git config --get svn-remote.svn.fetch \
 
 246                               "^:refs/remotes/git-svn$"
 
 249 test_expect_success 'dcommit $rev does not clobber current branch' '
 
 250         git svn fetch -i bar &&
 
 251         git checkout -b my-bar refs/remotes/bar &&
 
 254         git commit -m "change 1" &&
 
 257         git commit -m "change 2" &&
 
 258         old_head=$(git rev-parse HEAD) &&
 
 259         git svn dcommit -i bar HEAD^ &&
 
 260         test $old_head = $(git rev-parse HEAD) &&
 
 261         test refs/heads/my-bar = $(git symbolic-ref HEAD) &&
 
 262         git log refs/remotes/bar | grep "change 1" &&
 
 263         ! git log refs/remotes/bar | grep "change 2" &&
 
 264         git checkout master &&
 
 268 test_expect_success 'able to dcommit to a subdirectory' '
 
 269         git svn fetch -i bar &&
 
 270         git checkout -b my-bar refs/remotes/bar &&
 
 272         git update-index --add d &&
 
 273         git commit -m "/bar/d should be in the log" &&
 
 274         git svn dcommit -i bar &&
 
 275         test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" &&
 
 277         echo new > newdir/dir &&
 
 278         git update-index --add newdir/dir &&
 
 279         git commit -m "add a new directory" &&
 
 280         git svn dcommit -i bar &&
 
 281         test -z "$(git diff refs/heads/my-bar refs/remotes/bar)" &&
 
 282         echo foo >> newdir/dir &&
 
 283         git update-index newdir/dir &&
 
 284         git commit -m "modify a file in new directory" &&
 
 285         git svn dcommit -i bar &&
 
 286         test -z "$(git diff refs/heads/my-bar refs/remotes/bar)"
 
 289 test_expect_success 'dcommit should not fail with a touched file' '
 
 290         test_commit "commit-new-file-foo2" foo2 &&
 
 291         test-tool chmtime =-60 foo &&
 
 295 test_expect_success 'rebase should not fail with a touched file' '
 
 296         test-tool chmtime =-60 foo &&
 
 300 test_expect_success 'able to set-tree to a subdirectory' '
 
 302         git update-index d &&
 
 303         git commit -m "update /bar/d" &&
 
 304         git svn set-tree -i bar HEAD &&
 
 305         test -z "$(git diff refs/heads/my-bar refs/remotes/bar)"
 
 308 test_expect_success 'git-svn works in a bare repository' '
 
 312         GIT_DIR=. git svn init "$svnrepo" &&
 
 316 test_expect_success 'git-svn works in in a repository with a gitdir: link' '
 
 317         mkdir worktree gitdir &&
 
 319         git svn init "$svnrepo" &&
 
 320         git init --separate-git-dir ../gitdir &&
 
 322         rm -rf worktree gitdir