Skip to content

fix(completion): filter mutually exclusive options in bash and zsh completions#1642

Merged
PawelLipski merged 2 commits intoVirtusLab:developfrom
CodeLine9:clawoss/fix/1102-exclusive-completions
Apr 29, 2026
Merged

fix(completion): filter mutually exclusive options in bash and zsh completions#1642
PawelLipski merged 2 commits intoVirtusLab:developfrom
CodeLine9:clawoss/fix/1102-exclusive-completions

Conversation

@CodeLine9
Copy link
Copy Markdown
Contributor

Problem

Issue #1102: Bash and zsh shell completions suggest mutually exclusive options. For example, git machete slide-out --merge <Tab> suggests --down-fork-point even 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_opt helper function that checks if any of a set of options are already present in COMP_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 _arguments exclusion group prefixes to list all mutually exclusive options. For example, (-R --as-root) became (-R --as-root -f --as-first-child) for the --onto option in add. This leverages zsh's native completion system to handle the filtering.

Exclusion groups covered

  • add: --as-root exclusive with --onto and --as-first-child
  • anno: --sync-github-prs exclusive with --sync-gitlab-mrs
  • fork-point: three mutually exclusive forms (--inferred, --override-to*, --unset-override)
  • slide-out: --removed-from-remote exclusive with most other options; --merge exclusive with --down-fork-point and --no-interactive-rebase; -n exclusive with --no-edit-merge and --no-interactive-rebase; --no-rebase exclusive with rebase-specific and merge-specific options
  • traverse: --merge exclusive with --no-interactive-rebase; -n exclusive with --no-edit-merge, --no-interactive-rebase, --yes; --sync-github-prs/--sync-gitlab-mrs exclusive; --push/--no-push exclusive; --push-untracked/--no-push-untracked exclusive; -W exclusive with -F, -l, -w; --yes exclusive with -n
  • update: --merge exclusive with --fork-point and --no-interactive-rebase; -n exclusive with --no-edit-merge and --no-interactive-rebase

Testing

  • All 3 existing unit tests pass (test_bash_completion, test_fish_completion, test_zsh_completion)
  • Manually verified bash completions for all exclusion groups
  • Initial completions (no options present) remain unchanged

Closes #1102

@PawelLipski PawelLipski changed the base branch from master to develop April 20, 2026 10:46
@PawelLipski PawelLipski force-pushed the clawoss/fix/1102-exclusive-completions branch from 12229f3 to af4a416 Compare April 20, 2026 10:47
@PawelLipski
Copy link
Copy Markdown
Collaborator

Thanks for the contribution, I've repointed the PR to develop (master is mostly for releases)

Comment thread completion/git-machete.completion.bash Outdated
@PawelLipski
Copy link
Copy Markdown
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 :/)

@PawelLipski PawelLipski added this to the v3.40.1 milestone Apr 20, 2026
@PawelLipski PawelLipski added the completion Shell completions label Apr 20, 2026
…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.
@PawelLipski PawelLipski force-pushed the clawoss/fix/1102-exclusive-completions branch 5 times, most recently from 7332679 to 8f3d128 Compare April 29, 2026 09:07
@PawelLipski PawelLipski force-pushed the clawoss/fix/1102-exclusive-completions branch from 8f3d128 to c4c1d96 Compare April 29, 2026 14:35
@PawelLipski PawelLipski self-assigned this Apr 29, 2026
@PawelLipski PawelLipski merged commit b258b9f into VirtusLab:develop Apr 29, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

completion Shell completions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In bash and zsh completions, do not suggest options that are mutually exclusive

2 participants