t / t5801-remote-helpers.shon commit Add new simplified git-remote-testgit (fc407f9)
   1#!/bin/sh
   2#
   3# Copyright (c) 2010 Sverre Rabbelier
   4#
   5
   6test_description='Test remote-helper import and export commands'
   7
   8. ./test-lib.sh
   9
  10if ! type "${BASH-bash}" >/dev/null 2>&1; then
  11        skip_all='skipping remote-testgit tests, bash not available'
  12        test_done
  13fi
  14
  15compare_refs() {
  16        git --git-dir="$1/.git" rev-parse --verify $2 >expect &&
  17        git --git-dir="$3/.git" rev-parse --verify $4 >actual &&
  18        test_cmp expect actual
  19}
  20
  21test_expect_success 'setup repository' '
  22        git init --bare server/.git &&
  23        git clone server public &&
  24        (cd public &&
  25         echo content >file &&
  26         git add file &&
  27         git commit -m one &&
  28         git push origin master)
  29'
  30
  31test_expect_success 'cloning from local repo' '
  32        git clone "testgit::${PWD}/server" localclone &&
  33        test_cmp public/file localclone/file
  34'
  35
  36test_expect_success 'cloning from remote repo' '
  37        git clone "testgit::file://${PWD}/server" clone &&
  38        test_cmp public/file clone/file
  39'
  40
  41test_expect_success 'create new commit on remote' '
  42        (cd public &&
  43         echo content >>file &&
  44         git commit -a -m two &&
  45         git push)
  46'
  47
  48test_expect_success 'pulling from local repo' '
  49        (cd localclone && git pull) &&
  50        test_cmp public/file localclone/file
  51'
  52
  53test_expect_success 'pulling from remote remote' '
  54        (cd clone && git pull) &&
  55        test_cmp public/file clone/file
  56'
  57
  58test_expect_success 'pushing to local repo' '
  59        (cd localclone &&
  60        echo content >>file &&
  61        git commit -a -m three &&
  62        git push) &&
  63        compare_refs localclone HEAD server HEAD
  64'
  65
  66# Generally, skip this test.  It demonstrates a now-fixed race in
  67# git-remote-testgit, but is too slow to leave in for general use.
  68: test_expect_success 'racily pushing to local repo' '
  69        test_when_finished "rm -rf server2 localclone2" &&
  70        cp -R server server2 &&
  71        git clone "testgit::${PWD}/server2" localclone2 &&
  72        (cd localclone2 &&
  73        echo content >>file &&
  74        git commit -a -m three &&
  75        GIT_REMOTE_TESTGIT_SLEEPY=2 git push) &&
  76        compare_refs localclone2 HEAD server2 HEAD
  77'
  78
  79test_expect_success 'synch with changes from localclone' '
  80        (cd clone &&
  81         git pull)
  82'
  83
  84test_expect_success 'pushing remote local repo' '
  85        (cd clone &&
  86        echo content >>file &&
  87        git commit -a -m four &&
  88        git push) &&
  89        compare_refs clone HEAD server HEAD
  90'
  91
  92test_expect_success 'fetch new branch' '
  93        (cd public &&
  94         git checkout -b new &&
  95         echo content >>file &&
  96         git commit -a -m five &&
  97         git push origin new
  98        ) &&
  99        (cd localclone &&
 100         git fetch origin new
 101        ) &&
 102        compare_refs public HEAD localclone FETCH_HEAD
 103'
 104
 105test_expect_success 'fetch multiple branches' '
 106        (cd localclone &&
 107         git fetch
 108        ) &&
 109        compare_refs server master localclone refs/remotes/origin/master &&
 110        compare_refs server new localclone refs/remotes/origin/new
 111'
 112
 113test_expect_success 'push when remote has extra refs' '
 114        (cd clone &&
 115         echo content >>file &&
 116         git commit -a -m six &&
 117         git push
 118        ) &&
 119        compare_refs clone master server master
 120'
 121
 122test_expect_success 'push new branch by name' '
 123        (cd clone &&
 124         git checkout -b new-name  &&
 125         echo content >>file &&
 126         git commit -a -m seven &&
 127         git push origin new-name
 128        ) &&
 129        compare_refs clone HEAD server refs/heads/new-name
 130'
 131
 132test_expect_failure 'push new branch with old:new refspec' '
 133        (cd clone &&
 134         git push origin new-name:new-refspec
 135        ) &&
 136        compare_refs clone HEAD server refs/heads/new-refspec
 137'
 138
 139test_done