feat(cli): shell completions - #83
Merged
Merged
Conversation
`RepositoryParser` discovers the repository the way git does, walking up
from wherever it was invoked. `IndexStorage` did not — it looked for
`./.git` and gave up. So every command worked from the repository root
and reported "not a git repository" one directory down, which is where
most people actually are:
$ cd src && git-semantic search "race condition"
error: not a git repository: .git directory not found
Discovery also resolves the `gitdir:` pointer in a linked worktree's or
submodule's `.git` file. Submodules write that pointer relative to the
submodule directory (`gitdir: ../.git/modules/<name>`); reading the file
by hand resolved it against the process's working directory instead and
put the index outside the repository.
`InvalidGitFile` now marks a `.git` entry that exists but does not
resolve, so a broken worktree keeps its own hint instead of being told it
is not in a repository.
The storage tests built a bare `.git` directory that no git tool would
accept. They now initialize real repositories, which is what the file
headers claimed all along.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`git-semantic completions <shell>` writes a completion script for bash, zsh, fish, elvish, or powershell to stdout. Generated from the same clap definition the parser is built from, so the flags a shell offers cannot drift from the flags that exist. Named for the binary rather than the git alias: `git semantic …` completes through git's own subcommand machinery, which finds `git-semantic` on PATH. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Rust ignores SIGPIPE at startup, so writing to a closed pipe returns EPIPE and `println!` panics on it. `git-semantic completions zsh | head` printed a Rust panic and a backtrace note instead of the first few lines, and `search --json | head` did the same — the two outputs most likely to be piped were the two that broke. Restoring the default disposition on unix makes the process die the way every other tool in the pipeline does. Not covered by a test: whether the child hits EPIPE at all depends on losing a race against the reader's exit, and the completion script is 8 KB, well under a pipe buffer. A test would pass without exercising anything. Verified by hand instead. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
bash, zsh, fish, elvish, and powershell. Generated from the same clap definition the parser is built from, so the flags a shell offers cannot drift from the flags that exist.
Named for the binary rather than the git alias —
git semantic …completes through git's own subcommand machinery, which findsgit-semanticonPATH.Also here: a closed pipe no longer panics
Generating a completion script is the obvious thing to pipe, and piping it revealed that the binary panics on
EPIPE:Rust ignores
SIGPIPEat startup, so a closed pipe turns into anEPIPEthatprintln!panics on.search --json | headdid the same thing — the two outputs most likely to be piped were the two that broke. Restoring the default disposition on unix makes the process die the way every other tool in the pipeline does.Tests
Three new cases: every shell emits a script containing a marker unique to its own format, the script covers every subcommand, and an unknown shell is rejected with the list of known ones.
The pipe fix has no test. Whether the child hits
EPIPEat all depends on losing a race against the reader's exit, and the completion script is 8 KB — well under a pipe buffer — so a test would pass without exercising anything. Verified by hand instead.Second of four stacked PRs, on top of #82.