diff options
Diffstat (limited to 't/t5512-ls-remote.sh')
-rwxr-xr-x | t/t5512-ls-remote.sh | 131 |
1 files changed, 70 insertions, 61 deletions
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh index e3c4a48c85..f53f58895a 100755 --- a/t/t5512-ls-remote.sh +++ b/t/t5512-ls-remote.sh @@ -2,8 +2,19 @@ test_description='git ls-remote' +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME + . ./test-lib.sh +generate_references () { + for ref + do + oid=$(git rev-parse "$ref") && + printf '%s\t%s\n' "$oid" "$ref" || return 1 + done +} + test_expect_success setup ' >file && git add file && @@ -13,11 +24,11 @@ test_expect_success setup ' git tag mark1.1 && git tag mark1.2 && git tag mark1.10 && - git show-ref --tags -d | sed -e "s/ / /" >expected.tag && - ( - echo "$(git rev-parse HEAD) HEAD" && - git show-ref -d | sed -e "s/ / /" - ) >expected.all && + git show-ref --tags -d >expected.tag.raw && + sed -e "s/ / /" expected.tag.raw >expected.tag && + generate_references HEAD >expected.all && + git show-ref -d >refs && + sed -e "s/ / /" refs >>expected.all && git remote add self "$(pwd)/.git" ' @@ -43,34 +54,31 @@ test_expect_success 'ls-remote self' ' ' test_expect_success 'ls-remote --sort="version:refname" --tags self' ' - cat >expect <<-EOF && - $(git rev-parse mark) refs/tags/mark - $(git rev-parse mark1.1) refs/tags/mark1.1 - $(git rev-parse mark1.2) refs/tags/mark1.2 - $(git rev-parse mark1.10) refs/tags/mark1.10 - EOF + generate_references \ + refs/tags/mark \ + refs/tags/mark1.1 \ + refs/tags/mark1.2 \ + refs/tags/mark1.10 >expect && git ls-remote --sort="version:refname" --tags self >actual && test_cmp expect actual ' test_expect_success 'ls-remote --sort="-version:refname" --tags self' ' - cat >expect <<-EOF && - $(git rev-parse mark1.10) refs/tags/mark1.10 - $(git rev-parse mark1.2) refs/tags/mark1.2 - $(git rev-parse mark1.1) refs/tags/mark1.1 - $(git rev-parse mark) refs/tags/mark - EOF + generate_references \ + refs/tags/mark1.10 \ + refs/tags/mark1.2 \ + refs/tags/mark1.1 \ + refs/tags/mark >expect && git ls-remote --sort="-version:refname" --tags self >actual && test_cmp expect actual ' test_expect_success 'ls-remote --sort="-refname" --tags self' ' - cat >expect <<-EOF && - $(git rev-parse mark1.2) refs/tags/mark1.2 - $(git rev-parse mark1.10) refs/tags/mark1.10 - $(git rev-parse mark1.1) refs/tags/mark1.1 - $(git rev-parse mark) refs/tags/mark - EOF + generate_references \ + refs/tags/mark1.2 \ + refs/tags/mark1.10 \ + refs/tags/mark1.1 \ + refs/tags/mark >expect && git ls-remote --sort="-refname" --tags self >actual && test_cmp expect actual ' @@ -92,7 +100,7 @@ test_expect_success 'use "origin" when no remote specified' ' test_expect_success 'suppress "From <url>" with -q' ' git ls-remote -q 2>actual_err && - test_must_fail test_cmp exp_err actual_err + ! test_cmp exp_err actual_err ' test_expect_success 'use branch.<name>.remote if possible' ' @@ -113,7 +121,7 @@ test_expect_success 'use branch.<name>.remote if possible' ' echo "From $URL" >exp_err && git remote add other $URL && - git config branch.master.remote other && + git config branch.main.remote other && git ls-remote 2>actual_err >actual && test_cmp exp_err actual_err && @@ -124,9 +132,9 @@ test_expect_success 'confuses pattern as remote when no remote specified' ' if test_have_prereq MINGW then # Windows does not like asterisks in pathname - does_not_exist=master + does_not_exist=main else - does_not_exist="refs*master" + does_not_exist="refs*main" fi && cat >exp <<-EOF && fatal: '\''$does_not_exist'\'' does not appear to be a git repository @@ -139,10 +147,10 @@ test_expect_success 'confuses pattern as remote when no remote specified' ' # Do not expect "git ls-remote <pattern>" to work; ls-remote needs # <remote> if you want to feed <pattern>, just like you cannot say # fetch <branch>. - # We could just as easily have used "master"; the "*" emphasizes its + # We could just as easily have used "main"; the "*" emphasizes its # role as a pattern. test_must_fail git ls-remote "$does_not_exist" >actual 2>&1 && - test_i18ncmp exp actual + test_cmp exp actual ' test_expect_success 'die with non-2 for wrong repository even with --exit-code' ' @@ -180,8 +188,8 @@ do test_config $configsection.hiderefs refs/tags && git ls-remote . >actual && test_unconfig $configsection.hiderefs && - git ls-remote . | - sed -e "/ refs\/tags\//d" >expect && + git ls-remote . >expect.raw && + sed -e "/ refs\/tags\//d" expect.raw >expect && test_cmp expect actual ' @@ -212,63 +220,64 @@ test_expect_success 'protocol v2 supports hiderefs' ' test_expect_success 'ls-remote --symref' ' git fetch origin && - cat >expect <<-EOF && - ref: refs/heads/master HEAD - $(git rev-parse HEAD) HEAD - $(git rev-parse refs/heads/master) refs/heads/master - $(git rev-parse HEAD) refs/remotes/origin/HEAD - $(git rev-parse refs/remotes/origin/master) refs/remotes/origin/master - $(git rev-parse refs/tags/mark) refs/tags/mark - $(git rev-parse refs/tags/mark1.1) refs/tags/mark1.1 - $(git rev-parse refs/tags/mark1.10) refs/tags/mark1.10 - $(git rev-parse refs/tags/mark1.2) refs/tags/mark1.2 - EOF + echo "ref: refs/heads/main HEAD" >expect && + generate_references \ + HEAD \ + refs/heads/main >>expect && + oid=$(git rev-parse HEAD) && + echo "$oid refs/remotes/origin/HEAD" >>expect && + generate_references \ + refs/remotes/origin/main \ + refs/tags/mark \ + refs/tags/mark1.1 \ + refs/tags/mark1.10 \ + refs/tags/mark1.2 >>expect && # Protocol v2 supports sending symrefs for refs other than HEAD, so use # protocol v0 here. - GIT_TEST_PROTOCOL_VERSION= git ls-remote --symref >actual && + GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref >actual && test_cmp expect actual ' test_expect_success 'ls-remote with filtered symref (refname)' ' - cat >expect <<-\EOF && - ref: refs/heads/master HEAD - 1bd44cb9d13204b0fe1958db0082f5028a16eb3a HEAD + rev=$(git rev-parse HEAD) && + cat >expect <<-EOF && + ref: refs/heads/main HEAD + $rev HEAD EOF # Protocol v2 supports sending symrefs for refs other than HEAD, so use # protocol v0 here. - GIT_TEST_PROTOCOL_VERSION= git ls-remote --symref . HEAD >actual && + GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref . HEAD >actual && test_cmp expect actual ' test_expect_failure 'ls-remote with filtered symref (--heads)' ' git symbolic-ref refs/heads/foo refs/tags/mark && - cat >expect <<-\EOF && + cat >expect <<-EOF && ref: refs/tags/mark refs/heads/foo - 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/foo - 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/master + $rev refs/heads/foo + $rev refs/heads/main EOF # Protocol v2 supports sending symrefs for refs other than HEAD, so use # protocol v0 here. - GIT_TEST_PROTOCOL_VERSION= git ls-remote --symref --heads . >actual && + GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref --heads . >actual && test_cmp expect actual ' test_expect_success 'ls-remote --symref omits filtered-out matches' ' - cat >expect <<-\EOF && - 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/foo - 1bd44cb9d13204b0fe1958db0082f5028a16eb3a refs/heads/master + cat >expect <<-EOF && + $rev refs/heads/foo + $rev refs/heads/main EOF # Protocol v2 supports sending symrefs for refs other than HEAD, so use # protocol v0 here. - GIT_TEST_PROTOCOL_VERSION= git ls-remote --symref --heads . >actual && + GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref --heads . >actual && test_cmp expect actual && - GIT_TEST_PROTOCOL_VERSION= git ls-remote --symref . "refs/heads/*" >actual && + GIT_TEST_PROTOCOL_VERSION=0 git ls-remote --symref . "refs/heads/*" >actual && test_cmp expect actual ' test_lazy_prereq GIT_DAEMON ' - test_tristate GIT_TEST_GIT_DAEMON && - test "$GIT_TEST_GIT_DAEMON" != false + test_bool_env GIT_TEST_GIT_DAEMON true ' # This test spawns a daemon, so run it only if the user would be OK with @@ -324,10 +333,10 @@ test_expect_success 'ls-remote --sort fails gracefully outside repository' ' test_expect_success 'ls-remote patterns work with all protocol versions' ' git for-each-ref --format="%(objectname) %(refname)" \ - refs/heads/master refs/remotes/origin/master >expect && - git -c protocol.version=1 ls-remote . master >actual.v1 && + refs/heads/main refs/remotes/origin/main >expect && + git -c protocol.version=1 ls-remote . main >actual.v1 && test_cmp expect actual.v1 && - git -c protocol.version=2 ls-remote . master >actual.v2 && + git -c protocol.version=2 ls-remote . main >actual.v2 && test_cmp expect actual.v2 ' |