completions/git: fix completions for third-party git commands

Before 798527d79a (completions: fix double evaluation of tokenized commandline, 2024-01-06)
git-foo completions did something like

	set -l subcommand_args (commandline -opc)
	complete -C "git-foo $subcommand_args "

As mentioned in 368017905e (builtin commandline: -x for expanded tokens,
supplanting -o, 2024-01-06), the "-o" option is bad
because it produces a weird intermediate, half-expanded state.

The immediate goal of 798527d79a was to make sure we do not do any
more expansion on top of this.  To that end, it changed the above to
"\$subcommand_args".  The meaning is more or less the same[^*] but crucially,
the recursive completion invocation does not see through the variable,
which breaks some completions.

Fix this with the same approach as in 6b5ad163d3 (Fix double expansion of
tokenized command line, 2025-01-19).

[^*]: It wasn't semantically correct before or after -- this was later
corrected by 29f35d6cdf (completion: adopt commandline -x replacing deprecated
-o, 2024-01-22)).

Closes #11205
This commit is contained in:
Johannes Altmanninger
2025-03-03 14:14:24 +01:00
parent 4378e73fc7
commit 50e595503e
2 changed files with 7 additions and 2 deletions

View File

@@ -40,12 +40,17 @@ echo "echo foo" > git-frobnicate
chmod +x git-frobnicate
complete -c git-frobnicate -xa 'foo bar baz'
complete -c git-frobnicate -l onto -xa 'onto1 onto2'
complete -C'git frobnicate '
#CHECK: bar
#CHECK: baz
#CHECK: foo
complete -C'git frobnicate --onto '
#CHECK: onto1
#CHECK: onto2
complete -C'git ' | grep '^add'\t
# (note: actual tab character in the check here)
#CHECK: add Add file contents to the staging area