diff mbox series

[1/2] completion: merge options for cherry-pick and revert

Message ID cdcac975548502a58234f7537a5fe11dcdb538ea.1566637431.git.liu.denton@gmail.com (mailing list archive)
State New, archived
Headers show
Series completion: complete --skip for cherry-pick and revert | expand

Commit Message

Denton Liu Aug. 24, 2019, 9:04 a.m. UTC
Since revert and cherry-pick share the same sequencer code, they should
both accept the same command-line options. Merge the
`__git_cherry_pick_inprogress_options` and
`__git_revert_inprogress_options` variables together into
`__git_cherry_pick_revert_inprogress_options` so that the options aren't
unnecessarily duplicated twice.

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

Comments

Junio C Hamano Aug. 26, 2019, 4:59 p.m. UTC | #1
Denton Liu <liu.denton@gmail.com> writes:

> Since revert and cherry-pick share the same sequencer code, they should
> both accept the same command-line options. Merge the
> `__git_cherry_pick_inprogress_options` and
> `__git_revert_inprogress_options` variables together into
> `__git_cherry_pick_revert_inprogress_options` so that the options aren't
> unnecessarily duplicated twice.

Hmm, will the claim hold true in the future?  I do agree that they
will share continue, quit and abort (and skip) forever, but I am not
bold enough to declare that they will never have some unique option
in addition to the common one only because they "share the same
sequencer" machinery.  It is trivial to add a "if we are in revert,
do this" to the code, and it already works that way.

__git_sequencer_inprogress_common_options="--continue --quit --abort"
__git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_common_options
__git_revert_inprogress_options=$__git_sequencer_inprogress_common_options

may be a bit more future-proof way, perhaps?  The places that use
the variable(s) already correctly distinguish cherry-pick and
revert, so even though the above and your version equally "unify"
the set of common options and allow adding a new common option
(i.e. skip) with equal ease, yours makes giving unique option to one
but not to the other more difficult.
diff mbox series

Patch

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index e087c4bf00..62f8ef600d 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1361,13 +1361,13 @@  _git_checkout ()
 	esac
 }
 
-__git_cherry_pick_inprogress_options="--continue --quit --abort"
+__git_cherry_pick_revert_inprogress_options="--continue --quit --abort"
 
 _git_cherry_pick ()
 {
 	__git_find_repo_path
 	if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
-		__gitcomp "$__git_cherry_pick_inprogress_options"
+		__gitcomp "$__git_cherry_pick_revert_inprogress_options"
 		return
 	fi
 
@@ -1376,7 +1376,7 @@  _git_cherry_pick ()
 	case "$cur" in
 	--*)
 		__gitcomp_builtin cherry-pick "" \
-			"$__git_cherry_pick_inprogress_options"
+			"$__git_cherry_pick_revert_inprogress_options"
 		;;
 	*)
 		__git_complete_refs
@@ -2512,20 +2512,18 @@  _git_restore ()
 	esac
 }
 
-__git_revert_inprogress_options="--continue --quit --abort"
-
 _git_revert ()
 {
 	__git_find_repo_path
 	if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
-		__gitcomp "$__git_revert_inprogress_options"
+		__gitcomp "$__git_cherry_pick_revert_inprogress_options"
 		return
 	fi
 	__git_complete_strategy && return
 	case "$cur" in
 	--*)
 		__gitcomp_builtin revert "" \
-			"$__git_revert_inprogress_options"
+			"$__git_cherry_pick_revert_inprogress_options"
 		return
 		;;
 	esac