Skip to content

Commit fae9160

Browse files
authored
Migrate to git gtr subcommand (resolves coreutils conflict) (#19)
1 parent 989e809 commit fae9160

File tree

12 files changed

+510
-283
lines changed

12 files changed

+510
-283
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Pull Request
2+
3+
## Description
4+
5+
<!-- A clear and concise description of what this PR does -->
6+
7+
## Motivation
8+
9+
<!-- Why is this change needed? What problem does it solve? -->
10+
11+
Fixes # (issue)
12+
13+
## Type of Change
14+
15+
<!-- Check all that apply -->
16+
17+
- [ ] Bug fix (non-breaking change that fixes an issue)
18+
- [ ] New feature (non-breaking change that adds functionality)
19+
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
20+
- [ ] Documentation update
21+
- [ ] Code refactoring (no functional changes)
22+
- [ ] Other (please describe):
23+
24+
## Testing
25+
26+
<!-- Describe the tests you ran to verify your changes -->
27+
28+
### Manual Testing Checklist
29+
30+
**Tested on:**
31+
32+
- [ ] macOS
33+
- [ ] Linux (specify distro: **\*\***\_**\*\***)
34+
- [ ] Windows (Git Bash)
35+
36+
**Core functionality tested:**
37+
38+
- [ ] `git gtr new <branch>` - Create worktree
39+
- [ ] `git gtr go <branch>` - Navigate to worktree
40+
- [ ] `git gtr editor <branch>` - Open in editor (if applicable)
41+
- [ ] `git gtr ai <branch>` - Start AI tool (if applicable)
42+
- [ ] `git gtr rm <branch>` - Remove worktree
43+
- [ ] `git gtr list` - List worktrees
44+
- [ ] `git gtr config` - Configuration commands (if applicable)
45+
- [ ] Other commands affected by this change: **\*\***\_\_**\*\***
46+
47+
### Test Steps
48+
49+
<!-- Provide detailed steps to reproduce/test your changes -->
50+
51+
1.
52+
2.
53+
3.
54+
55+
**Expected behavior:**
56+
57+
**Actual behavior:**
58+
59+
## Breaking Changes
60+
61+
<!-- If this introduces breaking changes, describe: -->
62+
<!-- - What breaks -->
63+
<!-- - Why it's necessary -->
64+
<!-- - Migration path for users -->
65+
66+
- [ ] This PR introduces breaking changes
67+
- [ ] I have discussed this in an issue first
68+
- [ ] Migration guide is included in documentation
69+
70+
## Checklist
71+
72+
Before submitting this PR, please check:
73+
74+
- [ ] I have read [CONTRIBUTING.md](../CONTRIBUTING.md)
75+
- [ ] My code follows the project's style guidelines
76+
- [ ] I have performed manual testing on at least one platform
77+
- [ ] I have updated documentation (README.md, CLAUDE.md, etc.) if needed
78+
- [ ] My changes work on multiple platforms (or I've noted platform-specific behavior)
79+
- [ ] I have added/updated shell completions (if adding new commands or flags)
80+
- [ ] I have tested with both `git gtr` (production) and `./bin/gtr` (development)
81+
- [ ] No new external dependencies are introduced (Bash + git only)
82+
- [ ] All existing functionality still works
83+
84+
## Additional Context
85+
86+
<!-- Add any other context, screenshots, or information about the PR here -->
87+
88+
---
89+
90+
## License Acknowledgment
91+
92+
By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache License 2.0](../LICENSE.txt).
Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,77 @@
11
---
2-
applyTo: completions/gtr.bash, completions/_gtr, completions/gtr.fish
2+
applyTo: completions/gtr.bash, completions/_git-gtr, completions/gtr.fish
33
---
44

55
# Completions Instructions
66

77
## Overview
88

9-
Shell completions provide tab-completion for `gtr` commands, flags, branches, and adapter names across Bash, Zsh, and Fish shells.
9+
Shell completions provide tab-completion for `git gtr` commands, flags, branches, and adapter names across Bash, Zsh, and Fish shells.
1010

1111
## When to Update Completions
1212

1313
**Always update all three completion files** when:
1414

15-
- Adding new commands (e.g., `gtr new-command`)
15+
- Adding new commands (e.g., `git gtr new-command`)
1616
- Adding new flags to existing commands (e.g., `--new-flag`)
1717
- Adding editor or AI adapters (completion must list available adapters)
1818
- Changing command names or flag names
1919

2020
## File Responsibilities
2121

2222
- **`completions/gtr.bash`** - Bash completion (requires bash-completion v2+)
23-
- **`completions/_gtr`** - Zsh completion (uses Zsh completion system)
23+
- **`completions/_git-gtr`** - Zsh completion (uses Zsh completion system)
2424
- **`completions/gtr.fish`** - Fish shell completion
2525

2626
## Implementation Pattern
2727

2828
Each completion file implements:
2929

30-
1. **Command completion** - Top-level commands (`new`, `rm`, `open`, `ai`, `list`, etc.)
30+
1. **Command completion** - Top-level commands (`new`, `rm`, `editor`, `ai`, `list`, etc.)
3131
2. **Flag completion** - Command-specific flags (e.g., `--from`, `--force`, `--editor`)
32-
3. **Branch completion** - Dynamic completion of existing worktree branches (via `gtr list --porcelain`)
32+
3. **Branch completion** - Dynamic completion of git branches plus special ID `1` (via `git branch`)
3333
4. **Adapter completion** - Editor names (`cursor`, `vscode`, `zed`) and AI tool names (`aider`, `claude`, `codex`)
3434

3535
## Testing Completions
3636

3737
**Manual testing** (no automated tests):
3838

3939
```bash
40-
# Bash - source the completion file
40+
# Bash - source the completion file (requires git's bash completion to be loaded)
4141
source completions/gtr.bash
42-
gtr <TAB> # Should show commands
43-
gtr new <TAB> # Should show flags
44-
gtr open <TAB> # Should show branches
45-
gtr open --editor <TAB> # Should show editor names
46-
47-
# Zsh - fpath must include completions directory
48-
fpath=(completions $fpath)
49-
autoload -U compinit && compinit
50-
gtr <TAB>
42+
git gtr <TAB> # Should show commands
43+
git gtr new <TAB> # Should show flags
44+
git gtr go <TAB> # Should show branches + '1'
45+
git gtr editor <TAB> # Should show branches + '1'
46+
git gtr editor --editor <TAB> # Should show editor names
47+
48+
# Zsh - copy to fpath directory and reload (requires git's zsh completion)
49+
mkdir -p ~/.zsh/completions
50+
cp completions/_git-gtr ~/.zsh/completions/
51+
# Add to ~/.zshrc: fpath=(~/.zsh/completions $fpath)
52+
# Add to ~/.zshrc: autoload -Uz compinit && compinit
53+
exec zsh # Reload shell
54+
git gtr <TAB> # Should show commands
55+
git gtr new <TAB> # Should show flags
56+
git gtr go <TAB> # Should show branches + '1'
5157

5258
# Fish - symlink to ~/.config/fish/completions/
5359
ln -s "$(pwd)/completions/gtr.fish" ~/.config/fish/completions/
54-
gtr <TAB>
60+
exec fish # Reload shell
61+
git gtr <TAB> # Should show commands
62+
git gtr new <TAB> # Should show flags
63+
git gtr go <TAB> # Should show branches + '1'
5564
```
5665

66+
**Important**: All shell completions require git's own completion system to be enabled for the `git` command. The completions integrate with git's subcommand completion framework.
67+
5768
## Branch Completion Logic
5869

59-
All three completions dynamically fetch current worktree branches:
70+
All three completions dynamically fetch current git branches:
6071

61-
- Parse output of `gtr list --porcelain` (tab-separated: `path\tbranch\tstatus`)
62-
- Extract branch column (second field)
63-
- Exclude the special ID `1` (main repo) if needed
72+
- Use `git branch --format='%(refname:short)'` to get branch names
73+
- Add special ID `1` for main repo (allows `git gtr go 1`, `git gtr editor 1`, etc.)
74+
- Return combined list of branches + `1` for commands that accept branch arguments (go, editor, ai, rm)
6475

6576
## Adapter Name Updates
6677

@@ -71,15 +82,15 @@ When adding an editor or AI adapter:
7182
- Update `_gtr_editors` array or case statement
7283
- Update flag completion for `--editor` in `open` command
7384

74-
**Zsh** (`completions/_gtr`):
85+
**Zsh** (`completions/_git-gtr`):
7586

7687
- Update `_arguments` completion specs for `--editor` or `--ai`
7788
- Use `_values` or `_alternative` for adapter names
7889

7990
**Fish** (`completions/gtr.fish`):
8091

81-
- Update `complete -c gtr` lines for editor/AI flags
82-
- List adapter names explicitly or parse from `gtr adapter` output
92+
- Update `complete -c git` lines for editor/AI flags
93+
- List adapter names explicitly or parse from `git gtr adapter` output
8394

8495
## Keep in Sync
8596

@@ -92,7 +103,7 @@ The three completion files must stay synchronized:
92103

93104
## Examples
94105

95-
**Adding a new command `gtr status`**:
106+
**Adding a new command `git gtr status`**:
96107

97108
1. Add `status` to main command list in all three files
98109
2. Add flag completion if the command has flags
@@ -104,7 +115,7 @@ The three completion files must stay synchronized:
104115
2. Add `sublime` to editor list in all three completion files
105116
3. Update help text in `bin/gtr` (`cmd_help` function)
106117
4. Update README with installation instructions
107-
5. Test `gtr open --editor s<TAB>` completes to `sublime`
118+
5. Test `git gtr open --editor s<TAB>` completes to `sublime`
108119

109120
## Common Pitfalls
110121

@@ -128,6 +139,6 @@ The three completion files must stay synchronized:
128139

129140
## Fish-Specific Notes
130141

131-
- Uses declarative `complete -c gtr` syntax
132-
- Conditions can check previous arguments with `__fish_seen_subcommand_from`
142+
- Uses `complete -c git` with custom predicates (`__fish_git_gtr_needs_command`, `__fish_git_gtr_using_command`) to handle git subcommand context
143+
- Conditions can check previous arguments with custom functions to detect `git gtr` usage
133144
- Can call external commands for dynamic completion

.github/instructions/editor.instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ editor_open() {
2929
**Also update**:
3030

3131
- README.md (setup instructions)
32-
- All three completion files: `completions/gtr.bash`, `completions/_gtr`, `completions/gtr.fish`
32+
- All three completion files: `completions/gtr.bash`, `completions/_git-gtr`, `completions/gtr.fish`
3333
- Help text in `bin/gtr` (`cmd_help` function)
3434

3535
## Contract & Guidelines

0 commit comments

Comments
 (0)