t / t5801-remote-helpers.shon commit git-remote-testgit: build it to run under $SHELL_PATH (709a957)
   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
  10compare_refs() {
  11        git --git-dir="$1/.git" rev-parse --verify $2 >expect &&
  12        git --git-dir="$3/.git" rev-parse --verify $4 >actual &&
  13        test_cmp expect actual
  14}
  15
  16test_expect_success 'setup repository' '
  17        git init server &&
  18        (cd server &&
  19         echo content >file &&
  20         git add file &&
  21         git commit -m one)
  22'
  23
  24test_expect_success 'cloning from local repo' '
  25        git clone "testgit::${PWD}/server" local &&
  26        test_cmp server/file local/file
  27'
  28
  29test_expect_success 'create new commit on remote' '
  30        (cd server &&
  31         echo content >>file &&
  32         git commit -a -m two)
  33'
  34
  35test_expect_success 'pulling from local repo' '
  36        (cd local && git pull) &&
  37        test_cmp server/file local/file
  38'
  39
  40test_expect_success 'pushing to local repo' '
  41        (cd local &&
  42        echo content >>file &&
  43        git commit -a -m three &&
  44        git push) &&
  45        compare_refs local HEAD server HEAD
  46'
  47
  48test_expect_success 'fetch new branch' '
  49        (cd server &&
  50         git reset --hard &&
  51         git checkout -b new &&
  52         echo content >>file &&
  53         git commit -a -m five
  54        ) &&
  55        (cd local &&
  56         git fetch origin new
  57        ) &&
  58        compare_refs server HEAD local FETCH_HEAD
  59'
  60
  61test_expect_success 'fetch multiple branches' '
  62        (cd local &&
  63         git fetch
  64        ) &&
  65        compare_refs server master local refs/remotes/origin/master &&
  66        compare_refs server new local refs/remotes/origin/new
  67'
  68
  69test_expect_success 'push when remote has extra refs' '
  70        (cd local &&
  71         git reset --hard origin/master &&
  72         echo content >>file &&
  73         git commit -a -m six &&
  74         git push
  75        ) &&
  76        compare_refs local master server master
  77'
  78
  79test_expect_success 'push new branch by name' '
  80        (cd local &&
  81         git checkout -b new-name  &&
  82         echo content >>file &&
  83         git commit -a -m seven &&
  84         git push origin new-name
  85        ) &&
  86        compare_refs local HEAD server refs/heads/new-name
  87'
  88
  89test_expect_failure 'push new branch with old:new refspec' '
  90        (cd local &&
  91         git push origin new-name:new-refspec
  92        ) &&
  93        compare_refs local HEAD server refs/heads/new-refspec
  94'
  95
  96test_expect_success 'cloning without refspec' '
  97        GIT_REMOTE_TESTGIT_REFSPEC="" \
  98        git clone "testgit::${PWD}/server" local2 2>error &&
  99        grep "This remote helper should implement refspec capability" error &&
 100        compare_refs local2 HEAD server HEAD
 101'
 102
 103test_expect_success 'pulling without refspecs' '
 104        (cd local2 &&
 105        git reset --hard &&
 106        GIT_REMOTE_TESTGIT_REFSPEC="" git pull 2>../error) &&
 107        grep "This remote helper should implement refspec capability" error &&
 108        compare_refs local2 HEAD server HEAD
 109'
 110
 111test_expect_success 'pushing without refspecs' '
 112        test_when_finished "(cd local2 && git reset --hard origin)" &&
 113        (cd local2 &&
 114        echo content >>file &&
 115        git commit -a -m ten &&
 116        GIT_REMOTE_TESTGIT_REFSPEC="" &&
 117        export GIT_REMOTE_TESTGIT_REFSPEC &&
 118        test_must_fail git push 2>../error) &&
 119        grep "remote-helper doesn.t support push; refspec needed" error
 120'
 121
 122test_expect_success 'pulling without marks' '
 123        (cd local2 &&
 124        GIT_REMOTE_TESTGIT_NO_MARKS=1 git pull) &&
 125        compare_refs local2 HEAD server HEAD
 126'
 127
 128test_expect_failure 'pushing without marks' '
 129        test_when_finished "(cd local2 && git reset --hard origin)" &&
 130        (cd local2 &&
 131        echo content >>file &&
 132        git commit -a -m twelve &&
 133        GIT_REMOTE_TESTGIT_NO_MARKS=1 git push) &&
 134        compare_refs local2 HEAD server HEAD
 135'
 136
 137test_expect_success 'push all with existing object' '
 138        (cd local &&
 139        git branch dup2 master &&
 140        git push origin --all
 141        ) &&
 142        compare_refs local dup2 server dup2
 143'
 144
 145test_expect_success 'push ref with existing object' '
 146        (cd local &&
 147        git branch dup master &&
 148        git push origin dup
 149        ) &&
 150        compare_refs local dup server dup
 151'
 152
 153test_expect_success 'push update refs' '
 154        (cd local &&
 155        git checkout -b update master &&
 156        echo update >>file &&
 157        git commit -a -m update &&
 158        git push origin update
 159        git rev-parse --verify remotes/origin/update >expect &&
 160        git rev-parse --verify testgit/origin/heads/update >actual &&
 161        test_cmp expect actual
 162        )
 163'
 164
 165test_expect_success 'proper failure checks for fetching' '
 166        (GIT_REMOTE_TESTGIT_FAILURE=1 &&
 167        export GIT_REMOTE_TESTGIT_FAILURE &&
 168        cd local &&
 169        test_must_fail git fetch 2> error &&
 170        cat error &&
 171        grep -q "Error while running fast-import" error
 172        )
 173'
 174
 175test_expect_success 'proper failure checks for pushing' '
 176        (GIT_REMOTE_TESTGIT_FAILURE=1 &&
 177        export GIT_REMOTE_TESTGIT_FAILURE &&
 178        cd local &&
 179        test_must_fail git push --all 2> error &&
 180        cat error &&
 181        grep -q "Reading from helper .git-remote-testgit. failed" error
 182        )
 183'
 184
 185test_expect_success 'push messages' '
 186        (cd local &&
 187        git checkout -b new_branch master &&
 188        echo new >>file &&
 189        git commit -a -m new &&
 190        git push origin new_branch &&
 191        git fetch origin &&
 192        echo new >>file &&
 193        git commit -a -m new &&
 194        git push origin new_branch 2> msg &&
 195        ! grep "\[new branch\]" msg
 196        )
 197'
 198
 199test_done