{"modulePath":"github.com/bborbe/github-update-go-agent","version":"v0.28.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package git\n\nPackage git wraps git shell-outs behind the GitOps interface so the execution and ai\\_review steps can be tested with a counterfeiter mock. Implementations are responsible for assembling argv slices, capturing stderr, and wrapping errors via bborbe/errors. They MUST NOT use sh -c or any shell-interpolated form — argv only.\n\nAuth model: HTTPS clones with a GitHub token are handled by URL transformation at the call site (cloneURL → [https://x-access-token](https://x-access-token):\\\u003ctok\u003e@github.com/...). The package itself takes the transformed URL — it does not know about tokens directly.\n\nDeliberately NO Tag method exists on this interface (design § 7.0): versioning + tagging is the github-releaser agent's job on merge. The only push helper hardcodes --no-follow-tags and pushes a single branch ref — a tag physically cannot leak from this agent.\n\n## Functions\n\n```go\nfunc ProxyEnv() []string\n```\nProxyEnv returns the KEY=value entries for every proxy variable in proxyEnvKeys that is set in the current process. Subprocesses that run with an explicit env allowlist (git, gh) append it; without it they connect directly and are refused in a proxy-only namespace.\n\n```go\nfunc RedactToken(s string) string\n```\nRedactToken exposes the unexported redactToken helper for callers outside this package that need to log wrapped err.Error() strings through the same redaction. Behavior is identical to redactToken.\n\n## Types\n\n```go\ntype BotIdentity struct {\n\tName  string\n\tEmail string\n}\n```\nBotIdentity holds the commit author/committer identity. Hardcoded intentionally: the only consumer is github-update-go-agent, and a single value is the contract (mirrors github-releaser-agent).\n\n```go\nfunc DefaultBotIdentity() BotIdentity\n```\nDefaultBotIdentity returns the fleet-standard bot identity. The osExecGitOps struct reads this internally on every Commit — there is no override path. Exposed publicly for test assertions.\n\n```go\ntype ErrorCategory string\n```\nErrorCategory is the closed enum returned by ClassifyError. The steps branch on these values to compose actionable failure messages.\n\nThe set is CLOSED — adding a new category requires a design amendment.\n\n```go\nconst (\n\t// ErrorCategoryAuth — git server rejected credentials (401/403, missing username).\n\tErrorCategoryAuth ErrorCategory = \"auth\"\n\t// ErrorCategoryRepoNotFound — clone target does not exist on the server (404).\n\t// NOTE: GitHub returns \"Repository not found\" for BOTH a typo'd repo URL\n\t// AND an unauthenticated request for a private repo. The watcher emit +\n\t// App-IAT auth eliminate the private-repo confounder upstream, so a 404\n\t// truly means the repo does not exist (mirrors github-releaser-agent).\n\tErrorCategoryRepoNotFound ErrorCategory = \"repo_not_found\"\n\t// ErrorCategoryProtectedBranchRejected — branch protection rejected the push.\n\tErrorCategoryProtectedBranchRejected ErrorCategory = \"protected_branch_rejected\"\n\t// ErrorCategoryPushNonFastForward — remote moved between clone and push;\n\t// controller retry will re-fetch.\n\tErrorCategoryPushNonFastForward ErrorCategory = \"push_non_fast_forward\"\n\t// ErrorCategoryUnexpectedDiff — the update commit touched a forbidden path\n\t// (.github/workflows/**). Set DIRECTLY by the execution step's\n\t// committed-files guard, NOT by ClassifyError — it is a semantic assertion\n\t// on the file set, so there is no stderr fragment to match.\n\tErrorCategoryUnexpectedDiff ErrorCategory = \"unexpected_diff\"\n\t// ErrorCategoryPermissionDenied — a Claude sub-call tool invocation was\n\t// refused by the CLI allowlist. Amendment 2026-08-20: added after a run\n\t// whose only fault was a denied `grep` retried until the Job's 1800s\n\t// deadline killed it, recording error_category \"unknown\" and discarding a\n\t// green update. \"unknown\" made a permissions bug look like a timeout,\n\t// which is exactly the confusion this category removes.\n\t//\n\t// Unlike the git categories, the matched text comes from the Claude CLI's\n\t// stdout tail (wrapped into the error by the runner), not from git stderr.\n\tErrorCategoryPermissionDenied ErrorCategory = \"permission_denied\"\n\t// ErrorCategoryUnknown — message does not match any known fragment. Bug\n\t// signal: if this fires repeatedly, add a new substring to the table.\n\tErrorCategoryUnknown ErrorCategory = \"unknown\"\n)\n```\n\n```go\nfunc ClassifyError(err error) ErrorCategory\n```\nClassifyError maps a git stderr-wrapped error to the closed enum.\n\nReturns the empty-string sentinel \\`ErrorCategory(\"\")\\` when err is nil — this distinguishes \"no error to classify\" from ErrorCategoryUnknown (\"an error occurred but no fragment matched\").\n\nunexpected\\_diff is NEVER returned by this function — that category is set by the execution step's guard layer, not at the git-stderr layer.\n\n```go\ntype GitOps interface {\n\t// CloneAtRef shells out `git clone \u003ccloneURL\u003e \u003cworkdir\u003e` (full history —\n\t// the ref may be an arbitrary SHA) and checks out ref. ref may be a\n\t// commit SHA or a branch name (branch names resolve via checkout DWIM\n\t// against origin). cloneURL MUST already include any auth token.\n\tCloneAtRef(ctx context.Context, cloneURL, ref, workdir string) error\n\n\t// ResolveDefaultBranch shells out `git ls-remote --symref \u003ccloneURL\u003e HEAD`\n\t// and returns the remote's default branch name (without the refs/heads/\n\t// prefix) plus the commit SHA at its tip. The branch name is the PR base\n\t// and the prefix of every `origin/\u003cdefault\u003e` comparison the execution and\n\t// review steps make, so a repo whose default is `main` updates exactly as\n\t// one whose default is `master`. cloneURL MUST already include any auth\n\t// token.\n\tResolveDefaultBranch(ctx context.Context, cloneURL string) (branch, headSHA string, err error)\n\n\t// SwitchNewBranch creates and switches to a new local branch\n\t// (git switch -c \u003cbranch\u003e).\n\tSwitchNewBranch(ctx context.Context, workdir, branch string) error\n\n\t// ChangedFiles returns the repo-relative paths of all uncommitted\n\t// changes (staged, unstaged, and untracked) via `git status --porcelain`.\n\t// The execution step uses it to build the explicit commit pathspec and\n\t// to run the workflow-edit guard BEFORE anything is committed.\n\tChangedFiles(ctx context.Context, workdir string) ([]string, error)\n\n\t// Commit stages paths (relative to workdir) via explicit `git add -- \u003cpaths\u003e`\n\t// and creates a commit with the bot identity. Returns the short SHA\n\t// (7 chars) of the new commit. The bot identity is set per-invocation\n\t// via -c user.name / -c user.email — never writes to the global gitconfig.\n\tCommit(ctx context.Context, workdir, message string, paths ...string) (sha string, err error)\n\n\t// CommittedFiles returns the repo-relative paths changed by the HEAD\n\t// commit (git diff-tree --no-commit-id --name-only -r HEAD). The\n\t// execution step uses it as a pre-push guard.\n\tCommittedFiles(ctx context.Context, workdir string) ([]string, error)\n\n\t// Push pushes the current HEAD to origin as refs/heads/\u003cbranch\u003e,\n\t// hardcoding --no-follow-tags so a local tag can never reach origin.\n\tPush(ctx context.Context, workdir, branch string) error\n\n\t// LsRemoteTags shells out `git ls-remote --tags \u003ccloneURL\u003e` and returns\n\t// all SHAs sitting at tag refs (both tag-object SHAs and dereferenced\n\t// ^{} commit SHAs). The ai_review step checks that no branch commit\n\t// carries a tag. cloneURL MUST already include any auth token.\n\tLsRemoteTags(ctx context.Context, cloneURL string) ([]string, error)\n\n\t// RemoteBranchSHA shells out `git ls-remote --heads \u003ccloneURL\u003e refs/heads/\u003cbranch\u003e`\n\t// and returns the commit SHA the remote holds at that branch, or \"\" when the\n\t// branch does not exist on the remote. The execution step uses it to detect a\n\t// branch a prior run pushed before crashing ahead of PR creation.\n\t// cloneURL MUST already include any auth token.\n\tRemoteBranchSHA(ctx context.Context, cloneURL, branch string) (string, error)\n\n\t// RevList returns the commit SHAs on HEAD that are not reachable from\n\t// base (git rev-list \u003cbase\u003e..HEAD) — the branch's own commits.\n\tRevList(ctx context.Context, workdir, base string) ([]string, error)\n\n\t// ShowFile returns the content of path at the given ref\n\t// (git show \u003cref\u003e:\u003cpath\u003e) — e.g. origin/\u003cdefault\u003e:CHANGELOG.md.\n\tShowFile(ctx context.Context, workdir, ref, path string) ([]byte, error)\n\n\t// FileExistsAtRef reports whether path exists at ref\n\t// (git cat-file -e \u003cref\u003e:\u003cpath\u003e). A missing path returns (false, nil) so\n\t// the review step can treat an absent base CHANGELOG.md as an empty base\n\t// header set; any other git failure returns an error so the caller stays\n\t// fail-closed on a genuine error.\n\tFileExistsAtRef(ctx context.Context, workdir, ref, path string) (bool, error)\n}\n```\nGitOps is the seam between the steps and the git binary.\n\nAll methods are context-aware — callers can cancel mid-operation. workdir is the absolute path to the checkout (created and owned by the caller; the package does not manage workdir lifecycle).\n\n```go\nfunc NewOSExecGitOps() GitOps\n```\nNewOSExecGitOps returns a GitOps implementation that shells out to the git binary via os/exec. Zero-arg: the bot identity is constant via DefaultBotIdentity().\n\n","path":"github.com/bborbe/github-update-go-agent/pkg/git","name":"git","synopsis":"Package git wraps git shell-outs behind the GitOps interface so the execution and ai_review steps can be tested with a counterfeiter mock.","isRedistributable":true}
