t / t5512-ls-remote.shon commit test-lib: tests skipped by GIT_SKIP_TESTS say so (ef2ac68)
   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        cat >exp <<-\EOF &&
  89        fatal: '\''refs*master'\'' does not appear to be a git repository
  90        fatal: Could not read from remote repository.
  91
  92        Please make sure you have the correct access rights
  93        and the repository exists.
  94        EOF
  95        #
  96        # Do not expect "git ls-remote <pattern>" to work; ls-remote needs
  97        # <remote> if you want to feed <pattern>, just like you cannot say
  98        # fetch <branch>.
  99        # We could just as easily have used "master"; the "*" emphasizes its
 100        # role as a pattern.
 101        test_must_fail git ls-remote refs*master >actual 2>&1 &&
 102        test_cmp exp actual
 103'
 104
 105test_expect_success 'die with non-2 for wrong repository even with --exit-code' '
 106        git ls-remote --exit-code ./no-such-repository ;# not &&
 107        status=$? &&
 108        test $status != 2 && test $status != 0
 109'
 110
 111test_expect_success 'Report success even when nothing matches' '
 112        git ls-remote other.git "refs/nsn/*" >actual &&
 113        >expect &&
 114        test_cmp expect actual
 115'
 116
 117test_expect_success 'Report no-match with --exit-code' '
 118        test_expect_code 2 git ls-remote --exit-code other.git "refs/nsn/*" >actual &&
 119        >expect &&
 120        test_cmp expect actual
 121'
 122
 123test_expect_success 'Report match with --exit-code' '
 124        git ls-remote --exit-code other.git "refs/tags/*" >actual &&
 125        git ls-remote . tags/mark >expect &&
 126        test_cmp expect actual
 127'
 128
 129for configsection in transfer uploadpack
 130do
 131        test_expect_success "Hide some refs with $configsection.hiderefs" '
 132                test_config $configsection.hiderefs refs/tags &&
 133                git ls-remote . >actual &&
 134                test_unconfig $configsection.hiderefs &&
 135                git ls-remote . |
 136                sed -e "/       refs\/tags\//d" >expect &&
 137                test_cmp expect actual
 138        '
 139done
 140
 141test_done