Skip to content

fix: preserve bash wrapper completion context#159

Open
helizaga wants to merge 1 commit intomainfrom
fix/issue-156-bash-wrapper-completion
Open

fix: preserve bash wrapper completion context#159
helizaga wants to merge 1 commit intomainfrom
fix/issue-156-bash-wrapper-completion

Conversation

@helizaga
Copy link
Collaborator

@helizaga helizaga commented Mar 18, 2026

Summary

  • rewrite COMP_LINE and COMP_POINT when the bash gtr wrapper delegates completion to _git_gtr
  • keep the wrapper-specific new --cd behavior while sharing the delegation logic
  • add hermetic runtime regression tests for delegated wrapper completion, including custom wrapper names

Closes #156.

Testing

  • bats tests/init.bats
  • bats tests/
  • Disposable repo smoke: git gtr new test-feature, git gtr new feature/auth, git gtr list, git gtr go test-feature, git gtr run test-feature git status --short, git gtr rm test-feature feature/auth --yes
  • Bash wrapper smoke: generate git gtr init bash, invoke _gtr_completion for gtr ai fe, and verify delegated state becomes git gtr ai fe with COMP_POINT=13

Summary by CodeRabbit

  • Refactor

    • Enhanced bash completion consistency by centralizing delegation logic, ensuring uniform and reliable behavior across different command contexts and wrapper configurations.
  • Tests

    • Added comprehensive test coverage validating bash completion functionality across various wrapper configurations, different naming conventions, and complex delegation scenarios.

@helizaga helizaga requested a review from NatoBoram as a code owner March 18, 2026 08:25
@coderabbitai
Copy link

coderabbitai bot commented Mar 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 545880c7-93bb-42f0-bbe4-079ea450b5ca

📥 Commits

Reviewing files that changed from the base of the PR and between 5afbfa8 and f4b30c3.

📒 Files selected for processing (2)
  • lib/commands/init.sh
  • tests/init.bats

Walkthrough

Introduces a completion delegation function that properly adjusts all bash completion variables (COMP_WORDS, COMP_CWORD, COMP_LINE, COMP_POINT) when delegating to git-gtr, replacing direct function calls with unified function invocation. Adds test coverage for wrapper completion across varying input lengths.

Changes

Cohort / File(s) Summary
Completion delegation refactoring
lib/commands/init.sh
New ___FUNC___delegate_completion() function centralizes rewriting of bash completion context variables before delegating to _git_gtr. Existing completion branches updated to invoke this function instead of direct _git_gtr calls.
Test coverage for wrapper completion
tests/init.bats
New test helper run_generated_bash_wrapper_completion and three test cases validating bash wrapper completion behavior with ai targets, custom wrapper names, and new flag handling with --cd delegation across input lengths.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A hop through the completion maze,
Where vars were misaligned in many ways,
Now delegation shines so bright,
COMP_LINE and COMP_POINT set right,
Two, three, four chars—all work with ease!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: adding a wrapper function to preserve COMP_LINE and COMP_POINT context during bash completion delegation.
Linked Issues check ✅ Passed Changes implement the exact fix proposed in #156: COMP_LINE and COMP_POINT are rewritten in the new delegate_completion function, applied to both delegation sites (new subcommand and general fallback).
Out of Scope Changes check ✅ Passed All changes are scoped to fixing #156: lib/commands/init.sh adds the delegation function and updates completion logic, tests/init.bats adds regression tests for wrapper completion with --cd delegation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-156-bash-wrapper-completion
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@averyjennings averyjennings left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean fix for the COMP_LINE/COMP_POINT consistency bug. The extracted delegate helper is the right call — DRYs up both delegation sites and makes the rewrite logic easy to audit in one place. Arithmetic is correct for all realistic wrapper name lengths, and the tests are well-designed (eval the generated code, mock _git_gtr, verify all four completion variables). No blockers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bash completion for gtr wrapper breaks with 2+ character input

2 participants