git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] completion: teach archive to use __gitcomp_builtin

From
Denton Liu <liu.denton@gmail.com>
Date
Sep 12, 2019, 19:43 UTC
Message-ID
<39d6091ce636b2d732d589b55e7686796694e994.1568317093.git.liu.denton@gmail.com>
In-Reply-To
<cover.1568317093.git.liu.denton@gmail.com>

Currently, _git_archive() uses a hardcoded list of options for its completion. However, we can use __gitcomp_builtin() to get a dynamically generated list of completions instead.

Teach _git_archive() to use __gitcomp_builtin() so that newly implemented options in archive will be automatically completed without any mucking around in git-completion.bash. While we're at it, teach it to complete the missing `--worktree-attributes` option as well.

Unfortunately, since some args are passed through from cmd_archive() to write_archive() (which calls parse_archive_args()), there's no way that a `--git-completion-helper` arg can end up reaching parse_archive_args() since the first call to parse_options() will end up calling exit(0). As a result, we have to carry the options supported by write_archive() in the hardcoded string.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 contrib/completion/git-completion.bash | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 365edff639..7b1ab46f0b 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1250,10 +1250,7 @@ _git_archive ()
 		return
 		;;
 	--*)
-		__gitcomp "
-			--format= --list --verbose
-			--prefix= --remote= --exec= --output
-			"
+		__gitcomp_builtin archive "--format= --list --verbose --prefix= --worktree-attributes"
 		return
 		;;
 	esac
-- 
2.23.0.37.g745f681289
Previous: Denton LiuNext: Junio C Hamano
Message 3 of 4 in “completion: teach rebase and archive to use __gitcomp_builtin”
  1. 0/2 completion: teach rebase and archive to use __gitcomp_builtinDenton Liu, Sep 12, 2019
  2. 1/2 completion: teach rebase to use __gitcomp_builtinDenton Liu, Sep 12, 2019
  3. 2/2 completion: teach archive to use __gitcomp_builtinDenton Liu, Sep 12, 2019
  4. Junio C HamanoSep 12, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.