gitx

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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 Commit added in v0.1.3

type Commit struct {
	SHA     string
	Author  string // "Name <email>"
	Subject string
}

Commit is one commit on a branch.

func (Commit) Short added in v0.1.3

func (c Commit) Short() string

Short is the commit's first seven characters.

type ExecRunner

type ExecRunner struct{}

ExecRunner runs real subprocesses.

func (ExecRunner) Run

func (ExecRunner) Run(ctx context.Context, dir string, env []string, name string, args ...string) (string, error)

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 New

func New() *Git

New returns a Git over real subprocesses.

func (*Git) AuthorIdent added in v0.1.3

func (g *Git) AuthorIdent() string

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

func (g *Git) CherryPick(ctx context.Context, repo, sha string) error

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) CommitAll

func (g *Git) CommitAll(ctx context.Context, repo, subject, body string) (string, error)

CommitAll stages everything and commits, returning the new SHA.

func (*Git) CommitsNotIn added in v0.1.3

func (g *Git) CommitsNotIn(ctx context.Context, repo, base, tip string) ([]Commit, error)

CommitsNotIn lists the non-merge commits reachable from tip and not from base, oldest first.

func (*Git) CreateBranch

func (g *Git) CreateBranch(ctx context.Context, repo, name string) error

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

func (g *Git) CurrentBranch(ctx context.Context, repo string) (string, error)

CurrentBranch returns the checked-out branch, or "HEAD" when detached.

func (*Git) FetchBranch

func (g *Git) FetchBranch(ctx context.Context, repo, branch string) error

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

func (g *Git) HasUncommittedChanges(ctx context.Context, repo string) (bool, error)

HasUncommittedChanges reports whether the tree differs from HEAD.

func (*Git) ListTree added in v0.1.3

func (g *Git) ListTree(ctx context.Context, repo, ref, prefix string) ([]string, error)

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) OpenPR

func (g *Git) OpenPR(ctx context.Context, repo, branch, title, body, base string) (string, error)

OpenPR opens a pull request, or returns the open one already on the branch.

func (*Git) PRForBranch

func (g *Git) PRForBranch(ctx context.Context, repo, branch string) string

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

func (g *Git) PushBranch(ctx context.Context, repo, branch string, forceWithLease bool) error

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

func (g *Git) PushBranchLease(ctx context.Context, repo, branch, expect string) error

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.

func (*Git) RevParse added in v0.1.3

func (g *Git) RevParse(ctx context.Context, repo, ref string) string

RevParse returns the commit a ref names, or "" when it names none.

type Runner

type Runner interface {
	Run(ctx context.Context, dir string, env []string, name string, args ...string) (string, error)
}

Runner executes git and gh. Swapped in tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL