Documentation
¶
Index ¶
- func BranchExists(remote, name string) (bool, error)
- func CommitAndPush(filePath, message string) error
- func CommitAndPushWithRetry(filePath, message string, opts ...Option) error
- func CurrentBranch() (string, error)
- func DeleteRemoteBranch(remote, name string) error
- func DeleteRemoteTag(remote, name string) error
- func GetChangedFiles(baseSHA, headSHA string) ([]string, error)
- func GetInitialCommit() (string, error)
- func GetLatestReleaseTag(dir, prefix string) (string, string, error)
- func GetLatestReleaseTagSpec(dir string, spec taggrammar.Spec) (string, string, error)
- func GetLatestTag(dir, prefix string) (string, string, error)
- func GetLatestTagSpec(dir string, spec taggrammar.Spec) (string, string, error)
- func IsAncestor(ancestor, descendant string) (bool, error)
- func IsValidVersionTag(tag string) bool
- func IsValidVersionTagSpec(spec taggrammar.Spec, tag string) bool
- func ListRemoteBranches(remote string) ([]string, error)
- func ListTags() ([]string, error)
- func PushWithRebaseRetry(opts ...Option) error
- func RefetchAndReset(dir string) error
- func RemoteBranchSHA(remote, name string) (string, error)
- type Commit
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BranchExists ¶ added in v0.2.0
BranchExists reports whether the remote-tracking ref refs/remotes/<remote>/<name> exists by running "git rev-parse --verify". An exit code of 0 means the ref exists, a non-zero exit code means it does not, and an execution failure is returned as an error.
This checks remote-tracking refs, so the remote must have been fetched first. A shallow or partial fetch that omits the branch will cause this to report false.
func CommitAndPush ¶
CommitAndPush stages a file, commits with the given message, and pushes to origin.
func CommitAndPushWithRetry ¶ added in v0.2.0
CommitAndPushWithRetry stages filePath, commits it with message, and pushes to the current branch's upstream, retrying a rejected push up to pushRetryAttempts times behind a pull --rebase. A "nothing to commit" state is treated as success (no-op). This is the manifest state-write path shared by promote and hotfix finalize: an API-created commit on real GitHub goes through a different path, so this is the plain-git fallback used when committing locally.
Optional behaviour is supplied through Options: WithDir runs the commands in a specific repository, and WithBackoff tunes the retry delay. With no options the call behaves identically to the original positional signature.
func CurrentBranch ¶ added in v0.2.0
CurrentBranch returns the name of the currently checked-out branch. It returns an error if the HEAD is detached or the command fails.
func DeleteRemoteBranch ¶ added in v0.2.0
DeleteRemoteBranch deletes the named branch on the given remote by running "git push <remote> --delete <name>". Deleting a branch that does not exist on the remote is treated as success so the operation is idempotent: re-running a rejoin cleanup after a partial failure does not error on an already-deleted branch.
func DeleteRemoteTag ¶ added in v0.2.0
DeleteRemoteTag deletes the named tag on the given remote by running "git push <remote> --delete refs/tags/<name>". Deleting a tag that does not exist on the remote is treated as success so the operation is idempotent.
func GetChangedFiles ¶
GetChangedFiles returns the list of files changed between two commits
func GetInitialCommit ¶
GetInitialCommit returns the SHA of the first commit in the repository
func GetLatestReleaseTag ¶
GetLatestReleaseTag returns the most recent non-prerelease tag (no -rc suffix). This is used to find the base version for calculating next release versions. Tag lookups run against dir so the caller's repository is read even when the process working directory points elsewhere; an empty dir falls back to the process working directory.
func GetLatestReleaseTagSpec ¶ added in v0.10.0
GetLatestReleaseTagSpec is GetLatestReleaseTag under a caller-supplied grammar. The prefix glob widens the candidate set to every tag that leads with the grammar's prefix; the release predicate then narrows it to a published release, so a custom pre-release token is classified correctly rather than slipping through a hard-wired "-rc." check.
func GetLatestTag ¶
GetLatestTag returns the most recent tag matching the given prefix, sorted by semver. Tag lookups run against dir so the caller's repository is read even when the process working directory points elsewhere; an empty dir falls back to the process working directory. Returns empty string if no matching tags found.
func GetLatestTagSpec ¶ added in v0.12.0
GetLatestTagSpec is GetLatestTag under a caller-supplied grammar. The prefix glob widens the candidate set to every tag leading with spec.Prefix; the tag predicate then narrows it to a version-parseable tag under spec, so a strict per-component prefix (StrictPrefix) accepts only that component's tags and can never read a sibling component's namespace. Returns empty string if no matching version tag is found.
func IsAncestor ¶ added in v0.2.0
IsAncestor reports whether ancestor is an ancestor of descendant by running "git merge-base --is-ancestor". An exit code of 0 means true, an exit code of 1 means false, and any other exit code or execution failure is returned as an error.
Both commits must be present in the local object store. In a shallow clone the relevant history may be missing, so callers that rely on this must ensure full history is fetched (for example fetch-depth: 0).
func IsValidVersionTag ¶ added in v0.6.0
IsValidVersionTag reports whether tag is a well-formed cascade version tag under the default grammar. Tags that do not match (for example a vX.Y.Z-dryrun.N exercise tag, a foreign "nightly" or "latest" tag, or a typo) are invisible to version discovery so they can never be mistaken for the latest released or prereleased version.
func IsValidVersionTagSpec ¶ added in v0.10.0
func IsValidVersionTagSpec(spec taggrammar.Spec, tag string) bool
IsValidVersionTagSpec reports whether tag is a well-formed version tag under spec. Version discovery and git both read this from the canonical grammar, so the predicate can never drift from the parser the way a hand-copied regex once could.
func ListRemoteBranches ¶ added in v0.2.0
ListRemoteBranches returns the branch names known for the given remote via the remote-tracking refs refs/remotes/<remote>/*. The remote prefix and the symbolic HEAD pointer are stripped, so "refs/remotes/origin/env/test" is returned as "env/test". The remote must have been fetched first; a shallow or partial fetch that omits branches will leave them out of the result.
func ListTags ¶ added in v0.2.0
ListTags returns every tag in the repository. It returns an empty slice when the repository has no tags.
func PushWithRebaseRetry ¶ added in v0.9.0
PushWithRebaseRetry pushes the current branch to its upstream, retrying a rejected push up to pushRetryAttempts times (for example a non-fast-forward caused by a concurrent state writer landing on trunk between checkout and push). It is the push half of CommitAndPushWithRetry, exposed for callers that stage and commit through their own flow and only need the shared retry behaviour. By default a rejected push is retried behind a "git pull --rebase", aborting the rebase and returning the wrapped error on a conflict rather than leaving the repository mid-rebase. Passing WithReapply switches the retry to re-derive the owned state leaf against re-fetched trunk instead, so an owned leaf converges against a concurrent sibling's adjacent leaf without conflict.
func RefetchAndReset ¶ added in v0.14.0
RefetchAndReset re-fetches trunk and hard-resets the working tree to the upstream tracking tip, so the working manifest holds the fresh trunk bytes (including any concurrent sibling leaf). It is exported for a state writer that wants to re-derive its owned leaf onto fresh trunk before its first commit, so that write never rests on a stale checkout base rather than relying solely on a push rejection to surface the staleness. It is the same operation the push retry loop performs on a rejected push.
func RemoteBranchSHA ¶ added in v0.2.0
RemoteBranchSHA returns the SHA of the remote-tracking ref refs/remotes/<remote>/<name> by running "git rev-parse". The returned SHA is whitespace-trimmed. An error is returned if the ref cannot be resolved.
This resolves a remote-tracking ref, so the remote must have been fetched first. A shallow or partial fetch that omits the branch will cause this to fail.
Types ¶
type Commit ¶
type Commit struct {
Hash string
Subject string
Body string
Author string
AuthorEmail string // Author email for deduplication
GitHubUsername string // GitHub username (looked up via API)
}
Commit represents a git commit
func GetCommits ¶
GetCommits returns commits between two SHAs
func GetCommitsForPaths ¶ added in v0.12.0
GetCommitsForPaths returns commits between two SHAs whose changes touch at least one of includePaths, emitting `git log ... base..head -- <p1> <p2>`. It is the include-path sibling of GetCommits (which appends pathspecs only as exclusions): a component's version derivation passes its own path so a commit touching only a sibling component's subtree is invisible to it. With an empty includePaths the argv carries no `--` separator, so the result is identical to GetCommits(base, head, nil) and the single-component path is unchanged.
type Option ¶ added in v0.9.0
type Option func(*pushOptions)
Option configures the rebase-retry push helpers. Options are additive: a call with no options behaves exactly as the original positional API did.
func WithBackoff ¶ added in v0.9.0
WithBackoff sets the base delay between push retries. A zero duration (the default) selects defaultPushBackoff. The effective wait grows exponentially from this base per attempt (capped at maxPushBackoff) plus a random jitter, so tests pass a tiny value to keep the retry loop fast.
func WithDir ¶ added in v0.9.0
WithDir runs the git commands with cmd.Dir set to dir instead of the process working directory. An empty dir (the default) leaves the process working directory in effect. This lets a caller drive a repository other than the one the process was launched in.
func WithReapply ¶ added in v0.13.0
WithReapply supplies a re-apply callback invoked on a rejected push in place of a textual "git pull --rebase". On a non-fast-forward reject the loop re-fetches trunk, hard-resets the local branch to the upstream tip, then calls fn, which must re-derive and re-write only the owned state leaf onto the fresh trunk bytes and re-commit it. This makes an owned leaf converge against a concurrent sibling leaf already on trunk without the textual conflict a rebase hits on the adjacent edit. With no WithReapply the loop keeps the historical textual-rebase behaviour, so callers that do not need re-apply (promote, hotfix, rollback) are unaffected.