t / t9104-git-svn-follow-parent.shon commit untracked-cache: be defensive about missing NULs in index (c6909f9)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Eric Wong
   4#
   5
   6test_description='git svn fetching'
   7. ./lib-git-svn.sh
   8
   9test_expect_success 'initialize repo' '
  10        mkdir import &&
  11        (
  12                cd import &&
  13                mkdir -p trunk &&
  14                echo hello >trunk/readme &&
  15                svn_cmd import -m "initial" . "$svnrepo"
  16        ) &&
  17        svn_cmd co "$svnrepo" wc &&
  18        (
  19                cd wc &&
  20                echo world >>trunk/readme &&
  21                poke trunk/readme &&
  22                svn_cmd commit -m "another commit" &&
  23                svn_cmd up &&
  24                svn_cmd mv trunk thunk &&
  25                echo goodbye >>thunk/readme &&
  26                poke thunk/readme &&
  27                svn_cmd commit -m "bye now"
  28        )
  29        '
  30
  31test_expect_success 'init and fetch a moved directory' '
  32        git svn init --minimize-url -i thunk "$svnrepo"/thunk &&
  33        git svn fetch -i thunk &&
  34        test "$(git rev-parse --verify refs/remotes/thunk@2)" \
  35           = "$(git rev-parse --verify refs/remotes/thunk~1)" &&
  36        git cat-file blob refs/remotes/thunk:readme >actual &&
  37        test "$(sed -n -e "3p" actual)" = goodbye &&
  38        test -z "$(git config --get svn-remote.svn.fetch \
  39                 "^trunk:refs/remotes/thunk@2$")"
  40        '
  41
  42test_expect_success 'init and fetch from one svn-remote' '
  43        git config svn-remote.svn.url "$svnrepo" &&
  44        git config --add svn-remote.svn.fetch \
  45          trunk:refs/remotes/svn/trunk &&
  46        git config --add svn-remote.svn.fetch \
  47          thunk:refs/remotes/svn/thunk &&
  48        git svn fetch -i svn/thunk &&
  49        test "$(git rev-parse --verify refs/remotes/svn/trunk)" \
  50           = "$(git rev-parse --verify refs/remotes/svn/thunk~1)" &&
  51        git cat-file blob refs/remotes/svn/thunk:readme >actual &&
  52        test "$(sed -n -e "3p" actual)" = goodbye
  53        '
  54
  55test_expect_success 'follow deleted parent' '
  56        (svn_cmd cp -m "resurrecting trunk as junk" \
  57               "$svnrepo"/trunk@2 "$svnrepo"/junk ||
  58         svn cp -m "resurrecting trunk as junk" \
  59               -r2 "$svnrepo"/trunk "$svnrepo"/junk) &&
  60        git config --add svn-remote.svn.fetch \
  61          junk:refs/remotes/svn/junk &&
  62        git svn fetch -i svn/thunk &&
  63        git svn fetch -i svn/junk &&
  64        test -z "$(git diff svn/junk svn/trunk)" &&
  65        test "$(git merge-base svn/junk svn/trunk)" \
  66           = "$(git rev-parse svn/trunk)"
  67        '
  68
  69test_expect_success 'follow larger parent' '
  70        mkdir -p import/trunk/thunk/bump/thud &&
  71        echo hi > import/trunk/thunk/bump/thud/file &&
  72        svn import -m "import a larger parent" import "$svnrepo"/larger-parent &&
  73        svn cp -m "hi" "$svnrepo"/larger-parent "$svnrepo"/another-larger &&
  74        git svn init --minimize-url -i larger \
  75          "$svnrepo"/larger-parent/trunk/thunk/bump/thud &&
  76        git svn fetch -i larger &&
  77        git svn init --minimize-url -i larger-parent \
  78          "$svnrepo"/another-larger/trunk/thunk/bump/thud &&
  79        git svn fetch -i larger-parent &&
  80        git rev-parse --verify refs/remotes/larger &&
  81        git rev-parse --verify \
  82           refs/remotes/larger-parent &&
  83        test "$(git merge-base \
  84                 refs/remotes/larger-parent \
  85                 refs/remotes/larger)" = \
  86             "$(git rev-parse refs/remotes/larger)"
  87        '
  88
  89test_expect_success 'follow higher-level parent' '
  90        svn mkdir -m "follow higher-level parent" "$svnrepo"/blob &&
  91        svn co "$svnrepo"/blob blob &&
  92        (
  93                cd blob &&
  94                echo hi > hi &&
  95                svn add hi &&
  96                svn commit -m "hihi"
  97        ) &&
  98        svn mkdir -m "new glob at top level" "$svnrepo"/glob &&
  99        svn mv -m "move blob down a level" "$svnrepo"/blob "$svnrepo"/glob/blob &&
 100        git svn init --minimize-url -i blob "$svnrepo"/glob/blob &&
 101        git svn fetch -i blob
 102        '
 103
 104test_expect_success 'follow deleted directory' '
 105        svn_cmd mv -m "bye!" "$svnrepo"/glob/blob/hi "$svnrepo"/glob/blob/bye &&
 106        svn_cmd rm -m "remove glob" "$svnrepo"/glob &&
 107        git svn init --minimize-url -i glob "$svnrepo"/glob &&
 108        git svn fetch -i glob &&
 109        test "$(git cat-file blob refs/remotes/glob:blob/bye)" = hi &&
 110        git ls-tree refs/remotes/glob >actual &&
 111        test_line_count = 1 actual
 112        '
 113
 114# ref: r9270 of the Subversion repository: (http://svn.collab.net/repos/svn)
 115# in trunk/subversion/bindings/swig/perl
 116test_expect_success 'follow-parent avoids deleting relevant info' '
 117        mkdir -p import/trunk/subversion/bindings/swig/perl/t &&
 118        for i in a b c ; do \
 119          echo $i > import/trunk/subversion/bindings/swig/perl/$i.pm &&
 120          echo _$i > import/trunk/subversion/bindings/swig/perl/t/$i.t; \
 121        done &&
 122          echo "bad delete test" > \
 123           import/trunk/subversion/bindings/swig/perl/t/larger-parent &&
 124          echo "bad delete test 2" > \
 125           import/trunk/subversion/bindings/swig/perl/another-larger &&
 126        (
 127                cd import &&
 128                svn import -m "r9270 test" . "$svnrepo"/r9270
 129        ) &&
 130        svn_cmd co "$svnrepo"/r9270/trunk/subversion/bindings/swig/perl r9270 &&
 131        (
 132                cd r9270 &&
 133                svn mkdir native &&
 134                svn mv t native/t &&
 135                for i in a b c
 136                do
 137                        svn mv $i.pm native/$i.pm
 138                done &&
 139                echo z >>native/t/c.t &&
 140                poke native/t/c.t &&
 141                svn commit -m "reorg test"
 142        ) &&
 143        git svn init --minimize-url -i r9270-t \
 144          "$svnrepo"/r9270/trunk/subversion/bindings/swig/perl/native/t &&
 145        git svn fetch -i r9270-t &&
 146        test $(git rev-list r9270-t | wc -l) -eq 2 &&
 147        test "$(git ls-tree --name-only r9270-t~1)" = \
 148             "$(git ls-tree --name-only r9270-t)"
 149        '
 150
 151test_expect_success "track initial change if it was only made to parent" '
 152        svn_cmd cp -m "wheee!" "$svnrepo"/r9270/trunk "$svnrepo"/r9270/drunk &&
 153        git svn init --minimize-url -i r9270-d \
 154          "$svnrepo"/r9270/drunk/subversion/bindings/swig/perl/native/t &&
 155        git svn fetch -i r9270-d &&
 156        test $(git rev-list r9270-d | wc -l) -eq 3 &&
 157        test "$(git ls-tree --name-only r9270-t)" = \
 158             "$(git ls-tree --name-only r9270-d)" &&
 159        test "$(git rev-parse r9270-t)" = \
 160             "$(git rev-parse r9270-d~1)"
 161        '
 162
 163test_expect_success "follow-parent is atomic" '
 164        (
 165                cd wc &&
 166                svn_cmd up &&
 167                svn_cmd mkdir stunk &&
 168                echo "trunk stunk" > stunk/readme &&
 169                svn_cmd add stunk/readme &&
 170                svn_cmd ci -m "trunk stunk" &&
 171                echo "stunk like junk" >> stunk/readme &&
 172                svn_cmd ci -m "really stunk" &&
 173                echo "stink stank stunk" >> stunk/readme &&
 174                svn_cmd ci -m "even the grinch agrees"
 175        ) &&
 176        svn_cmd copy -m "stunk flunked" "$svnrepo"/stunk "$svnrepo"/flunk &&
 177        { svn cp -m "early stunk flunked too" \
 178                "$svnrepo"/stunk@17 "$svnrepo"/flunked ||
 179        svn_cmd cp -m "early stunk flunked too" \
 180                -r17 "$svnrepo"/stunk "$svnrepo"/flunked; } &&
 181        git svn init --minimize-url -i stunk "$svnrepo"/stunk &&
 182        git svn fetch -i stunk &&
 183        git update-ref refs/remotes/flunk@18 refs/remotes/stunk~2 &&
 184        git update-ref -d refs/remotes/stunk &&
 185        git config --unset svn-remote.svn.fetch stunk &&
 186        mkdir -p "$GIT_DIR"/svn/refs/remotes/flunk@18 &&
 187        rev_map=$(cd "$GIT_DIR"/svn/refs/remotes/stunk && ls .rev_map*) &&
 188        dd if="$GIT_DIR"/svn/refs/remotes/stunk/$rev_map \
 189           of="$GIT_DIR"/svn/refs/remotes/flunk@18/$rev_map bs=24 count=1 &&
 190        rm -rf "$GIT_DIR"/svn/refs/remotes/stunk &&
 191        git svn init --minimize-url -i flunk "$svnrepo"/flunk &&
 192        git svn fetch -i flunk &&
 193        git svn init --minimize-url -i stunk "$svnrepo"/stunk &&
 194        git svn fetch -i stunk &&
 195        git svn init --minimize-url -i flunked "$svnrepo"/flunked &&
 196        git svn fetch -i flunked &&
 197        test "$(git rev-parse --verify refs/remotes/flunk@18)" \
 198           = "$(git rev-parse --verify refs/remotes/stunk)" &&
 199        test "$(git rev-parse --verify refs/remotes/flunk~1)" \
 200           = "$(git rev-parse --verify refs/remotes/stunk)" &&
 201        test "$(git rev-parse --verify refs/remotes/flunked~1)" \
 202           = "$(git rev-parse --verify refs/remotes/stunk~1)"
 203        '
 204
 205test_expect_success "track multi-parent paths" '
 206        svn_cmd cp -m "resurrect /glob" "$svnrepo"/r9270 "$svnrepo"/glob &&
 207        git svn multi-fetch &&
 208        git cat-file commit refs/remotes/glob >actual &&
 209        grep "^parent " actual >actual2 &&
 210        test_line_count = 2 actual2
 211        '
 212
 213test_expect_success "multi-fetch continues to work" "
 214        git svn multi-fetch
 215        "
 216
 217test_expect_success "multi-fetch works off a 'clean' repository" '
 218        rm -rf "$GIT_DIR/svn" &&
 219        git for-each-ref --format="option no-deref%0adelete %(refname)" refs/remotes |
 220        git update-ref --stdin &&
 221        git reflog expire --all --expire=all &&
 222        mkdir "$GIT_DIR/svn" &&
 223        git svn multi-fetch
 224        '
 225
 226test_debug 'gitk --all &'
 227
 228test_done