Documentation
¶
Overview ¶
Package credential implements a git credential helper for gitswitch.
gitswitch never stores tokens. It acts purely as a router: given a git credential request (protocol/host), it resolves which gitswitch profile applies to the current repo, then delegates to the gh CLI to fetch that account's token (`gh auth token --hostname <host> --user <ghUser>`). The token lives in gh's own secure storage; gitswitch only forwards it to git.
For any case it cannot serve (gh missing, no profile, account not authenticated for the host), the helper writes nothing and exits 0 so git falls through to the next helper in the chain (osxkeychain, gh, prompt).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
Get handles the `get`/`fill` operation: resolve the applicable profile, fetch its token via gh, and write a credential response to w. repoDir is the directory git invoked the helper from, used to read the repo's local identity. On any miss (no profile, gh unavailable, account not authed for host) it writes nothing so git falls through to the next helper. Always returns nil (exit 0).
func ResolveGHUser ¶ added in v0.3.0
ResolveGHUser picks which profile's gh_user applies to repoDir/repoKey.
- If the repo or this terminal's session overrides the global identity, that wins outright — commits here are authored as that profile, so pushes must use its token.
- Otherwise determine the globally active profile.
- Ask history for a per-repo recommendation (pinned/learned identity for repoKey). history.Recommend returns ("",false) when the recommendation equals the active nickname, so the active profile is the natural fallback and the two branches converge on the same result.
Returns "" if no profile applies (callers then stay silent). Shared by the git credential helper (Get, below) and the `gh` CLI wrapper (cmd/gitswitch ghuser), so HTTPS pushes and bare `gh` commands always resolve identically.
Types ¶
type Request ¶
type Request struct {
Protocol string
Host string // may include :port; use HostNoPort() for matching/queries
Path string
Username string
}
Request is the parsed git credential protocol input.
func ParseRequest ¶
ParseRequest reads key=value lines from r until a blank line or EOF. Unknown keys are ignored. Lines without '=' are skipped.
func (Request) HostNoPort ¶
HostNoPort returns Host with any trailing :port stripped (github.com:443 -> github.com). IPv6 hosts are left untouched.