git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/2] completion: teach rebase and archive to use __gitcomp_builtin
@ 2019-09-12 19:43 Denton Liu
  2019-09-12 19:43 ` [PATCH 1/2] completion: teach rebase " Denton Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Denton Liu @ 2019-09-12 19:43 UTC (permalink / raw)
  To: Git Mailing List

Currently, the completion function for rebase and archive don't take
advantage of __gitcomp_builtin(). Teach them to use it so that future
changes to options will automatically be included by the completion
script with no extra work.

I discovered rebase wasn't using it and fixed that and I started looking
for other low-hanging fruit to fix. I deliberately left stuff like diff
and log alone since that's a whole Pandora's box that I don't really
want to open right now.


Denton Liu (2):
  completion: teach rebase to use __gitcomp_builtin
  completion: teach archive to use __gitcomp_builtin

 contrib/completion/git-completion.bash | 27 ++++++++------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

-- 
2.23.0.37.g745f681289


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] completion: teach rebase to use __gitcomp_builtin
  2019-09-12 19:43 [PATCH 0/2] completion: teach rebase and archive to use __gitcomp_builtin Denton Liu
@ 2019-09-12 19:43 ` Denton Liu
  2019-09-12 19:43 ` [PATCH 2/2] completion: teach archive " Denton Liu
  2019-09-12 20:44 ` [PATCH 0/2] completion: teach rebase and " Junio C Hamano
  2 siblings, 0 replies; 4+ messages in thread
From: Denton Liu @ 2019-09-12 19:43 UTC (permalink / raw)
  To: Git Mailing List

Currently, _git_rebase() 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_rebase() to use __gitcomp_builtin() so that newly implemented
options in rebase will be automatically completed without any mucking
around in git-completion.bash.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 contrib/completion/git-completion.bash | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index e087c4bf00..365edff639 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2004,15 +2004,18 @@ _git_range_diff ()
 	__git_complete_revlist
 }
 
+__git_rebase_inprogress_options="--continue --skip --abort --quit --show-current-patch"
+__git_rebase_interactive_inprogress_options="$__git_rebase_inprogress_options --edit-todo"
+
 _git_rebase ()
 {
 	__git_find_repo_path
 	if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
-		__gitcomp "--continue --skip --abort --quit --edit-todo --show-current-patch"
+		__gitcomp "$__git_rebase_interactive_inprogress_options"
 		return
 	elif [ -d "$__git_repo_path"/rebase-apply ] || \
 	     [ -d "$__git_repo_path"/rebase-merge ]; then
-		__gitcomp "--continue --skip --abort --quit --show-current-patch"
+		__gitcomp "$__git_rebase_inprogress_options"
 		return
 	fi
 	__git_complete_strategy && return
@@ -2022,19 +2025,8 @@ _git_rebase ()
 		return
 		;;
 	--*)
-		__gitcomp "
-			--onto --merge --strategy --interactive
-			--rebase-merges --preserve-merges --stat --no-stat
-			--committer-date-is-author-date --ignore-date
-			--ignore-whitespace --whitespace=
-			--autosquash --no-autosquash
-			--fork-point --no-fork-point
-			--autostash --no-autostash
-			--verify --no-verify
-			--keep-empty --root --force-rebase --no-ff
-			--rerere-autoupdate
-			--exec
-			"
+		__gitcomp_builtin rebase "" \
+			"$__git_rebase_interactive_inprogress_options"
 
 		return
 	esac
-- 
2.23.0.37.g745f681289


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] completion: teach archive to use __gitcomp_builtin
  2019-09-12 19:43 [PATCH 0/2] completion: teach rebase and archive to use __gitcomp_builtin Denton Liu
  2019-09-12 19:43 ` [PATCH 1/2] completion: teach rebase " Denton Liu
@ 2019-09-12 19:43 ` Denton Liu
  2019-09-12 20:44 ` [PATCH 0/2] completion: teach rebase and " Junio C Hamano
  2 siblings, 0 replies; 4+ messages in thread
From: Denton Liu @ 2019-09-12 19:43 UTC (permalink / raw)
  To: Git Mailing List

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] completion: teach rebase and archive to use __gitcomp_builtin
  2019-09-12 19:43 [PATCH 0/2] completion: teach rebase and archive to use __gitcomp_builtin Denton Liu
  2019-09-12 19:43 ` [PATCH 1/2] completion: teach rebase " Denton Liu
  2019-09-12 19:43 ` [PATCH 2/2] completion: teach archive " Denton Liu
@ 2019-09-12 20:44 ` Junio C Hamano
  2 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2019-09-12 20:44 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List

Denton Liu <liu.denton@gmail.com> writes:

> Currently, the completion function for rebase and archive don't take
> advantage of __gitcomp_builtin(). Teach them to use it so that future
> changes to options will automatically be included by the completion
> script with no extra work.

Nice ;-)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-09-12 20:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-12 19:43 [PATCH 0/2] completion: teach rebase and archive to use __gitcomp_builtin Denton Liu
2019-09-12 19:43 ` [PATCH 1/2] completion: teach rebase " Denton Liu
2019-09-12 19:43 ` [PATCH 2/2] completion: teach archive " Denton Liu
2019-09-12 20:44 ` [PATCH 0/2] completion: teach rebase and " Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).