fix(completion): filter mutually exclusive options in bash and zsh completions#1642
Merged
PawelLipski merged 2 commits intoVirtusLab:developfrom Apr 29, 2026
Conversation
12229f3 to
af4a416
Compare
Collaborator
|
Thanks for the contribution, I've repointed the PR to |
PawelLipski
reviewed
Apr 20, 2026
Collaborator
|
Please also cover at least some of the case in completion tests - i.e. that non-compatible options are consistently skipped from completion in the 3 shells. Given that all the completion tests still pass currently, these cases were most likely not covered at all (since fish excluded non-compatible options correctly, but the other shells did not :/) |
…mpletions Issue: VirtusLab#1102 Bash and zsh completions currently suggest all options regardless of what has already been specified on the command line. For example, 'slide-out --merge -' suggests '--down-fork-point' even though these are mutually exclusive. Fish completion already has this filtering logic. Port the same mutual exclusion patterns to bash and zsh completions: Bash: Add _git_machete_seen_opt helper that checks if any of a set of options are already present in COMP_WORDS, then filter the option list for each subcommand accordingly (add, anno, fork-point, slide-out, traverse, update). Zsh: Update _arguments exclusion group prefixes to list all mutually exclusive options, so zsh's native completion system handles the filtering.
7332679 to
8f3d128
Compare
8f3d128 to
c4c1d96
Compare
PawelLipski
approved these changes
Apr 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Issue #1102: Bash and zsh shell completions suggest mutually exclusive options. For example,
git machete slide-out --merge <Tab>suggests--down-fork-pointeven though these flags cannot be used together.Fish completion already handles this correctly.
Solution
Port the same mutual exclusion filtering from fish completion to bash and zsh completions.
Bash completion
Added
_git_machete_seen_opthelper function that checks if any of a set of options are already present inCOMP_WORDS. For each subcommand with exclusivity rules (add,anno,fork-point,slide-out,traverse,update), filter the option list before passing it to__gitcomp.Zsh completion
Updated
_argumentsexclusion group prefixes to list all mutually exclusive options. For example,(-R --as-root)became(-R --as-root -f --as-first-child)for the--ontooption inadd. This leverages zsh's native completion system to handle the filtering.Exclusion groups covered
--as-rootexclusive with--ontoand--as-first-child--sync-github-prsexclusive with--sync-gitlab-mrs--inferred,--override-to*,--unset-override)--removed-from-remoteexclusive with most other options;--mergeexclusive with--down-fork-pointand--no-interactive-rebase;-nexclusive with--no-edit-mergeand--no-interactive-rebase;--no-rebaseexclusive with rebase-specific and merge-specific options--mergeexclusive with--no-interactive-rebase;-nexclusive with--no-edit-merge,--no-interactive-rebase,--yes;--sync-github-prs/--sync-gitlab-mrsexclusive;--push/--no-pushexclusive;--push-untracked/--no-push-untrackedexclusive;-Wexclusive with-F,-l,-w;--yesexclusive with-n--mergeexclusive with--fork-pointand--no-interactive-rebase;-nexclusive with--no-edit-mergeand--no-interactive-rebaseTesting
test_bash_completion,test_fish_completion,test_zsh_completion)Closes #1102