t / t9107-git-svn-migrate.shon commit Teach "apply --index-info" to handle rename patches (18cdf80)
   1#!/bin/sh
   2# Copyright (c) 2006 Eric Wong
   3test_description='git svn metadata migrations from previous versions'
   4. ./lib-git-svn.sh
   5
   6test_expect_success 'setup old-looking metadata' '
   7        cp "$GIT_DIR"/config "$GIT_DIR"/config-old-git-svn &&
   8        mkdir import &&
   9        cd import &&
  10                for i in trunk branches/a branches/b \
  11                         tags/0.1 tags/0.2 tags/0.3; do
  12                        mkdir -p $i && \
  13                        echo hello >> $i/README || exit 1
  14                done && \
  15                svn_cmd import -m test . "$svnrepo"
  16                cd .. &&
  17        git svn init "$svnrepo" &&
  18        git svn fetch &&
  19        rm -rf "$GIT_DIR"/svn &&
  20        git update-ref refs/heads/git-svn-HEAD refs/${remotes_git_svn} &&
  21        git update-ref refs/heads/svn-HEAD refs/${remotes_git_svn} &&
  22        git update-ref -d refs/${remotes_git_svn} refs/${remotes_git_svn}
  23        '
  24
  25head=`git rev-parse --verify refs/heads/git-svn-HEAD^0`
  26test_expect_success 'git-svn-HEAD is a real HEAD' "test -n '$head'"
  27
  28test_expect_success 'initialize old-style (v0) git svn layout' '
  29        mkdir -p "$GIT_DIR"/git-svn/info "$GIT_DIR"/svn/info &&
  30        echo "$svnrepo" > "$GIT_DIR"/git-svn/info/url &&
  31        echo "$svnrepo" > "$GIT_DIR"/svn/info/url &&
  32        git svn migrate &&
  33        ! test -d "$GIT_DIR"/git svn &&
  34        git rev-parse --verify refs/${remotes_git_svn}^0 &&
  35        git rev-parse --verify refs/remotes/svn^0 &&
  36        test "$(git config --get svn-remote.svn.url)" = "$svnrepo" &&
  37        test `git config --get svn-remote.svn.fetch` = \
  38             ":refs/${remotes_git_svn}"
  39        '
  40
  41test_expect_success 'initialize a multi-repository repo' '
  42        git svn init "$svnrepo" -T trunk -t tags -b branches &&
  43        git config --get-all svn-remote.svn.fetch > fetch.out &&
  44        grep "^trunk:refs/remotes/trunk$" fetch.out &&
  45        test -n "`git config --get svn-remote.svn.branches \
  46                    "^branches/\*:refs/remotes/\*$"`" &&
  47        test -n "`git config --get svn-remote.svn.tags \
  48                    "^tags/\*:refs/remotes/tags/\*$"`" &&
  49        git config --unset svn-remote.svn.branches \
  50                                "^branches/\*:refs/remotes/\*$" &&
  51        git config --unset svn-remote.svn.tags \
  52                                "^tags/\*:refs/remotes/tags/\*$" &&
  53        git config --add svn-remote.svn.fetch "branches/a:refs/remotes/a" &&
  54        git config --add svn-remote.svn.fetch "branches/b:refs/remotes/b" &&
  55        for i in tags/0.1 tags/0.2 tags/0.3; do
  56                git config --add svn-remote.svn.fetch \
  57                                 $i:refs/remotes/$i || exit 1; done &&
  58        git config --get-all svn-remote.svn.fetch > fetch.out &&
  59        grep "^trunk:refs/remotes/trunk$" fetch.out &&
  60        grep "^branches/a:refs/remotes/a$" fetch.out &&
  61        grep "^branches/b:refs/remotes/b$" fetch.out &&
  62        grep "^tags/0\.1:refs/remotes/tags/0\.1$" fetch.out &&
  63        grep "^tags/0\.2:refs/remotes/tags/0\.2$" fetch.out &&
  64        grep "^tags/0\.3:refs/remotes/tags/0\.3$" fetch.out &&
  65        grep "^:refs/${remotes_git_svn}" fetch.out
  66        '
  67
  68# refs should all be different, but the trees should all be the same:
  69test_expect_success 'multi-fetch works on partial urls + paths' "
  70        git svn multi-fetch &&
  71        for i in trunk a b tags/0.1 tags/0.2 tags/0.3; do
  72                git rev-parse --verify refs/remotes/\$i^0 >> refs.out || exit 1;
  73            done &&
  74        test -z \"\`sort < refs.out | uniq -d\`\" &&
  75        for i in trunk a b tags/0.1 tags/0.2 tags/0.3; do
  76          for j in trunk a b tags/0.1 tags/0.2 tags/0.3; do
  77                if test \$j != \$i; then continue; fi
  78            test -z \"\`git diff refs/remotes/\$i \
  79                                 refs/remotes/\$j\`\" ||exit 1; done; done
  80        "
  81
  82test_expect_success 'migrate --minimize on old inited layout' '
  83        git config --unset-all svn-remote.svn.fetch &&
  84        git config --unset-all svn-remote.svn.url &&
  85        rm -rf "$GIT_DIR"/svn &&
  86        for i in `cat fetch.out`; do
  87                path=`expr $i : "\([^:]*\):.*$"`
  88                ref=`expr $i : "[^:]*:\(refs/remotes/.*\)$"`
  89                if test -z "$ref"; then continue; fi
  90                if test -n "$path"; then path="/$path"; fi
  91                ( mkdir -p "$GIT_DIR"/svn/$ref/info/ &&
  92                echo "$svnrepo"$path > "$GIT_DIR"/svn/$ref/info/url ) || exit 1;
  93        done &&
  94        git svn migrate --minimize &&
  95        test -z "`git config -l | grep "^svn-remote\.git-svn\."`" &&
  96        git config --get-all svn-remote.svn.fetch > fetch.out &&
  97        grep "^trunk:refs/remotes/trunk$" fetch.out &&
  98        grep "^branches/a:refs/remotes/a$" fetch.out &&
  99        grep "^branches/b:refs/remotes/b$" fetch.out &&
 100        grep "^tags/0\.1:refs/remotes/tags/0\.1$" fetch.out &&
 101        grep "^tags/0\.2:refs/remotes/tags/0\.2$" fetch.out &&
 102        grep "^tags/0\.3:refs/remotes/tags/0\.3$" fetch.out &&
 103        grep "^:refs/${remotes_git_svn}" fetch.out
 104        '
 105
 106test_expect_success  ".rev_db auto-converted to .rev_map.UUID" '
 107        git svn fetch -i trunk &&
 108        test -z "$(ls "$GIT_DIR"/svn/refs/remotes/trunk/.rev_db.* 2>/dev/null)" &&
 109        expect="$(ls "$GIT_DIR"/svn/refs/remotes/trunk/.rev_map.*)" &&
 110        test -n "$expect" &&
 111        rev_db="$(echo $expect | sed -e "s,_map,_db,")" &&
 112        convert_to_rev_db "$expect" "$rev_db" &&
 113        rm -f "$expect" &&
 114        test -f "$rev_db" &&
 115        git svn fetch -i trunk &&
 116        test -z "$(ls "$GIT_DIR"/svn/refs/remotes/trunk/.rev_db.* 2>/dev/null)" &&
 117        test ! -e "$GIT_DIR"/svn/refs/remotes/trunk/.rev_db &&
 118        test -f "$expect"
 119        '
 120
 121test_done