Documentation
¶
Overview ¶
Package gitx shells out to git and gh.
Deliberately subprocesses rather than a Go git library: the sync runs on a CI runner whose credentials arrive as git config (http.https://github.com/.extraheader, set by the workflow), and pull requests are opened with gh. A library would have to reimplement both, and the workflow's own comments record what it cost to get that plumbing right.
Index ¶
- Constants
- type Commit
- type ExecRunner
- type Git
- func (g *Git) AuthorIdent() string
- func (g *Git) CherryPick(ctx context.Context, repo, sha string) error
- func (g *Git) CommitAll(ctx context.Context, repo, subject, body string) (string, error)
- func (g *Git) CommitsNotIn(ctx context.Context, repo, base, tip string) ([]Commit, error)
- func (g *Git) CreateBranch(ctx context.Context, repo, name string) error
- func (g *Git) CurrentBranch(ctx context.Context, repo string) (string, error)
- func (g *Git) FetchBranch(ctx context.Context, repo, branch string) error
- func (g *Git) HasUncommittedChanges(ctx context.Context, repo string) (bool, error)
- func (g *Git) ListTree(ctx context.Context, repo, ref, prefix string) ([]string, error)
- func (g *Git) OpenPR(ctx context.Context, repo, branch, title, body, base string) (string, error)
- func (g *Git) PRForBranch(ctx context.Context, repo, branch string) string
- func (g *Git) PushBranch(ctx context.Context, repo, branch string, forceWithLease bool) errordeprecated
- func (g *Git) PushBranchLease(ctx context.Context, repo, branch, expect string) error
- func (g *Git) RevParse(ctx context.Context, repo, ref string) string
- type Runner
Constants ¶
const DefaultAuthor = "ichava-sync-bot <41898282+github-actions[bot]@users.noreply.github.com>"
DefaultAuthor is the identity sync commits are attributed to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Git ¶
type Git struct {
Run Runner
Author string
// Env is added to every command's environment (tests isolate git from
// the machine's own config with it).
Env []string
}
Git wraps the repository operations the sync needs.
func (*Git) AuthorIdent ¶ added in v0.1.3
AuthorIdent is "Name <email>": the identity sync commits carry, and so what tells them from a person's commits on the same branch.
func (*Git) CherryPick ¶ added in v0.1.3
CherryPick replays a commit onto the current branch, keeping its author. A commit whose change is already there is dropped rather than kept empty. On a conflict the pick is aborted, so the checkout is left as it was, and the error is returned.
func (*Git) CommitsNotIn ¶ added in v0.1.3
CommitsNotIn lists the non-merge commits reachable from tip and not from base, oldest first.
func (*Git) CreateBranch ¶
CreateBranch creates or resets a branch to HEAD.
-B rather than -b, so a re-run over a branch a previous run left behind succeeds instead of failing on "already exists". The sync pushes to one stable branch per pack so each run updates a single pull request.
func (*Git) CurrentBranch ¶ added in v0.1.1
CurrentBranch returns the checked-out branch, or "HEAD" when detached.
func (*Git) FetchBranch ¶
FetchBranch fetches one remote branch into its tracking ref.
The sync pushes to a stable branch and relies on --force-with-lease, which compares against the remote-tracking ref. actions/checkout fetches only the default branch, so that ref does not exist on a runner and the lease has nothing to compare -- git then rejects the push as "stale info", which reads like a race and is not one.
func (*Git) HasUncommittedChanges ¶
HasUncommittedChanges reports whether the tree differs from HEAD.
func (*Git) ListTree ¶ added in v0.1.3
ListTree returns every file path under prefix at ref, relative to the repo root. An error means ref names nothing (a repo with no commits yet) or git failed; an empty slice means the prefix holds no files at ref.
func (*Git) PRForBranch ¶
PRForBranch returns an existing pull request URL for a branch, or "".
Filtered to open pull requests. Python asked gh for whatever it had, which matched a *merged* one once the first sync landed -- so every later run reported "already open", skipped creation and exited 0 while the branch it had just pushed had nothing tracking it.
func (*Git) PushBranch
deprecated
PushBranch pushes and sets upstream.
Deprecated: use PushBranchLease, which names the tip the caller inspected. A bare --force-with-lease compares with the remote-tracking ref, and the sync fetches that ref just before pushing, so the lease always held and a person's commit on the branch was overwritten. Kept working, with no caller left; earliest removal 0.2.0.
--force-with-lease, because the branch is stable across runs and a later run legitimately replaces an earlier one's commit. The lease is what stops it overwriting a human's edit to the same branch.
func (*Git) PushBranchLease ¶ added in v0.1.3
PushBranchLease pushes branch, replacing the remote one only if it is still at expect (empty: only if there is none). The lease names the tip the caller inspected, so a commit pushed after that inspection is never overwritten: the push fails instead.