t / t5512-ls-remote.shon commit treewide: correct several "up-to-date" to "up to date" (7560f54)
   1#!/bin/sh
   2
   3test_description='git ls-remote'
   4
   5. ./test-lib.sh
   6
   7test_expect_success setup '
   8        >file &&
   9        git add file &&
  10        test_tick &&
  11        git commit -m initial &&
  12        git tag mark &&
  13        git show-ref --tags -d | sed -e "s/ /   /" >expected.tag &&
  14        (
  15                echo "$(git rev-parse HEAD)     HEAD"
  16                git show-ref -d | sed -e "s/ /  /"
  17        ) >expected.all &&
  18
  19        git remote add self "$(pwd)/.git"
  20'
  21
  22test_expect_success 'ls-remote --tags .git' '
  23        git ls-remote --tags .git >actual &&
  24        test_cmp expected.tag actual
  25'
  26
  27test_expect_success 'ls-remote .git' '
  28        git ls-remote .git >actual &&
  29        test_cmp expected.all actual
  30'
  31
  32test_expect_success 'ls-remote --tags self' '
  33        git ls-remote --tags self >actual &&
  34        test_cmp expected.tag actual
  35'
  36
  37test_expect_success 'ls-remote self' '
  38        git ls-remote self >actual &&
  39        test_cmp expected.all actual
  40'
  41
  42test_expect_success 'dies when no remote specified and no default remotes found' '
  43        test_must_fail git ls-remote
  44'
  45
  46test_expect_success 'use "origin" when no remote specified' '
  47        URL="$(pwd)/.git" &&
  48        echo "From $URL" >exp_err &&
  49
  50        git remote add origin "$URL" &&
  51        git ls-remote 2>actual_err >actual &&
  52
  53        test_cmp exp_err actual_err &&
  54        test_cmp expected.all actual
  55'
  56
  57test_expect_success 'suppress "From <url>" with -q' '
  58        git ls-remote -q 2>actual_err &&
  59        test_must_fail test_cmp exp_err actual_err
  60'
  61
  62test_expect_success 'use branch.<name>.remote if possible' '
  63        #
  64        # Test that we are indeed using branch.<name>.remote, not "origin", even
  65        # though the "origin" remote has been set.
  66        #
  67
  68        # setup a new remote to differentiate from "origin"
  69        git clone . other.git &&
  70        (
  71                cd other.git &&
  72                echo "$(git rev-parse HEAD)     HEAD"
  73                git show-ref    | sed -e "s/ /  /"
  74        ) >exp &&
  75
  76        URL="other.git" &&
  77        echo "From $URL" >exp_err &&
  78
  79        git remote add other $URL &&
  80        git config branch.master.remote other &&
  81
  82        git ls-remote 2>actual_err >actual &&
  83        test_cmp exp_err actual_err &&
  84        test_cmp exp actual
  85'
  86
  87test_expect_success 'confuses pattern as remote when no remote specified' '
  88        if test_have_prereq MINGW
  89        then
  90                # Windows does not like asterisks in pathname
  91                does_not_exist=master
  92        else
  93                does_not_exist="refs*master"
  94        fi &&
  95        cat >exp <<-EOF &&
  96        fatal: '\''$does_not_exist'\'' does not appear to be a git repository
  97        fatal: Could not read from remote repository.
  98
  99        Please make sure you have the correct access rights
 100        and the repository exists.
 101        EOF
 102        #
 103        # Do not expect "git ls-remote <pattern>" to work; ls-remote needs
 104        # <remote> if you want to feed <pattern>, just like you cannot say
 105        # fetch <branch>.
 106        # We could just as easily have used "master"; the "*" emphasizes its
 107        # role as a pattern.
 108        test_must_fail git ls-remote "$does_not_exist" >actual 2>&1 &&
 109        test_i18ncmp exp actual
 110'
 111
 112test_expect_success 'die with non-2 for wrong repository even with --exit-code' '
 113        {
 114                git ls-remote --exit-code ./no-such-repository
 115                status=$?
 116        } &&
 117        test $status != 2 && test $status != 0
 118'
 119
 120test_expect_success 'Report success even when nothing matches' '
 121        git ls-remote other.git "refs/nsn/*" >actual &&
 122        >expect &&
 123        test_cmp expect actual
 124'
 125
 126test_expect_success 'Report no-match with --exit-code' '
 127        test_expect_code 2 git ls-remote --exit-code other.git "refs/nsn/*" >actual &&
 128        >expect &&
 129        test_cmp expect actual
 130'
 131
 132test_expect_success 'Report match with --exit-code' '
 133        git ls-remote --exit-code other.git "refs/tags/*" >actual &&
 134        git ls-remote . tags/mark >expect &&
 135        test_cmp expect actual
 136'
 137
 138test_expect_success 'set up some extra tags for ref hiding' '
 139        git tag magic/one &&
 140        git tag magic/two
 141'
 142
 143for configsection in transfer uploadpack
 144do
 145        test_expect_success "Hide some refs with $configsection.hiderefs" '
 146                test_config $configsection.hiderefs refs/tags &&
 147                git ls-remote . >actual &&
 148                test_unconfig $configsection.hiderefs &&
 149                git ls-remote . |
 150                sed -e "/       refs\/tags\//d" >expect &&
 151                test_cmp expect actual
 152        '
 153
 154        test_expect_success "Override hiding of $configsection.hiderefs" '
 155                test_when_finished "test_unconfig $configsection.hiderefs" &&
 156                git config --add $configsection.hiderefs refs/tags &&
 157                git config --add $configsection.hiderefs "!refs/tags/magic" &&
 158                git config --add $configsection.hiderefs refs/tags/magic/one &&
 159                git ls-remote . >actual &&
 160                grep refs/tags/magic/two actual &&
 161                ! grep refs/tags/magic/one actual
 162        '
 163
 164done
 165
 166test_expect_success 'overrides work between mixed transfer/upload-pack hideRefs' '
 167        test_config uploadpack.hiderefs refs/tags &&
 168        test_config transfer.hiderefs "!refs/tags/magic" &&
 169        git ls-remote . >actual &&
 170        grep refs/tags/magic actual
 171'
 172
 173test_expect_success 'ls-remote --symref' '
 174        cat >expect <<-\EOF &&
 175        ref: refs/heads/master  HEAD
 176        1bd44cb9d13204b0fe1958db0082f5028a16eb3a        HEAD
 177        1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/heads/master
 178        1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/remotes/origin/HEAD
 179        1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/remotes/origin/master
 180        1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/tags/mark
 181        EOF
 182        git ls-remote --symref >actual &&
 183        test_cmp expect actual
 184'
 185
 186test_expect_success 'ls-remote with filtered symref (refname)' '
 187        cat >expect <<-\EOF &&
 188        ref: refs/heads/master  HEAD
 189        1bd44cb9d13204b0fe1958db0082f5028a16eb3a        HEAD
 190        EOF
 191        git ls-remote --symref . HEAD >actual &&
 192        test_cmp expect actual
 193'
 194
 195test_expect_failure 'ls-remote with filtered symref (--heads)' '
 196        git symbolic-ref refs/heads/foo refs/tags/mark &&
 197        cat >expect <<-\EOF &&
 198        ref: refs/tags/mark     refs/heads/foo
 199        1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/heads/foo
 200        1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/heads/master
 201        EOF
 202        git ls-remote --symref --heads . >actual &&
 203        test_cmp expect actual
 204'
 205
 206test_expect_success 'ls-remote --symref omits filtered-out matches' '
 207        cat >expect <<-\EOF &&
 208        1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/heads/foo
 209        1bd44cb9d13204b0fe1958db0082f5028a16eb3a        refs/heads/master
 210        EOF
 211        git ls-remote --symref --heads . >actual &&
 212        test_cmp expect actual &&
 213        git ls-remote --symref . "refs/heads/*" >actual &&
 214        test_cmp expect actual
 215'
 216
 217test_lazy_prereq GIT_DAEMON '
 218        test_tristate GIT_TEST_GIT_DAEMON &&
 219        test "$GIT_TEST_GIT_DAEMON" != false
 220'
 221
 222# This test spawns a daemon, so run it only if the user would be OK with
 223# testing with git-daemon.
 224test_expect_success PIPE,JGIT,GIT_DAEMON 'indicate no refs in standards-compliant empty remote' '
 225        JGIT_DAEMON_PORT=${JGIT_DAEMON_PORT-${this_test#t}} &&
 226        JGIT_DAEMON_PID= &&
 227        git init --bare empty.git &&
 228        >empty.git/git-daemon-export-ok &&
 229        mkfifo jgit_daemon_output &&
 230        {
 231                jgit daemon --port="$JGIT_DAEMON_PORT" . >jgit_daemon_output &
 232                JGIT_DAEMON_PID=$!
 233        } &&
 234        test_when_finished kill "$JGIT_DAEMON_PID" &&
 235        {
 236                read line &&
 237                case $line in
 238                Exporting*)
 239                        ;;
 240                *)
 241                        echo "Expected: Exporting" &&
 242                        false;;
 243                esac &&
 244                read line &&
 245                case $line in
 246                "Listening on"*)
 247                        ;;
 248                *)
 249                        echo "Expected: Listening on" &&
 250                        false;;
 251                esac
 252        } <jgit_daemon_output &&
 253        # --exit-code asks the command to exit with 2 when no
 254        # matching refs are found.
 255        test_expect_code 2 git ls-remote --exit-code git://localhost:$JGIT_DAEMON_PORT/empty.git
 256'
 257
 258test_expect_success 'ls-remote works outside repository' '
 259        # It is important for this repo to be inside the nongit
 260        # area, as we want a repo name that does not include
 261        # slashes (because those inhibit some of our configuration
 262        # lookups).
 263        nongit git init --bare dst.git &&
 264        nongit git ls-remote dst.git
 265'
 266
 267test_done