From 5a85a25e3528cf94a89861800eb4b939408792e3 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 25 Mar 2020 01:54:48 -0400 Subject: t5512: don't use `test_must_fail test_cmp` The test_must_fail function should only be used for git commands since we should assume that external commands work sanely. Since test_cmp() just wraps an external command, replace `test_must_fail test_cmp` with `! test_cmp`. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- t/t5512-ls-remote.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't') diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh index 04b35402c7..08b98f12b8 100755 --- a/t/t5512-ls-remote.sh +++ b/t/t5512-ls-remote.sh @@ -92,7 +92,7 @@ test_expect_success 'use "origin" when no remote specified' ' test_expect_success 'suppress "From " 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..remote if possible' ' -- cgit v1.2.3 From 3227ddc97f7e268488791161a88760dbdaf4e6a9 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Thu, 26 Mar 2020 04:27:49 -0400 Subject: t5512: stop losing git exit code in here-docs The expected references are generated using a here-doc with some inline command substitutions. If one of the `git rev-parse` invocations within the command substitutions fails, its return code is swallowed and we won't know about it. Replace these command substitutions with generate_references(), which actually reports when `git rev-parse` fails. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- t/t5512-ls-remote.sh | 64 ++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 29 deletions(-) (limited to 't') diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh index 08b98f12b8..98de7f5933 100755 --- a/t/t5512-ls-remote.sh +++ b/t/t5512-ls-remote.sh @@ -4,6 +4,14 @@ test_description='git ls-remote' . ./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 && @@ -43,34 +51,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 ' @@ -212,17 +217,18 @@ 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/master HEAD" >expect && + generate_references \ + HEAD \ + refs/heads/master >>expect && + oid=$(git rev-parse HEAD) && + echo "$oid refs/remotes/origin/HEAD" >>expect && + generate_references \ + refs/remotes/origin/master \ + 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=0 git ls-remote --symref >actual && -- cgit v1.2.3 From ef343f41239f63ac20ebe7909756c7d57c5416dd Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Thu, 26 Mar 2020 04:27:50 -0400 Subject: t5512: stop losing return codes of git commands In a pipe, only the return code of the last command is used. Thus, all other commands will have their return codes masked. Rewrite pipes so that there are no git commands upstream so that their failure is reported. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- t/t5512-ls-remote.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 't') diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh index 98de7f5933..e98c3a0174 100755 --- a/t/t5512-ls-remote.sh +++ b/t/t5512-ls-remote.sh @@ -21,11 +21,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" ' @@ -185,8 +185,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 ' -- cgit v1.2.3 From 5a828bcf1e1a3152f31c90bcf6557ba8d7b0459f Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Thu, 26 Mar 2020 04:27:51 -0400 Subject: t5550: simplify no matching line check In the 'did not use upload-pack service' test, we have a complicated song-and-dance to ensure that there are no "/git-upload-pack" lines in "$HTTPD_ROOT_PATH/access.log". Simplify this by just checking that grep returns a non-zero exit code. Helped-by: Junio C Hamano Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- t/t5550-http-fetch-dumb.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 't') diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh index b811d89cfd..bcde886b87 100755 --- a/t/t5550-http-fetch-dumb.sh +++ b/t/t5550-http-fetch-dumb.sh @@ -248,9 +248,7 @@ test_expect_success 'fetch can handle previously-fetched .idx files' ' ' test_expect_success 'did not use upload-pack service' ' - test_might_fail grep '/git-upload-pack' <"$HTTPD_ROOT_PATH"/access.log >act && - : >exp && - test_cmp exp act + ! grep "/git-upload-pack" "$HTTPD_ROOT_PATH/access.log" ' test_expect_success 'git client shows text/plain errors' ' -- cgit v1.2.3 From 85db348895ff30dd933d0a58701c97d28f65ade1 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Thu, 26 Mar 2020 04:27:52 -0400 Subject: t5607: reorder `nongit test_must_fail` In the future, we plan on only allowing `test_must_fail` to work on a restricted subset of commands, including `git`. Reorder the commands so that `nongit` comes before `test_must_fail`. This way, `test_must_fail` operates on a git command. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- t/t5607-clone-bundle.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't') diff --git a/t/t5607-clone-bundle.sh b/t/t5607-clone-bundle.sh index 9108ff6fbd..6d5a977fcb 100755 --- a/t/t5607-clone-bundle.sh +++ b/t/t5607-clone-bundle.sh @@ -16,7 +16,7 @@ test_expect_success 'setup' ' test_expect_success '"verify" needs a worktree' ' git bundle create tip.bundle -1 master && - test_must_fail nongit git bundle verify ../tip.bundle 2>err && + nongit test_must_fail git bundle verify ../tip.bundle 2>err && test_i18ngrep "need a repository" err ' -- cgit v1.2.3 From 0813dd28b948787ed61b3052d36043d9a8348edc Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Thu, 26 Mar 2020 04:27:53 -0400 Subject: t5612: don't use `test_must_fail test_cmp` The test_must_fail function should only be used for git commands since we should assume that external commands work sanely. Since test_cmp() just wraps an external command, replace `test_must_fail test_cmp` with `! test_cmp`. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- t/t5612-clone-refspec.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't') diff --git a/t/t5612-clone-refspec.sh b/t/t5612-clone-refspec.sh index e36ac01661..28373e715a 100755 --- a/t/t5612-clone-refspec.sh +++ b/t/t5612-clone-refspec.sh @@ -87,7 +87,7 @@ test_expect_success 'by default no tags will be kept updated' ' git for-each-ref refs/tags >../actual ) && git for-each-ref refs/tags >expect && - test_must_fail test_cmp expect actual && + ! test_cmp expect actual && test_line_count = 2 actual ' -- cgit v1.2.3 From 3d180973c1bc0723ab4d2225e8df3469cfaa0434 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Thu, 26 Mar 2020 04:27:54 -0400 Subject: t5612: stop losing return codes of git commands In a pipe, only the return code of the last command is used. Thus, all other commands will have their return codes masked. Rewrite pipes so that there are no git commands upstream so that their failure is reported. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- t/t5612-clone-refspec.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 't') diff --git a/t/t5612-clone-refspec.sh b/t/t5612-clone-refspec.sh index 28373e715a..e3b436d8ae 100755 --- a/t/t5612-clone-refspec.sh +++ b/t/t5612-clone-refspec.sh @@ -71,9 +71,9 @@ test_expect_success 'by default all branches will be kept updated' ' ( cd dir_all && git fetch && - git for-each-ref refs/remotes/origin | + git for-each-ref refs/remotes/origin >refs && sed -e "/HEAD$/d" \ - -e "s|/remotes/origin/|/heads/|" >../actual + -e "s|/remotes/origin/|/heads/|" refs >../actual ) && # follow both master and side git for-each-ref refs/heads >expect && @@ -104,9 +104,9 @@ test_expect_success '--single-branch while HEAD pointing at master' ' ( cd dir_master && git fetch --force && - git for-each-ref refs/remotes/origin | + git for-each-ref refs/remotes/origin >refs && sed -e "/HEAD$/d" \ - -e "s|/remotes/origin/|/heads/|" >../actual + -e "s|/remotes/origin/|/heads/|" refs >../actual ) && # only follow master git for-each-ref refs/heads/master >expect && @@ -126,9 +126,9 @@ test_expect_success '--single-branch while HEAD pointing at master and --no-tags ( cd dir_master_no_tags && git fetch && - git for-each-ref refs/remotes/origin | + git for-each-ref refs/remotes/origin >refs && sed -e "/HEAD$/d" \ - -e "s|/remotes/origin/|/heads/|" >../actual + -e "s|/remotes/origin/|/heads/|" refs >../actual ) && # only follow master git for-each-ref refs/heads/master >expect && @@ -156,9 +156,9 @@ test_expect_success '--single-branch while HEAD pointing at side' ' ( cd dir_side && git fetch && - git for-each-ref refs/remotes/origin | + git for-each-ref refs/remotes/origin >refs && sed -e "/HEAD$/d" \ - -e "s|/remotes/origin/|/heads/|" >../actual + -e "s|/remotes/origin/|/heads/|" refs >../actual ) && # only follow side git for-each-ref refs/heads/side >expect && @@ -169,9 +169,9 @@ test_expect_success '--single-branch with explicit --branch side' ' ( cd dir_side2 && git fetch && - git for-each-ref refs/remotes/origin | + git for-each-ref refs/remotes/origin >refs && sed -e "/HEAD$/d" \ - -e "s|/remotes/origin/|/heads/|" >../actual + -e "s|/remotes/origin/|/heads/|" refs >../actual ) && # only follow side git for-each-ref refs/heads/side >expect && @@ -223,9 +223,9 @@ test_expect_success '--single-branch with detached' ' ( cd dir_detached && git fetch && - git for-each-ref refs/remotes/origin | + git for-each-ref refs/remotes/origin >refs && sed -e "/HEAD$/d" \ - -e "s|/remotes/origin/|/heads/|" >../actual + -e "s|/remotes/origin/|/heads/|" refs >../actual ) && # nothing test_must_be_empty actual -- cgit v1.2.3 From ec8f87b8eb5304c7cffa8b76838ad96850cf0e55 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Thu, 26 Mar 2020 04:27:55 -0400 Subject: t5801: teach compare_refs() to accept ! Before, testing if two refs weren't equal with compare_refs() was done with `test_must_fail compare_refs`. This was wrong for two reasons. First, test_must_fail should only be used on git commands. Second, negating the error code is a little heavy-handed since in the case where one of the git invocations within compare_refs() fails, we will report success, even though it failed at an unexpected point. Teach compare_refs() to accept `!` as the first argument which would _only_ negate the test_cmp()'s return code. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano --- t/t5801-remote-helpers.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 't') diff --git a/t/t5801-remote-helpers.sh b/t/t5801-remote-helpers.sh index 121e5c6edb..0f04b6cddb 100755 --- a/t/t5801-remote-helpers.sh +++ b/t/t5801-remote-helpers.sh @@ -11,9 +11,15 @@ test_description='Test remote-helper import and export commands' PATH="$TEST_DIRECTORY/t5801:$PATH" compare_refs() { + fail= && + if test "x$1" = 'x!' + then + fail='!' && + shift + fi && git --git-dir="$1/.git" rev-parse --verify $2 >expect && git --git-dir="$3/.git" rev-parse --verify $4 >actual && - test_cmp expect actual + eval $fail test_cmp expect actual } test_expect_success 'setup repository' ' @@ -189,7 +195,7 @@ test_expect_success GPG 'push signed tag' ' git push origin signed-tag ) && compare_refs local signed-tag^{} server signed-tag^{} && - test_must_fail compare_refs local signed-tag server signed-tag + compare_refs ! local signed-tag server signed-tag ' test_expect_success GPG 'push signed tag with signed-tags capability' ' -- cgit v1.2.3