{"thread":{"id":"60724","subject":"[PATCH 0/2] completion: silence pseudo-ref existence check","startedAt":"2024-01-11T10:41:54Z","lastAt":"2024-01-15T10:36:19Z","messageCount":18,"participants":["Patrick Steinhardt","Junio C Hamano","Johannes Schindelin","Jeff King","SZEDER Gábor"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"486617","messageId":"cover.1704969119.git.ps@pks.im","threadId":"60724","inReplyTo":null,"subject":"[PATCH 0/2] completion: silence pseudo-ref existence check","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-01-11T10:41:49Z","receivedAt":"2024-01-11T10:41:54Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Hi,\n\nI recently noticed that the Bash completion script started to output\nobject IDs in repositories which use the \"reftable\" backend when\ncompleting certain commands. This patch series fixes this issue.\n\nPatrick\n\nPatrick Steinhardt (2):\n  t9902: verify that completion does not print anything\n  completion: silence pseudoref existence check\n\n contrib/completion/git-completion.bash |  2 +-\n t/t9902-completion.sh                  | 14 ++++++++++++--\n 2 files changed, 13 insertions(+), 3 deletions(-)\n\n-- \n2.43.GIT\n\n"},{"id":"486618","messageId":"73406ca9c8f38ac2ad8f0e32d6d81f1566a6b4d1.1704969119.git.ps@pks.im","threadId":"60724","inReplyTo":"cover.1704969119.git.ps@pks.im","subject":"[PATCH 1/2] t9902: verify that completion does not print anything","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-01-11T10:41:54Z","receivedAt":"2024-01-11T10:41:58Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The Bash completion script must not print anything to either stdout or\nstderr. Instead, it is only expected to populate certain variables.\nTighten our `test_completion ()` test helper to verify this requirement.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n t/t9902-completion.sh | 6 ++++--\n 1 file changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex aa9a614de3..78cb93bea7 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -87,9 +87,11 @@ test_completion ()\n \telse\n \t\tsed -e 's/Z$//' |sort >expected\n \tfi &&\n-\trun_completion \"$1\" &&\n+\trun_completion \"$1\" >\"$TRASH_DIRECTORY\"/output 2>&1 &&\n \tsort out >out_sorted &&\n-\ttest_cmp expected out_sorted\n+\ttest_cmp expected out_sorted &&\n+\ttest_must_be_empty \"$TRASH_DIRECTORY\"/output &&\n+\trm \"$TRASH_DIRECTORY\"/output\n }\n \n # Test __gitcomp.\n-- \n2.43.GIT\n\n"},{"id":"486619","messageId":"24563975fca8df6ae73917e9ee3534933d47c429.1704969119.git.ps@pks.im","threadId":"60724","inReplyTo":"cover.1704969119.git.ps@pks.im","subject":"[PATCH 2/2] completion: silence pseudoref existence check","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-01-11T10:41:59Z","receivedAt":"2024-01-11T10:42:02Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"In 44dbb3bf29 (completion: support pseudoref existence checks for\nreftables, 2023-12-19), we have extended the Bash completion script to\nsupport future ref backends better by using git-rev-parse(1) to check\nfor pseudo-ref existence. This conversion has introduced a bug, because\neven though we pass `--quiet` to git-rev-parse(1) it would still output\nthe resolved object ID of the ref in question if it exists.\n\nFix this by redirecting its stdout to `/dev/null` and add a test that\ncatches this behaviour. Note that the test passes even without the fix\nfor the \"files\" backend because we parse pseudo refs via the filesystem\ndirectly in that case. But the test will fail with the \"reftable\"\nbackend.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n contrib/completion/git-completion.bash | 2 +-\n t/t9902-completion.sh                  | 8 ++++++++\n 2 files changed, 9 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 8c40ade494..8872192e2b 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -146,7 +146,7 @@ __git_pseudoref_exists ()\n \tif __git_eread \"$__git_repo_path/HEAD\" head; then\n \t\tb=\"${head#ref: }\"\n \t\tif [ \"$b\" == \"refs/heads/.invalid\" ]; then\n-\t\t\t__git -C \"$__git_repo_path\" rev-parse --verify --quiet \"$ref\" 2>/dev/null\n+\t\t\t__git -C \"$__git_repo_path\" rev-parse --verify --quiet \"$ref\" >/dev/null 2>&1\n \t\t\treturn $?\n \t\tfi\n \tfi\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 78cb93bea7..b14ae4de14 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1927,6 +1927,14 @@ test_expect_success 'git checkout - --orphan with branch already provided comple\n \tEOF\n '\n \n+test_expect_success 'git reset completes modified files' '\n+\ttest_commit A a.file &&\n+\techo B >a.file &&\n+\ttest_completion \"git restore a.\" <<-\\EOF\n+\ta.file\n+\tEOF\n+'\n+\n test_expect_success 'teardown after ref completion' '\n \tgit branch -d matching-branch &&\n \tgit tag -d matching-tag &&\n-- \n2.43.GIT\n\n"},{"id":"486655","messageId":"xmqqil3zfwaj.fsf@gitster.g","threadId":"60724","inReplyTo":"73406ca9c8f38ac2ad8f0e32d6d81f1566a6b4d1.1704969119.git.ps@pks.im","subject":"Re: [PATCH 1/2] t9902: verify that completion does not print anything","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-01-11T20:29:56Z","receivedAt":"2024-01-11T20:30:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> The Bash completion script must not print anything to either stdout or\n> stderr. Instead, it is only expected to populate certain variables.\n> Tighten our `test_completion ()` test helper to verify this requirement.\n>\n> Signed-off-by: Patrick Steinhardt <ps@pks.im>\n> ---\n>  t/t9902-completion.sh | 6 ++++--\n>  1 file changed, 4 insertions(+), 2 deletions(-)\n>\n> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\n> index aa9a614de3..78cb93bea7 100755\n> --- a/t/t9902-completion.sh\n> +++ b/t/t9902-completion.sh\n> @@ -87,9 +87,11 @@ test_completion ()\n>  \telse\n>  \t\tsed -e 's/Z$//' |sort >expected\n>  \tfi &&\n> -\trun_completion \"$1\" &&\n> +\trun_completion \"$1\" >\"$TRASH_DIRECTORY\"/output 2>&1 &&\n\nOK, there is a call to test_completion after cd and this is a\nreasonable way to make sure we write to a known location.\n\nI would have done the \"run_completion should be totally silent\"\ncheck immediately after this line, as they logically are more\nrelated to each other than to the two lines that implement \"the\n'out' file when sorted must match the expectation we just prepared\",\nbut that is not a huge deal.\n\nThe filename \"output\" is something that may tempt folks who add more\ntests to this file to use for their own purpose; because we use it\nonly three times locally here, it might be safer to give it a bit\nmore specific name, e.g., \"run-completion-output\" or something.\n\n\n\n>  \tsort out >out_sorted &&\n> -\ttest_cmp expected out_sorted\n> +\ttest_cmp expected out_sorted &&\n> +\ttest_must_be_empty \"$TRASH_DIRECTORY\"/output &&\n> +\trm \"$TRASH_DIRECTORY\"/output\n>  }\n>  \n>  # Test __gitcomp.\n"},{"id":"486657","messageId":"xmqqedenfuq7.fsf@gitster.g","threadId":"60724","inReplyTo":"24563975fca8df6ae73917e9ee3534933d47c429.1704969119.git.ps@pks.im","subject":"Re: [PATCH 2/2] completion: silence pseudoref existence check","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-01-11T21:03:44Z","receivedAt":"2024-01-11T21:03:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> In 44dbb3bf29 (completion: support pseudoref existence checks for\n> reftables, 2023-12-19), we have extended the Bash completion script to\n> support future ref backends better by using git-rev-parse(1) to check\n> for pseudo-ref existence. This conversion has introduced a bug, because\n> even though we pass `--quiet` to git-rev-parse(1) it would still output\n> the resolved object ID of the ref in question if it exists.\n>\n> Fix this by redirecting its stdout to `/dev/null` and add a test that\n> catches this behaviour. Note that the test passes even without the fix\n> for the \"files\" backend because we parse pseudo refs via the filesystem\n> directly in that case. But the test will fail with the \"reftable\"\n> backend.\n\nThanks.  Will queue.\n"},{"id":"486703","messageId":"d978494d-6c48-5923-4745-c42a39e1187a@gmx.de","threadId":"60724","inReplyTo":"73406ca9c8f38ac2ad8f0e32d6d81f1566a6b4d1.1704969119.git.ps@pks.im","subject":"Re: [PATCH 1/2] t9902: verify that completion does not print anything","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2024-01-12T10:08:21Z","receivedAt":"2024-01-12T10:08:27Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Patrick,\n\nOn Thu, 11 Jan 2024, Patrick Steinhardt wrote:\n\n> The Bash completion script must not print anything to either stdout or\n> stderr. Instead, it is only expected to populate certain variables.\n> Tighten our `test_completion ()` test helper to verify this requirement.\n>\n> Signed-off-by: Patrick Steinhardt <ps@pks.im>\n> ---\n>  t/t9902-completion.sh | 6 ++++--\n>  1 file changed, 4 insertions(+), 2 deletions(-)\n>\n> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\n> index aa9a614de3..78cb93bea7 100755\n> --- a/t/t9902-completion.sh\n> +++ b/t/t9902-completion.sh\n> @@ -87,9 +87,11 @@ test_completion ()\n>  \telse\n>  \t\tsed -e 's/Z$//' |sort >expected\n>  \tfi &&\n> -\trun_completion \"$1\" &&\n> +\trun_completion \"$1\" >\"$TRASH_DIRECTORY\"/output 2>&1 &&\n>  \tsort out >out_sorted &&\n> -\ttest_cmp expected out_sorted\n> +\ttest_cmp expected out_sorted &&\n> +\ttest_must_be_empty \"$TRASH_DIRECTORY\"/output &&\n\nIt seems that this fails CI on macOS, most likely because we're running\nwith `set -x` and that output somehow ends up in `output`, see e.g. here:\nhttps://github.com/git/git/actions/runs/7496790359/job/20409405194#step:4:1880\n\n  [...]\n  ++ test_completion 'git switch '\n  ++ test 1 -gt 1\n  ++ sed -e 's/Z$//'\n  ++ sort\n  ++ run_completion 'git switch '\n  ++ sort out\n  ++ test_cmp expected out_sorted\n  ++ test 2 -ne 2\n  ++ eval 'diff -u' '\"$@\"'\n  +++ diff -u expected out_sorted\n  ++ test_must_be_empty '/Users/runner/work/git/git/t/trash directory.t9902-completion/output'\n  ++ test 1 -ne 1\n  ++ test_path_is_file '/Users/runner/work/git/git/t/trash directory.t9902-completion/output'\n  ++ test 1 -ne 1\n  ++ test -f '/Users/runner/work/git/git/t/trash directory.t9902-completion/output'\n  ++ test -s '/Users/runner/work/git/git/t/trash directory.t9902-completion/output'\n  ++ echo ''\\''/Users/runner/work/git/git/t/trash directory.t9902-completion/output'\\'' is not empty, it contains:'\n  '/Users/runner/work/git/git/t/trash directory.t9902-completion/output' is not empty, it contains:\n  ++ cat '/Users/runner/work/git/git/t/trash directory.t9902-completion/output'\n  ++ local -a COMPREPLY _words\n  ++ local _cword\n  [...]\n\nMaybe this is running in Dash and therefore `BASH_XTRACEFD=4` in\n`test-lib.sh` has not the intended effect?\n\nCiao,\nJohannes\n"},{"id":"486706","messageId":"ZaEZar9OTVgfkD9r@framework","threadId":"60724","inReplyTo":"d978494d-6c48-5923-4745-c42a39e1187a@gmx.de","subject":"Re: [PATCH 1/2] t9902: verify that completion does not print anything","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-01-12T10:50:18Z","receivedAt":"2024-01-12T10:50:25Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, Jan 12, 2024 at 11:08:21AM +0100, Johannes Schindelin wrote:\n> Hi Patrick,\n> \n> On Thu, 11 Jan 2024, Patrick Steinhardt wrote:\n> \n> > The Bash completion script must not print anything to either stdout or\n> > stderr. Instead, it is only expected to populate certain variables.\n> > Tighten our `test_completion ()` test helper to verify this requirement.\n> >\n> > Signed-off-by: Patrick Steinhardt <ps@pks.im>\n> > ---\n> >  t/t9902-completion.sh | 6 ++++--\n> >  1 file changed, 4 insertions(+), 2 deletions(-)\n> >\n> > diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\n> > index aa9a614de3..78cb93bea7 100755\n> > --- a/t/t9902-completion.sh\n> > +++ b/t/t9902-completion.sh\n> > @@ -87,9 +87,11 @@ test_completion ()\n> >  \telse\n> >  \t\tsed -e 's/Z$//' |sort >expected\n> >  \tfi &&\n> > -\trun_completion \"$1\" &&\n> > +\trun_completion \"$1\" >\"$TRASH_DIRECTORY\"/output 2>&1 &&\n> >  \tsort out >out_sorted &&\n> > -\ttest_cmp expected out_sorted\n> > +\ttest_cmp expected out_sorted &&\n> > +\ttest_must_be_empty \"$TRASH_DIRECTORY\"/output &&\n> \n> It seems that this fails CI on macOS, most likely because we're running\n> with `set -x` and that output somehow ends up in `output`, see e.g. here:\n> https://github.com/git/git/actions/runs/7496790359/job/20409405194#step:4:1880\n> \n>   [...]\n>   ++ test_completion 'git switch '\n>   ++ test 1 -gt 1\n>   ++ sed -e 's/Z$//'\n>   ++ sort\n>   ++ run_completion 'git switch '\n>   ++ sort out\n>   ++ test_cmp expected out_sorted\n>   ++ test 2 -ne 2\n>   ++ eval 'diff -u' '\"$@\"'\n>   +++ diff -u expected out_sorted\n>   ++ test_must_be_empty '/Users/runner/work/git/git/t/trash directory.t9902-completion/output'\n>   ++ test 1 -ne 1\n>   ++ test_path_is_file '/Users/runner/work/git/git/t/trash directory.t9902-completion/output'\n>   ++ test 1 -ne 1\n>   ++ test -f '/Users/runner/work/git/git/t/trash directory.t9902-completion/output'\n>   ++ test -s '/Users/runner/work/git/git/t/trash directory.t9902-completion/output'\n>   ++ echo ''\\''/Users/runner/work/git/git/t/trash directory.t9902-completion/output'\\'' is not empty, it contains:'\n>   '/Users/runner/work/git/git/t/trash directory.t9902-completion/output' is not empty, it contains:\n>   ++ cat '/Users/runner/work/git/git/t/trash directory.t9902-completion/output'\n>   ++ local -a COMPREPLY _words\n>   ++ local _cword\n>   [...]\n> \n> Maybe this is running in Dash and therefore `BASH_XTRACEFD=4` in\n> `test-lib.sh` has not the intended effect?\n\nMeh, thanks for the heads up. Another test gap in GitLab CI which I'm\ngoing to address soon via a new macOS job.\n\nIn any case, Dash indeed does not honor the above envvar. I also could\nnot find any alternate solutions to redirect the tracing output. So for\nall I can see there are a few ways to handle this:\n\n  - `set -x` and then restore the previous value after having called\n    `run_completion`.\n\n  - Filter the output so that any line starting with \"${PS4}\" gets\n    removed. \n\n  - Don't test for this bug.\n\nNot sure which way to go, but the first alternative feels a bit more\nsensible to me. It does remove the ability to see what's going on in the\ncompletion script though in case one wants to debug it.\n\nI'll reroll this patch series early next week.\n\nPatrick\n"},{"id":"486709","messageId":"27edf445-d7fa-7aaf-7682-4ecc03366ef0@gmx.de","threadId":"60724","inReplyTo":"ZaEZar9OTVgfkD9r@framework","subject":"Re: [PATCH 1/2] t9902: verify that completion does not print anything","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2024-01-12T13:12:43Z","receivedAt":"2024-01-12T13:12:50Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Patrick,\n\nOn Fri, 12 Jan 2024, Patrick Steinhardt wrote:\n\n> On Fri, Jan 12, 2024 at 11:08:21AM +0100, Johannes Schindelin wrote:\n>\n> > On Thu, 11 Jan 2024, Patrick Steinhardt wrote:\n> >\n> > > The Bash completion script must not print anything to either stdout or\n> > > stderr. Instead, it is only expected to populate certain variables.\n> > > Tighten our `test_completion ()` test helper to verify this requirement.\n> > >\n> > > Signed-off-by: Patrick Steinhardt <ps@pks.im>\n> > > ---\n> > >  t/t9902-completion.sh | 6 ++++--\n> > >  1 file changed, 4 insertions(+), 2 deletions(-)\n> > >\n> > > diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\n> > > index aa9a614de3..78cb93bea7 100755\n> > > --- a/t/t9902-completion.sh\n> > > +++ b/t/t9902-completion.sh\n> > > @@ -87,9 +87,11 @@ test_completion ()\n> > >  \telse\n> > >  \t\tsed -e 's/Z$//' |sort >expected\n> > >  \tfi &&\n> > > -\trun_completion \"$1\" &&\n> > > +\trun_completion \"$1\" >\"$TRASH_DIRECTORY\"/output 2>&1 &&\n> > >  \tsort out >out_sorted &&\n> > > -\ttest_cmp expected out_sorted\n> > > +\ttest_cmp expected out_sorted &&\n> > > +\ttest_must_be_empty \"$TRASH_DIRECTORY\"/output &&\n> >\n> > It seems that this fails CI on macOS, most likely because we're running\n> > with `set -x` and that output somehow ends up in `output`, see e.g. here:\n> > https://github.com/git/git/actions/runs/7496790359/job/20409405194#step:4:1880\n> >\n> >   [...]\n> >   ++ test_completion 'git switch '\n> >   ++ test 1 -gt 1\n> >   ++ sed -e 's/Z$//'\n> >   ++ sort\n> >   ++ run_completion 'git switch '\n> >   ++ sort out\n> >   ++ test_cmp expected out_sorted\n> >   ++ test 2 -ne 2\n> >   ++ eval 'diff -u' '\"$@\"'\n> >   +++ diff -u expected out_sorted\n> >   ++ test_must_be_empty '/Users/runner/work/git/git/t/trash directory.t9902-completion/output'\n> >   ++ test 1 -ne 1\n> >   ++ test_path_is_file '/Users/runner/work/git/git/t/trash directory.t9902-completion/output'\n> >   ++ test 1 -ne 1\n> >   ++ test -f '/Users/runner/work/git/git/t/trash directory.t9902-completion/output'\n> >   ++ test -s '/Users/runner/work/git/git/t/trash directory.t9902-completion/output'\n> >   ++ echo ''\\''/Users/runner/work/git/git/t/trash directory.t9902-completion/output'\\'' is not empty, it contains:'\n> >   '/Users/runner/work/git/git/t/trash directory.t9902-completion/output' is not empty, it contains:\n> >   ++ cat '/Users/runner/work/git/git/t/trash directory.t9902-completion/output'\n> >   ++ local -a COMPREPLY _words\n> >   ++ local _cword\n> >   [...]\n> >\n> > Maybe this is running in Dash and therefore `BASH_XTRACEFD=4` in\n> > `test-lib.sh` has not the intended effect?\n>\n> Meh, thanks for the heads up. Another test gap in GitLab CI which I'm\n> going to address soon via a new macOS job.\n>\n> In any case, Dash indeed does not honor the above envvar.\n\nHmm. I had a closer look and now I am thoroughly confused. In\n`t/lib-bash.exe`, we make sure that this test is run in Bash. And indeed,\nwhen I call\n\n  BASH=1 POSIXLY_CORRECT=1 TEST_SHELL_PATH=/bin/dash dash t9902-completion.sh -iVx\n\nI am greeted by this error message:\n\n  git-completion.bash: Syntax error: \"(\" unexpected (expecting \"fi\")\n\nSo something else must be going on here.\n\n> I also could not find any alternate solutions to redirect the tracing\n> output. So for all I can see there are a few ways to handle this:\n>\n>   - `set -x` and then restore the previous value after having called\n>     `run_completion`.\n>\n>   - Filter the output so that any line starting with \"${PS4}\" gets\n>     removed.\n>\n>   - Don't test for this bug.\n>\n> Not sure which way to go, but the first alternative feels a bit more\n> sensible to me. It does remove the ability to see what's going on in the\n> completion script though in case one wants to debug it.\n\nPersonally, I would go for option 2, filtering out the xtrace output. This\nhere seems to work:\n\n-- snip --\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex b14ae4de14e..23cd1cd9508 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -87,11 +87,14 @@ test_completion ()\n \telse\n \t\tsed -e 's/Z$//' |sort >expected\n \tfi &&\n+\tPS4=+ &&\n \trun_completion \"$1\" >\"$TRASH_DIRECTORY\"/output 2>&1 &&\n+\tsed \"/^+/{:1;s/'[^']*'//g;/'/{N;b1};d}\" \\\n+\t\t<\"$TRASH_DIRECTORY\"/output >\"$TRASH_DIRECTORY\"/output.x &&\n+\ttest_must_be_empty \"$TRASH_DIRECTORY\"/output.x &&\n+\trm \"$TRASH_DIRECTORY\"/output \"$TRASH_DIRECTORY\"/output.x &&\n \tsort out >out_sorted &&\n-\ttest_cmp expected out_sorted &&\n-\ttest_must_be_empty \"$TRASH_DIRECTORY\"/output &&\n-\trm \"$TRASH_DIRECTORY\"/output\n+\ttest_cmp expected out_sorted\n }\n\n # Test __gitcomp.\n-- snap --\n\nIt is a bit ugly, in particular the `sed` expression (which is a bit\ncomplex because the `output` file can contain multi-line strings enclosed\nin single-quotes), and we could probably lose the `\"$TRASH_DIRECTORY\"/`\npart to improve the reading experience somewhat.\n\nBut my main concern is: Why does this happen in the first place? If we are\nrunning with Bash, why does `BASH_XTRACEFD` to work as intended here and\nmakes it necessary to filter out the traced commands?\n\nCiao,\nJohannes\n"},{"id":"486712","messageId":"20240112151655.GA640039@coredump.intra.peff.net","threadId":"60724","inReplyTo":"27edf445-d7fa-7aaf-7682-4ecc03366ef0@gmx.de","subject":"Re: [PATCH 1/2] t9902: verify that completion does not print anything","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2024-01-12T15:16:55Z","receivedAt":"2024-01-12T15:16:57Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Jan 12, 2024 at 02:12:43PM +0100, Johannes Schindelin wrote:\n\n> But my main concern is: Why does this happen in the first place? If we are\n> running with Bash, why does `BASH_XTRACEFD` to work as intended here and\n> makes it necessary to filter out the traced commands?\n\nBASH_XTRACEFD was introduced in bash 4.1. macOS ships with the ancient\nbash 3.2.57, which is the last GPLv2 version.\n\nOne simple solution is to mark the script with test_untraceable. See\n5fc98e79fc (t: add means to disable '-x' tracing for individual test\nscripts, 2018-02-24) and 5827506928 (t1510-repo-setup: mark as\nuntraceable with '-x', 2018-02-24).\n\nThat will disable tracing entirely in the script for older versions of\nbash, which could make debugging harder. But it will still work as\nexpected for people on reasonable versions of bash, and doesn't\nintroduce any complicated code.\n\n-Peff\n"},{"id":"486724","messageId":"xmqqedembem7.fsf@gitster.g","threadId":"60724","inReplyTo":"20240112151655.GA640039@coredump.intra.peff.net","subject":"Re: [PATCH 1/2] t9902: verify that completion does not print anything","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-01-12T18:17:36Z","receivedAt":"2024-01-12T18:17:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Fri, Jan 12, 2024 at 02:12:43PM +0100, Johannes Schindelin wrote:\n>\n>> But my main concern is: Why does this happen in the first place? If we are\n>> running with Bash, why does `BASH_XTRACEFD` to work as intended here and\n>> makes it necessary to filter out the traced commands?\n>\n> BASH_XTRACEFD was introduced in bash 4.1. macOS ships with the ancient\n> bash 3.2.57, which is the last GPLv2 version.\n>\n> One simple solution is to mark the script with test_untraceable. See\n> 5fc98e79fc (t: add means to disable '-x' tracing for individual test\n> scripts, 2018-02-24) and 5827506928 (t1510-repo-setup: mark as\n> untraceable with '-x', 2018-02-24).\n>\n> That will disable tracing entirely in the script for older versions of\n> bash, which could make debugging harder. But it will still work as\n> expected for people on reasonable versions of bash, and doesn't\n> introduce any complicated code.\n\nThank you, all three of you, for digging through to the bottom\nquickly.\n\nI too suspected a version of bash that is ancient and found out\nabout the \"untraceable\" bit just before I started reading this\nthread ;-)\n"},{"id":"486765","messageId":"20240113191749.GB3000857@szeder.dev","threadId":"60724","inReplyTo":"24563975fca8df6ae73917e9ee3534933d47c429.1704969119.git.ps@pks.im","subject":"Re: [PATCH 2/2] completion: silence pseudoref existence check","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2024-01-13T19:17:49Z","receivedAt":"2024-01-13T19:17:53Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Thu, Jan 11, 2024 at 11:41:59AM +0100, Patrick Steinhardt wrote:\n> In 44dbb3bf29 (completion: support pseudoref existence checks for\n> reftables, 2023-12-19), we have extended the Bash completion script to\n> support future ref backends better by using git-rev-parse(1) to check\n> for pseudo-ref existence. This conversion has introduced a bug, because\n> even though we pass `--quiet` to git-rev-parse(1) it would still output\n> the resolved object ID of the ref in question if it exists.\n> \n> Fix this by redirecting its stdout to `/dev/null` and add a test that\n> catches this behaviour. Note that the test passes even without the fix\n> for the \"files\" backend because we parse pseudo refs via the filesystem\n> directly in that case. But the test will fail with the \"reftable\"\n> backend.\n> \n> Signed-off-by: Patrick Steinhardt <ps@pks.im>\n> ---\n>  contrib/completion/git-completion.bash | 2 +-\n>  t/t9902-completion.sh                  | 8 ++++++++\n>  2 files changed, 9 insertions(+), 1 deletion(-)\n> \n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 8c40ade494..8872192e2b 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -146,7 +146,7 @@ __git_pseudoref_exists ()\n>  \tif __git_eread \"$__git_repo_path/HEAD\" head; then\n>  \t\tb=\"${head#ref: }\"\n>  \t\tif [ \"$b\" == \"refs/heads/.invalid\" ]; then\n\nNit: I guess these last two lines above came from the git prompt\nscript, where we do need the name of the ref, but here we don't need\nthat, so the condition could have simply been\n\n  if [ \"$head\" = \"ref: refs/heads/.invalid\" ]\n\nWith a single = instead of ==, because there is no pattern matching\nhere.\n\n> -\t\t\t__git -C \"$__git_repo_path\" rev-parse --verify --quiet \"$ref\" 2>/dev/null\n> +\t\t\t__git -C \"$__git_repo_path\" rev-parse --verify --quiet \"$ref\" >/dev/null 2>&1\n\nYou don't need the '-C $__git_repo_path' option and you don't have to\nredirect stderr either, because the purpose of the __git wrapper\nfunction is to take care of both.\n\n>  \t\t\treturn $?\n>  \t\tfi\n>  \tfi\n> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\n> index 78cb93bea7..b14ae4de14 100755\n> --- a/t/t9902-completion.sh\n> +++ b/t/t9902-completion.sh\n> @@ -1927,6 +1927,14 @@ test_expect_success 'git checkout - --orphan with branch already provided comple\n>  \tEOF\n>  '\n>  \n> +test_expect_success 'git reset completes modified files' '\n\nThe description of the test case mentions 'git reset' ...\n\n> +\ttest_commit A a.file &&\n> +\techo B >a.file &&\n> +\ttest_completion \"git restore a.\" <<-\\EOF\n\n... but it invokes 'git restore'.\n\nAnyway, I think it would be better to add a dedicated test or two to\nexercise the __git_pseudoref_exists helper function instead (or\nperhaps in addition).\n\n> +\ta.file\n> +\tEOF\n> +'\n> +\n>  test_expect_success 'teardown after ref completion' '\n>  \tgit branch -d matching-branch &&\n>  \tgit tag -d matching-tag &&\n> -- \n> 2.43.GIT\n> \n\n\n"},{"id":"486792","messageId":"ZaT0u4pEfY61V8QS@tanuki","threadId":"60724","inReplyTo":"20240112151655.GA640039@coredump.intra.peff.net","subject":"Re: [PATCH 1/2] t9902: verify that completion does not print anything","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-01-15T09:02:51Z","receivedAt":"2024-01-15T09:02:57Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, Jan 12, 2024 at 10:16:55AM -0500, Jeff King wrote:\n> On Fri, Jan 12, 2024 at 02:12:43PM +0100, Johannes Schindelin wrote:\n> \n> > But my main concern is: Why does this happen in the first place? If we are\n> > running with Bash, why does `BASH_XTRACEFD` to work as intended here and\n> > makes it necessary to filter out the traced commands?\n> \n> BASH_XTRACEFD was introduced in bash 4.1. macOS ships with the ancient\n> bash 3.2.57, which is the last GPLv2 version.\n> \n> One simple solution is to mark the script with test_untraceable. See\n> 5fc98e79fc (t: add means to disable '-x' tracing for individual test\n> scripts, 2018-02-24) and 5827506928 (t1510-repo-setup: mark as\n> untraceable with '-x', 2018-02-24).\n> \n> That will disable tracing entirely in the script for older versions of\n> bash, which could make debugging harder. But it will still work as\n> expected for people on reasonable versions of bash, and doesn't\n> introduce any complicated code.\n> \n> -Peff\n\nAh, this is indeed the best solution. Thanks for the hints and\ninvestigations everyone, will fix in the next iteration.\n\nPatrick\n"},{"id":"486796","messageId":"cover.1705314554.git.ps@pks.im","threadId":"60724","inReplyTo":"cover.1704969119.git.ps@pks.im","subject":"[PATCH v2 0/5] completion: silence pseudo-ref existence check","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-01-15T10:35:53Z","receivedAt":"2024-01-15T10:35:59Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Hi,\n\nthis is the second version of my patch series that refactors the Bash\ncompletion scripts to work better with reftables. Changes compared to\nv1:\n\n  - I've incorporated SZEDER's feedback that he has sent in reply to the\n    original patch series that is already in `master`. Most importantly,\n    we now discover the repo path in `__git_pseudoref_exists ()` itself.\n\n  - I've included some refactorings to stop leaking local variables in\n    `__git_pseudoref_exists ()`.\n\n  - I've added tests for `__git_pseudoref_exists ()` directly, which was\n    also suggested by SZEDER.\n\n  - I've marked t9902 with `test_untraceable` now to unbreak macOS CI.\n\n  - I've refactored the completion test to use `git show-ref --exists`\n    to fix an issue with unborn pseudorefs that I didn't notice\n    previously.\n\nI didn't include a range-diff because quite a lof of things have moved\naround.\n\nPatrick\n\nPatrick Steinhardt (5):\n  completion: discover repo path in `__git_pseudoref_exists ()`\n  t9902: verify that completion does not print anything\n  completion: improve existence check for pseudo-refs\n  completion: silence pseudoref existence check\n  completion: treat dangling symrefs as existing pseudorefs\n\n contrib/completion/git-completion.bash | 11 +++---\n t/t9902-completion.sh                  | 47 ++++++++++++++++++++++++--\n 2 files changed, 50 insertions(+), 8 deletions(-)\n-- \n2.43.GIT\n\n"},{"id":"486797","messageId":"8b6a45664a210ca5a18810fc6a8ff95823f92390.1705314554.git.ps@pks.im","threadId":"60724","inReplyTo":"cover.1705314554.git.ps@pks.im","subject":"[PATCH v2 1/5] completion: discover repo path in `__git_pseudoref_exists ()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-01-15T10:35:57Z","receivedAt":"2024-01-15T10:36:02Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The helper function `__git_pseudoref_exists ()` expects that the repo\npath has already been discovered by its callers, which makes for a\nrather fragile calling convention. Refactor the function to discover the\nrepo path itself to make it more self-contained, which also removes the\nneed to discover the path in some of its callers.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n contrib/completion/git-completion.bash | 5 ++---\n 1 file changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 8c40ade494..06a9107449 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -138,6 +138,8 @@ __git_pseudoref_exists ()\n {\n \tlocal ref=$1\n \n+\t__git_find_repo_path\n+\n \t# If the reftable is in use, we have to shell out to 'git rev-parse'\n \t# to determine whether the ref exists instead of looking directly in\n \t# the filesystem to determine whether the ref exists. Otherwise, use\n@@ -1656,7 +1658,6 @@ __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options\n \n _git_cherry_pick ()\n {\n-\t__git_find_repo_path\n \tif __git_pseudoref_exists CHERRY_PICK_HEAD; then\n \t\t__gitcomp \"$__git_cherry_pick_inprogress_options\"\n \t\treturn\n@@ -2966,7 +2967,6 @@ _git_reset ()\n \n _git_restore ()\n {\n-\t__git_find_repo_path\n \tcase \"$prev\" in\n \t-s)\n \t\t__git_complete_refs\n@@ -2995,7 +2995,6 @@ __git_revert_inprogress_options=$__git_sequencer_inprogress_options\n \n _git_revert ()\n {\n-\t__git_find_repo_path\n \tif __git_pseudoref_exists REVERT_HEAD; then\n \t\t__gitcomp \"$__git_revert_inprogress_options\"\n \t\treturn\n-- \n2.43.GIT\n\n"},{"id":"486798","messageId":"84b3546a8d8961ce77a2d55e67b91c9d61bbf351.1705314554.git.ps@pks.im","threadId":"60724","inReplyTo":"cover.1705314554.git.ps@pks.im","subject":"[PATCH v2 2/5] t9902: verify that completion does not print anything","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-01-15T10:36:02Z","receivedAt":"2024-01-15T10:36:06Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The Bash completion script must not print anything to either stdout or\nstderr. Instead, it is only expected to populate certain variables.\nTighten our `test_completion ()` test helper to verify this requirement.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n t/t9902-completion.sh | 12 ++++++++++--\n 1 file changed, 10 insertions(+), 2 deletions(-)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex aa9a614de3..95ec762a74 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -5,6 +5,12 @@\n \n test_description='test bash completion'\n \n+# The Bash completion scripts must not print anything to either stdout or\n+# stderr, which we try to verify. When tracing is enabled without support for\n+# BASH_XTRACEFD this assertion will fail, so we have to mark the test as\n+# untraceable with such ancient Bash versions.\n+test_untraceable=UnfortunatelyYes\n+\n . ./lib-bash.sh\n \n complete ()\n@@ -87,9 +93,11 @@ test_completion ()\n \telse\n \t\tsed -e 's/Z$//' |sort >expected\n \tfi &&\n-\trun_completion \"$1\" &&\n+\trun_completion \"$1\" >\"$TRASH_DIRECTORY\"/bash-completion-output 2>&1 &&\n \tsort out >out_sorted &&\n-\ttest_cmp expected out_sorted\n+\ttest_cmp expected out_sorted &&\n+\ttest_must_be_empty \"$TRASH_DIRECTORY\"/bash-completion-output &&\n+\trm \"$TRASH_DIRECTORY\"/bash-completion-output\n }\n \n # Test __gitcomp.\n-- \n2.43.GIT\n\n"},{"id":"486799","messageId":"ab6e9118a552308d7121b6a1c12a8f04c4788326.1705314554.git.ps@pks.im","threadId":"60724","inReplyTo":"cover.1705314554.git.ps@pks.im","subject":"[PATCH v2 3/5] completion: improve existence check for pseudo-refs","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-01-15T10:36:06Z","receivedAt":"2024-01-15T10:36:09Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Improve the existence check along the following lines:\n\n  - Stop stripping the \"ref :\" prefix and compare to the expected value\n    directly. This allows us to drop a now-unused variable that was\n    previously leaking into the user's shell.\n\n  - Mark the \"head\" variable as local so that we don't leak its value\n    into the user's shell.\n\n  - Stop manually handling the `-C $__git_repo_path` option, which the\n    `__git ()` wrapper aleady does for us.\n\n  - In simlar spirit, stop redirecting stderr, which is also handled by\n    the wrapper already.\n\nSuggested-by: SZEDER Gábor <szeder.dev@gmail.com>\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n contrib/completion/git-completion.bash | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 06a9107449..d703e3e64f 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -137,6 +137,7 @@ __git_eread ()\n __git_pseudoref_exists ()\n {\n \tlocal ref=$1\n+\tlocal head\n \n \t__git_find_repo_path\n \n@@ -146,9 +147,8 @@ __git_pseudoref_exists ()\n \t# Bash builtins since executing Git commands are expensive on some\n \t# platforms.\n \tif __git_eread \"$__git_repo_path/HEAD\" head; then\n-\t\tb=\"${head#ref: }\"\n-\t\tif [ \"$b\" == \"refs/heads/.invalid\" ]; then\n-\t\t\t__git -C \"$__git_repo_path\" rev-parse --verify --quiet \"$ref\" 2>/dev/null\n+\t\tif [ \"$head\" == \"ref: refs/heads/.invalid\" ]; then\n+\t\t\t__git rev-parse --verify --quiet \"$ref\"\n \t\t\treturn $?\n \t\tfi\n \tfi\n-- \n2.43.GIT\n\n"},{"id":"486800","messageId":"4de00121b24f31d21e54738a4645eefa3d283374.1705314554.git.ps@pks.im","threadId":"60724","inReplyTo":"cover.1705314554.git.ps@pks.im","subject":"[PATCH v2 4/5] completion: silence pseudoref existence check","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-01-15T10:36:11Z","receivedAt":"2024-01-15T10:36:15Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"In 44dbb3bf29 (completion: support pseudoref existence checks for\nreftables, 2023-12-19), we have extended the Bash completion script to\nsupport future ref backends better by using git-rev-parse(1) to check\nfor pseudo-ref existence. This conversion has introduced a bug, because\neven though we pass `--quiet` to git-rev-parse(1) it would still output\nthe resolved object ID of the ref in question if it exists.\n\nFix this by redirecting its stdout to `/dev/null` and add a test that\ncatches this behaviour. Note that the test passes even without the fix\nfor the \"files\" backend because we parse pseudo refs via the filesystem\ndirectly in that case. But the test will fail with the \"reftable\"\nbackend.\n\nHelped-by: Jeff King <peff@peff.net>\nHelped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n contrib/completion/git-completion.bash |  2 +-\n t/t9902-completion.sh                  | 31 ++++++++++++++++++++++++++\n 2 files changed, 32 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex d703e3e64f..54ce58f73d 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -148,7 +148,7 @@ __git_pseudoref_exists ()\n \t# platforms.\n \tif __git_eread \"$__git_repo_path/HEAD\" head; then\n \t\tif [ \"$head\" == \"ref: refs/heads/.invalid\" ]; then\n-\t\t\t__git rev-parse --verify --quiet \"$ref\"\n+\t\t\t__git rev-parse --verify --quiet \"$ref\" >/dev/null\n \t\t\treturn $?\n \t\tfi\n \tfi\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 95ec762a74..56dc7343a2 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -1933,6 +1933,14 @@ test_expect_success 'git checkout - --orphan with branch already provided comple\n \tEOF\n '\n \n+test_expect_success 'git restore completes modified files' '\n+\ttest_commit A a.file &&\n+\techo B >a.file &&\n+\ttest_completion \"git restore a.\" <<-\\EOF\n+\ta.file\n+\tEOF\n+'\n+\n test_expect_success 'teardown after ref completion' '\n \tgit branch -d matching-branch &&\n \tgit tag -d matching-tag &&\n@@ -2728,4 +2736,27 @@ test_expect_success '__git_complete' '\n \ttest_must_fail __git_complete ga missing\n '\n \n+test_expect_success '__git_pseudoref_exists' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\tsane_unset __git_repo_path &&\n+\n+\t\t# HEAD points to an existing branch, so it should exist.\n+\t\ttest_commit A &&\n+\t\t__git_pseudoref_exists HEAD >output 2>&1 &&\n+\t\ttest_must_be_empty output &&\n+\n+\t\t# CHERRY_PICK_HEAD does not exist, so the existence check should fail.\n+\t\t! __git_pseudoref_exists CHERRY_PICK_HEAD >output 2>&1 &&\n+\t\ttest_must_be_empty output &&\n+\n+\t\t# CHERRY_PICK_HEAD points to a commit, so it should exist.\n+\t\tgit update-ref CHERRY_PICK_HEAD A &&\n+\t\t__git_pseudoref_exists CHERRY_PICK_HEAD >output 2>&1 &&\n+\t\ttest_must_be_empty output\n+\t)\n+'\n+\n test_done\n-- \n2.43.GIT\n\n"},{"id":"486801","messageId":"22269af050fc9379c1049afb8ae51cbfec2a3670.1705314554.git.ps@pks.im","threadId":"60724","inReplyTo":"cover.1705314554.git.ps@pks.im","subject":"[PATCH v2 5/5] completion: treat dangling symrefs as existing pseudorefs","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-01-15T10:36:15Z","receivedAt":"2024-01-15T10:36:19Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The `__git_pseudoref_exists ()` helper function back to git-rev-parse(1)\nin case the reftable backend is in use. This is not in the same spirit\nas the simple existence check that the \"files\" backend does though,\nbecause there we only check for the pseudo-ref to exist with `test -f`.\nWith git-rev-parse(1) we not only check for existence, but also verify\nthat the pseudo-ref resolves to an object, which may not be the case\nwhen the pseudo-ref points to an unborn branch.\n\nFix this issue by using `git show-ref --exists` instead. Note that we do\nnot have to silence stdout anymore as git-show-ref(1) will not print\nanything.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n contrib/completion/git-completion.bash | 2 +-\n t/t9902-completion.sh                  | 4 ++++\n 2 files changed, 5 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 54ce58f73d..6662db221d 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -148,7 +148,7 @@ __git_pseudoref_exists ()\n \t# platforms.\n \tif __git_eread \"$__git_repo_path/HEAD\" head; then\n \t\tif [ \"$head\" == \"ref: refs/heads/.invalid\" ]; then\n-\t\t\t__git rev-parse --verify --quiet \"$ref\" >/dev/null\n+\t\t\t__git show-ref --exists \"$ref\"\n \t\t\treturn $?\n \t\tfi\n \tfi\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 56dc7343a2..35eb534fdd 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -2743,6 +2743,10 @@ test_expect_success '__git_pseudoref_exists' '\n \t\tcd repo &&\n \t\tsane_unset __git_repo_path &&\n \n+\t\t# HEAD should exist, even if it points to an unborn branch.\n+\t\t__git_pseudoref_exists HEAD >output 2>&1 &&\n+\t\ttest_must_be_empty output &&\n+\n \t\t# HEAD points to an existing branch, so it should exist.\n \t\ttest_commit A &&\n \t\t__git_pseudoref_exists HEAD >output 2>&1 &&\n-- \n2.43.GIT\n\n"}]}