Documentation
¶
Overview ¶
Package git contains subprocess boundaries, independent of command flags.
Index ¶
- Variables
- func CredentialArguments(instance, executable, user, configDir string) ([]string, error)
- func CredentialHelper(instance, executable, user, configDir string) (string, error)
- func CurrentBranch(ctx context.Context, runner Runner, dir string) (string, error)
- func CurrentUpstreamRemote(ctx context.Context, runner Runner, dir string) (branch, remote string)
- func DiscoverRemote(ctx context.Context, runner Runner, dir, preferred string, ...) (string, error)
- func FindCleanBranch(ctx context.Context, runner Runner, opts FindCleanBranchOptions) (localBranch, remote string, err error)
- func HelperScope(ctx context.Context, runner Runner, dir, instance string) string
- func PushAgitPR(ctx context.Context, runner Runner, opts AgitOptions) error
- func RecordBaseRemote(ctx context.Context, runner Runner, dir, branch, remote string) error
- func RecordPull(ctx context.Context, runner Runner, dir, branch string, number int64, ...) error
- func RejectCredentials(ctx context.Context, runner Runner, dir, instance, user, token string) error
- func SSHArguments(key string, agent bool) ([]string, error)
- func SetupCredentials(ctx context.Context, runner Runner, options CredentialSetup) error
- func SetupTLS(ctx context.Context, runner Runner, dir string, local bool, ...) error
- func TLSArguments(instance, certFile, keyFile string, insecure bool) ([]string, error)
- func UnsetInsecureTLS(ctx context.Context, runner Runner, dir string, local bool, instance string) error
- func UpstreamRemote(ctx context.Context, runner Runner, dir, branch string) string
- type AgitOptions
- type BranchConfig
- type CheckoutOptions
- type CheckoutResult
- type CleanOptions
- type CleanResult
- type CommandError
- type CredentialSetup
- type FindCleanBranchOptions
- type InputRunner
- type Runner
- type SyncOptions
- type SyncResult
- type System
Constants ¶
This section is empty.
Variables ¶
var ErrAmbiguousRemote = errors.New("ambiguous repository: select --remote or --repo")
ErrAmbiguousRemote reports that repository discovery cannot choose between several remotes.
var ErrNotOnBranch = errors.New("not on a branch")
ErrNotOnBranch reports a detached HEAD or a directory outside a checkout.
Functions ¶
func CredentialArguments ¶
CredentialArguments scopes a helper to one Git operation instead of changing Git configuration. The empty helper resets other helpers for this instance.
func CredentialHelper ¶
CredentialHelper builds a shell command for Git's helper protocol. Git itself supplies the final get/store/erase argument. No credential enters this command.
func CurrentBranch ¶
CurrentBranch names the checked-out branch, failing with ErrNotOnBranch when HEAD is detached or dir is not a checkout. It reads the full ref because --short answers heads/NAME for a branch that shares its name with a tag.
func CurrentUpstreamRemote ¶
CurrentUpstreamRemote names the checked-out branch and the remote it tracks; each is "" when HEAD is detached or the branch tracks no remote.
func DiscoverRemote ¶
func DiscoverRemote(ctx context.Context, runner Runner, dir, preferred string, repository func(remote string) string) (string, error)
DiscoverRemote names the remote used for repository discovery: preferred when it exists, then the base remote pr checkout recorded for the current branch, the current branch's upstream remote unless it is a pulls/<owner>/<repo> head remote or origin beside an upstream remote (a fork clone), then upstream, origin, or the only remote. When repository is not nil, it names the repository of a remote gt can act on, or returns "" for one on another forge. Those steps then skip such remotes, and the other remotes decide when they name exactly one repository; with none of them usable the choice is the name-based one.
func FindCleanBranch ¶
func FindCleanBranch(ctx context.Context, runner Runner, opts FindCleanBranchOptions) (localBranch, remote string, err error)
FindCleanBranch locates one local branch for PR cleanup without mutating Git state.
func HelperScope ¶
HelperScope returns where Git is configured to ask gt for credentials of instance: "local" for the repository in dir, "global", or "" when it is not.
func PushAgitPR ¶
func PushAgitPR(ctx context.Context, runner Runner, opts AgitOptions) error
PushAgitPR pushes head to refs/for/<base>/<topic> with optional title/description options.
func RecordBaseRemote ¶
RecordBaseRemote records remote as the remote of the base repository of branch, which repository discovery prefers to the remote the branch tracks, such as a fork.
func RecordPull ¶
func RecordPull(ctx context.Context, runner Runner, dir, branch string, number int64, baseRemote string) error
RecordPull records in the configuration of branch the pull request it belongs to and the remote of that pull request's base repository, which pr commands read to find the pull request of the branch and pr clean to find the branch of the pull request.
func RejectCredentials ¶
RejectCredentials asks Git's credential helpers to erase the copies of token they stored for user on instance, such as one that a keychain kept after a push. Helpers keep entries with another password, such as the user's own. Runners that cannot send input reject nothing.
func SSHArguments ¶
SSHArguments selects a private key for one Git operation. Agent selection retains the user's SSH configuration, as does an account without a key.
func SetupCredentials ¶
func SetupCredentials(ctx context.Context, runner Runner, options CredentialSetup) error
SetupCredentials installs a helper scoped to the instance. Unless KeepHelpers is set, an empty helper first resets other helpers for the instance, so they neither answer for gt nor store its token.
func SetupTLS ¶
func SetupTLS(ctx context.Context, runner Runner, dir string, local bool, instance, certFile, keyFile string, insecure bool) error
SetupTLS writes the settings of TLSArguments to the global Git configuration, or with local to the configuration of the repository in dir, so that plain git fetch and push reach the instance.
func TLSArguments ¶
TLSArguments make one Git operation present the instance's TLS client certificate, with its key in keyFile or else in certFile, and skip certificate verification when insecure, as gt's API requests do. They apply only to the instance's URLs.
func UnsetInsecureTLS ¶
func UnsetInsecureTLS(ctx context.Context, runner Runner, dir string, local bool, instance string) error
UnsetInsecureTLS removes the sslVerify=false that SetupTLS wrote for the instance, once the instance verifies certificates again. A setting with another value is kept.
func UpstreamRemote ¶
UpstreamRemote names the remote branch tracks, or "" when it tracks none or a local branch. Unlike splitting @{upstream}, it keeps remote names with slashes, such as the pulls/<owner>/<repo> remotes pr checkout adds.
Types ¶
type AgitOptions ¶
type AgitOptions struct {
Directory, Remote, Head, Base, Topic, Title, Body string
CredentialArgs []string
Prompt bool
}
AgitOptions creates a pull request through Gitea's AGit push convention.
type BranchConfig ¶
type BranchConfig struct {
// Name is the local branch.
Name string
// Remote and Merge are the remote and branch the branch tracks, Merge without refs/heads/;
// both are empty for a branch that tracks nothing or another local branch.
Remote, Merge string
// PullNumber and BaseRemote are what pr checkout recorded: the pull request the branch was
// checked out from and the remote of that pull request's base repository.
PullNumber int64
BaseRemote string
}
BranchConfig is the configuration of a local branch that locates its pull request.
func CurrentBranchConfig ¶
CurrentBranchConfig reads the configuration of the checked-out branch, failing with ErrNotOnBranch when HEAD is detached or dir is not a checkout.
func ReadBranchConfig ¶
func ReadBranchConfig(ctx context.Context, runner Runner, dir, name string) BranchConfig
ReadBranchConfig reads branch.<name>.remote, .merge and the keys pr checkout records. Missing or malformed keys stay empty.
type CheckoutOptions ¶
type CheckoutOptions struct {
// CredentialArgs contains per-operation Git configuration for the fetch only.
CredentialArgs []string
Directory string
Remote string
Number int64
Branch string
Detached bool
Update bool
Prompt bool
ExpectedCommit string
// HeadRemote and HeadBranch select fork tracking when the head branch still exists.
// When HeadBranch is empty, checkout fetches the retained pull ref from Remote.
HeadRemote string
HeadBranch string
}
CheckoutOptions identifies the base remote and how to check out the PR commit.
type CheckoutResult ¶
type CheckoutResult struct {
Detached bool `json:"detached"`
Branch string `json:"branch"`
Commit string `json:"commit"`
Remote string `json:"remote,omitempty"`
Tracking string `json:"tracking,omitempty"`
}
CheckoutResult describes the selected branch or detached PR commit.
func CheckoutPull ¶
func CheckoutPull(ctx context.Context, runner Runner, options CheckoutOptions) (CheckoutResult, error)
CheckoutPull fetches a PR head and checks out its commit. When HeadRemote and HeadBranch are set, it fetches that head branch and configures tracking. Otherwise it fetches Gitea's retained pull ref from the base remote.
type CleanOptions ¶
type CleanOptions struct {
Directory, DefaultBranch, LocalBranch, Remote, RemoteBranch string
CredentialArgs []string
Prompt, DeleteRemote bool
}
CleanOptions identifies a closed PR's local branch and optional remote head.
type CleanResult ¶
type CleanResult struct {
LocalBranch string `json:"local_branch"`
Remote string `json:"remote,omitempty"`
RemoteBranch string `json:"remote_branch,omitempty"`
DefaultBranch string `json:"default_branch"`
RemoteDeleted bool `json:"remote_deleted"`
RemoteSkipped bool `json:"remote_skipped"`
RemoteSkipReason string `json:"remote_skip_reason,omitempty"`
}
CleanResult reports which branches were removed.
func CleanPull ¶
func CleanPull(ctx context.Context, runner Runner, opts CleanOptions) (CleanResult, error)
CleanPull deletes the selected local branch and optionally its remote head.
type CommandError ¶
type CommandError struct{ ExitCode int }
CommandError carries Git's exit status without including command arguments or output.
func (*CommandError) Error ¶
func (*CommandError) Error() string
type CredentialSetup ¶
type CredentialSetup struct {
Directory, Instance, Executable, User, ConfigDirectory string
Local bool
// KeepHelpers adds gt's helper after other helpers instead of resetting them for the instance.
KeepHelpers bool
}
CredentialSetup specifies an explicit persistent helper installation.
type FindCleanBranchOptions ¶
type FindCleanBranchOptions struct {
Directory, HeadSHA, HeadBranch string
DefaultBranch string
PreferredNames, MatchingRemotes []string
IgnoreSHA bool
// PullNumber is the pull request being cleaned; a branch that pr checkout recorded for it
// wins over branches that merely share the head branch's name.
PullNumber int64
}
FindCleanBranchOptions searches for a local branch belonging to a closed PR.
type InputRunner ¶
type InputRunner interface {
Input(ctx context.Context, dir, input string, args ...string) (string, error)
}
InputRunner runs Git with text on its standard input.
type SyncOptions ¶
SyncOptions selects the local branch to fast-forward and the remote whose branch of the same name it follows.
type SyncResult ¶
type SyncResult struct {
Branch string `json:"branch"`
Commit string `json:"commit"`
Previous string `json:"previous"`
Remote string `json:"remote"`
}
SyncResult reports a synced branch. Previous is the branch's commit before the sync, empty when the sync created the branch; it equals Commit when there was nothing to sync. For a sync on the server, Remote names the repository the branch was synced from.
func SyncBranch ¶
func SyncBranch(ctx context.Context, runner Runner, opts SyncOptions) (SyncResult, error)
SyncBranch fast-forwards the local branch to the remote's branch of the same name, creating it when it is missing, and never changes which branch is checked out. The checked-out branch merges with --ff-only and needs a clean working tree; another branch moves with update-ref, which fails if the branch changed meanwhile. A branch that already contains the remote history is kept. A branch checked out in another linked worktree, or being rebased in any worktree, is refused, since moving it would leave that worktree's files behind its HEAD or break the rebase.
type System ¶
type System struct {
// Env overrides the subprocess environment when supplied.
Env []string
In io.Reader
ErrOut io.Writer
}
System executes installed Git with explicit stream and prompting policy.