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