Documentation
¶
Overview ¶
Package gitx runs the git CLI. It knows nothing about features, forges, or Ghostbranch's rules; it only makes git calls predictable.
Index ¶
- Constants
- func Cleanup() error
- func Version(ctx context.Context) (string, error)
- type ConflictError
- type Error
- type Git
- func (g *Git) AddRemote(ctx context.Context, name, url string) error
- func (g *Git) CherryPick(ctx context.Context, commits []string, committer Identity) ([]string, error)
- func (g *Git) CommitAuthor(ctx context.Context, sha string) (Identity, error)
- func (g *Git) CommitIdentities(ctx context.Context, sha string) (author, committer string, err error)
- func (g *Git) CommitMessage(ctx context.Context, sha string) (string, error)
- func (g *Git) CommitTree(ctx context.Context, tree string, parents []string, message string, ...) (string, error)
- func (g *Git) CommitsBetween(ctx context.Context, base, head string) ([]string, error)
- func (g *Git) DeleteRef(ctx context.Context, ref string) error
- func (g *Git) DiffNames(ctx context.Context, a, b string) ([]string, error)
- func (g *Git) Fetch(ctx context.Context, remote string, refspecs ...string) error
- func (g *Git) HashObject(ctx context.Context, content []byte) (string, error)
- func (g *Git) IsAncestor(ctx context.Context, a, b string) (bool, error)
- func (g *Git) ListTree(ctx context.Context, rev string) ([]TreeEntry, error)
- func (g *Git) LsRemote(ctx context.Context, remote string) (map[string]string, error)
- func (g *Git) MakeTree(ctx context.Context, entries []TreeEntry) (string, error)
- func (g *Git) MergeTreeCheck(ctx context.Context, base, head string) (bool, []string, error)
- func (g *Git) MustResolve(ctx context.Context, rev string) (string, error)
- func (g *Git) PatchIDs(ctx context.Context, commits []string) ([]string, error)
- func (g *Git) ProtectAttributes(ctx context.Context) error
- func (g *Git) Push(ctx context.Context, remote string, opt PushOptions, refspecs ...string) error
- func (g *Git) ReadBlobs(ctx context.Context, shas []string) (map[string][]byte, error)
- func (g *Git) Refs(ctx context.Context, prefix string) (map[string]string, error)
- func (g *Git) Resolve(ctx context.Context, rev string) (string, bool, error)
- func (g *Git) Run(ctx context.Context, args ...string) (string, error)
- func (g *Git) RunInput(ctx context.Context, stdin io.Reader, args ...string) (string, error)
- func (g *Git) ShowFile(ctx context.Context, rev, path string) ([]byte, bool, error)
- func (g *Git) SourceCommits(ctx context.Context, base, head string) ([]string, error)
- func (g *Git) TreeOf(ctx context.Context, rev string) (string, error)
- func (g *Git) UpdateRef(ctx context.Context, ref, sha string) error
- func (g *Git) With(dir string) *Git
- func (g *Git) WorktreeAdd(ctx context.Context, dir, rev string) (*Git, error)
- func (g *Git) WorktreeRemove(ctx context.Context, dir string) error
- type Identity
- type Lease
- type PermissionError
- type PushOptions
- type RefusedError
- type RejectedError
- type TreeEntry
Constants ¶
const AttributesOverride = "* -filter -ident -text -working-tree-encoding merge=text -diff\n"
AttributesOverride is written to every engine mirror's info/attributes, which outranks in-tree .gitattributes files. No tracked file can then name a filter, a merge driver, or an eol or encoding conversion, so blobs pass through a rebase byte for byte. merge=text is git's own 3-way merge.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConflictError ¶
type ConflictError struct {
Files []string
// Commit is the commit that stopped a cherry-pick replay; empty for a rebase.
Commit string
}
ConflictError means a rebase or cherry-pick replay stopped on conflicts. It has been aborted; Files lists the conflicting paths.
func (*ConflictError) Error ¶
func (e *ConflictError) Error() string
type Error ¶
Error is a failed git invocation. Args never contain secrets: credentials travel in the environment.
type Git ¶
Git runs git against one repository directory (bare repo or worktree). Config entries are passed through GIT_CONFIG_* environment variables, so values such as auth headers never appear in a process listing.
func Init ¶
Init creates a repository at dir, which may not exist yet. A mirror holds unreleased shadow commits (F-28), so the repo is private whatever the umask: its directory and every parent Init creates are 0700, the files git init wrote lose their group and other bits, and core.sharedRepository=0600 makes git write every later file 0600 and directory 0700. The key is set after init rather than with --shared, which would also set receive.denyNonFastForwards and so change how a bare repo made here takes pushes.
func (*Git) CherryPick ¶
func (g *Git) CherryPick(ctx context.Context, commits []string, committer Identity) ([]string, error)
CherryPick applies commits, in order, onto this worktree's HEAD, keeping each commit's author and message and committing as committer. A commit that becomes empty is kept. It returns the new SHA for each input commit. On conflict it aborts and returns *ConflictError naming that commit; any other failure names the commit and aborts nothing that wasn't started.
func (*Git) CommitAuthor ¶
CommitAuthor reads a commit's author from the raw object, with its time in UTC.
func (*Git) CommitIdentities ¶
func (g *Git) CommitIdentities(ctx context.Context, sha string) (author, committer string, err error)
CommitIdentities returns a commit's author and committer as "Name <email>", read from the raw object.
func (*Git) CommitMessage ¶
CommitMessage returns a commit's message exactly as stored: the raw object after the header's blank line. Unlike log --format=%B, no config (such as i18n.logOutputEncoding) can re-encode it.
func (*Git) CommitTree ¶
func (g *Git) CommitTree(ctx context.Context, tree string, parents []string, message string, author, committer Identity) (string, error)
CommitTree writes a commit object. The message is stored with exactly one trailing newline.
func (*Git) CommitsBetween ¶
CommitsBetween lists the commits in head but not base along head's first-parent line, oldest first; never nil.
func (*Git) Fetch ¶
Fetch fetches refspecs from remote, pruning refs that disappeared. Tags are fetched only when a refspec names them.
func (*Git) HashObject ¶
HashObject stores content as a blob, byte for byte.
func (*Git) IsAncestor ¶
IsAncestor reports whether a is an ancestor of (or equal to) b.
func (*Git) MergeTreeCheck ¶
MergeTreeCheck reports whether head merges cleanly onto base, without a worktree: git merge-tree --write-tree exits 0 when clean and 1 when it conflicts, listing the conflicted files after the tree line. Any other failure (a bad ref, say) is an error.
func (*Git) MustResolve ¶
MustResolve resolves rev and fails if it does not exist.
func (*Git) PatchIDs ¶
PatchIDs returns each commit's stable patch-id against its first parent, in order (git patch-id --stable): the same change on another base, or with another message, has the same patch-id. A commit that changes nothing has "".
func (*Git) ProtectAttributes ¶
ProtectAttributes writes AttributesOverride to the repository's info/attributes, which its worktrees share.
func (*Git) Push ¶
Push pushes refspecs to remote. Refspec sources may be SHAs; destinations must be full ref names.
func (*Git) SourceCommits ¶
SourceCommits lists the commits replaying head onto base applies, oldest first: those in head but not base, without merges, and without commits whose patch base already has (as git rebase leaves them out).
func (*Git) WorktreeAdd ¶
WorktreeAdd checks out rev, detached, into a new worktree at dir and returns a Git for it.
type Identity ¶
Identity is an author or committer with a fixed time, so commits made from the same inputs always get the same SHA.
type PermissionError ¶
type PermissionError struct{ Detail string }
PermissionError means the remote refused the push because the credentials may not write to it (GitHub answers 403).
func (*PermissionError) Error ¶
func (e *PermissionError) Error() string
type PushOptions ¶
PushOptions controls a push.
type RefusedError ¶
type RefusedError struct {
Refs []string
Reason string // the server's reason, e.g. text inside "[remote rejected] (...)"
}
RefusedError means the remote refused at least one ref for a reason of its own (permissions, a ruleset, a hook); retrying won't help.
func (*RefusedError) Error ¶
func (e *RefusedError) Error() string
type RejectedError ¶
RejectedError means the remote refused at least one ref, for example because a lease did not match.
func (*RejectedError) Error ¶
func (e *RejectedError) Error() string