feat: the gh account follows the directory outside interactive zsh too - #4
Merged
Merged
Conversation
Binding the account on chpwd only ever worked in an interactive zsh. A script, an editor or a coding agent got whatever account was last made active -- and because that is global state shared by every terminal, switching accounts to open a pull request in one window silently repointed the others. Observed, not theorised: an agent working in one workspace had the account changed under it by a terminal sitting in another. ~/.config/git/bin/gh decides at the point of use and switches nothing. gh is handed the bound account's token through GH_TOKEN for the life of one process, so nothing global changes and a shell that never sourced the plugin still gets the right identity. gh auth is excluded: switch refuses to run while GH_TOKEN is set, and status would report the token's account as the active one. install wires the directory onto PATH through both ~/.zshenv and ~/.zprofile. .zshenv is the only startup file a non-interactive zsh reads; macOS then rebuilds PATH in /etc/zprofile, which would leave the wrapper behind the gh it shadows. doctor checks what actually matters -- whether gh resolves to the wrapper in this shell. Resolution moved to lib/resolve.sh. Sourcing guard.sh runs git and exits on a mismatch, which is right for a hook and useless to anything else. Two defects surfaced on the way. --sign wrote gpg.format = ssh without checking that git understands it: on 2.23 every commit in the workspace then died on "bad config variable" pointing at a file the user never wrote, so add refuses and doctor reports it. And `skip` was called in three places and defined in none, which nothing had reached until the signing tests learned to take the other path.
The lint job carried its own copy of the shellcheck arguments. Adding lib/resolve.sh to package.json therefore left CI linting guard.sh without the file it sources, and SC1091 turned a green change red. One list, in package.json. tests/run.sh joins it, which CI was checking and npm was not.
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.
The chpwd hook only ever reached an interactive zsh, so scripts, editors and agents got whatever account was last made active — global state every terminal shares. A gh wrapper on PATH now hands gh the bound account token for one process and switches nothing.
Wired onto PATH through both ~/.zshenv and ~/.zprofile: .zshenv is the only file a non-interactive zsh reads, and macOS rebuilds PATH in /etc/zprofile afterwards. doctor checks whether gh actually resolves to the wrapper.
Also fixes --sign writing gpg.format = ssh on git < 2.34, which failed every commit in the workspace, and defines the skip helper that was called in three places and defined in none.
This PR was opened through the wrapper, with the global active account left on the other one.