Documentation
¶
Index ¶
- Constants
- Variables
- func IsURL(u string) bool
- func IsolateConfig(t *testing.T)
- func ParseURL(rawURL string) (*url.URL, error)
- func ShortSHA(sha string) string
- type BranchConfig
- type Client
- func (c *Client) AddRemote(ctx context.Context, name, urlStr string, trackingBranches []string) (*Remote, error)
- func (c *Client) AuthenticatedCommand(ctx context.Context, credentialPattern CredentialPattern, args ...string) (*Command, error)
- func (c *Client) CheckoutBranch(ctx context.Context, branch string) error
- func (c *Client) CheckoutNewBranch(ctx context.Context, remoteName, branch string) error
- func (c *Client) Clone(ctx context.Context, cloneURL string, args []string, mods ...CommandModifier) (string, error)
- func (c *Client) Command(ctx context.Context, args ...string) (*Command, error)
- func (c *Client) CommitBody(ctx context.Context, sha string) (string, error)
- func (c *Client) Commits(ctx context.Context, baseRef, headRef string) ([]*Commit, error)
- func (c *Client) Config(ctx context.Context, name string) (string, error)
- func (c *Client) Copy() *Client
- func (c *Client) CurrentBranch(ctx context.Context) (string, error)
- func (c *Client) DeleteLocalBranch(ctx context.Context, branch string) error
- func (c *Client) DeleteLocalTag(ctx context.Context, tag string) error
- func (c *Client) Fetch(ctx context.Context, remote string, refspec string, mods ...CommandModifier) error
- func (c *Client) GitDir(ctx context.Context) (string, error)
- func (c *Client) HasLocalBranch(ctx context.Context, branch string) bool
- func (c *Client) IsIgnored(ctx context.Context, path string) (bool, error)
- func (c *Client) IsLocalGitRepo(ctx context.Context) (bool, error)
- func (c *Client) LastCommit(ctx context.Context) (*Commit, error)
- func (c *Client) PathFromRoot(ctx context.Context) string
- func (c *Client) Pull(ctx context.Context, remote, branch string, mods ...CommandModifier) error
- func (c *Client) Push(ctx context.Context, remote string, ref string, mods ...CommandModifier) error
- func (c *Client) PushDefault(ctx context.Context) (PushDefault, error)
- func (c *Client) PushRevision(ctx context.Context, branch string) (RemoteTrackingRef, error)
- func (c *Client) ReadBranchConfig(ctx context.Context, branch string) (BranchConfig, error)
- func (c *Client) RemotePushDefault(ctx context.Context) (string, error)
- func (c *Client) RemoteURL(ctx context.Context, name string) (string, error)
- func (c *Client) Remotes(ctx context.Context) (RemoteSet, error)
- func (c *Client) SetBranchConfig(ctx context.Context, branch, name, value string) error
- func (c *Client) SetRemoteBranches(ctx context.Context, remote string, refspec string) error
- func (c *Client) SetRemoteResolution(ctx context.Context, name, resolution string) error
- func (c *Client) ShowRefs(ctx context.Context, refs []string) ([]Ref, error)
- func (c *Client) ToplevelDir(ctx context.Context) (string, error)
- func (c *Client) TrackingBranchNames(ctx context.Context, prefix string) []string
- func (c *Client) UncommittedChangeCount(ctx context.Context) (int, error)
- func (c *Client) UnsetRemoteResolution(ctx context.Context, name string) error
- func (c *Client) UpdateRemoteURL(ctx context.Context, name, url string) error
- func (c *Client) WorktreePrune(ctx context.Context) error
- func (c *Client) WorktreeRemove(ctx context.Context, path string) error
- func (c *Client) Worktrees(ctx context.Context) ([]Worktree, error)
- type Command
- type CommandModifier
- type Commit
- type CredentialPattern
- type GitError
- type NotInstalled
- type PushDefault
- type Ref
- type Remote
- type RemoteSet
- type RemoteTrackingRef
- type Worktree
Constants ¶
const MergeBaseConfig = "gh-merge-base"
MergeBaseConfig is the configuration setting to keep track of the PR target branch.
Variables ¶
var AllMatchingCredentialsPattern = CredentialPattern{/* contains filtered or unexported fields */}
AllMatchingCredentialsPattern allows for setting gh as credential helper for all hosts. However, we should endeavour to remove it as it's less secure.
var ErrNotOnAnyBranch = errors.New("git: not on any branch")
ErrNotOnAnyBranch indicates that the user is in detached HEAD state.
Functions ¶
func IsolateConfig ¶ added in v2.98.0
IsolateConfig prevents the ambient git configuration from reaching tests that shell out to real git.
Types ¶
type BranchConfig ¶
type BranchConfig struct {
RemoteName string // .remote if string
RemoteURL *url.URL // .remote if url
MergeRef string // .merge
PushRemoteName string // .pushremote if string
PushRemoteURL *url.URL // .pushremote if url
// MergeBase is the optional base branch to target in a new PR if `--base` is not specified.
MergeBase string
}
These are the keys we read from the git branch.<name> config.
type Client ¶ added in v2.18.0
type Client struct {
GhPath string
RepoDir string
GitPath string
Stderr io.Writer
Stdin io.Reader
Stdout io.Writer
// contains filtered or unexported fields
}
func (*Client) AuthenticatedCommand ¶ added in v2.18.0
func (c *Client) AuthenticatedCommand(ctx context.Context, credentialPattern CredentialPattern, args ...string) (*Command, error)
AuthenticatedCommand is a wrapper around Command that included configuration to use gh as the credential helper for git.
func (*Client) CheckoutBranch ¶ added in v2.18.0
func (*Client) CheckoutNewBranch ¶ added in v2.18.0
func (*Client) CommitBody ¶ added in v2.18.0
func (*Client) CurrentBranch ¶ added in v2.18.0
CurrentBranch reads the checked-out branch for the git repository.
func (*Client) DeleteLocalBranch ¶ added in v2.18.0
func (*Client) DeleteLocalTag ¶ added in v2.35.0
func (*Client) HasLocalBranch ¶ added in v2.18.0
func (*Client) IsIgnored ¶ added in v2.90.0
IsIgnored reports whether the given path is ignored by .gitignore rules. Returns an error for fatal git failures (e.g. path outside repository).
func (*Client) IsLocalGitRepo ¶ added in v2.22.0
func (*Client) LastCommit ¶ added in v2.18.0
func (*Client) PathFromRoot ¶ added in v2.18.0
Show current directory relative to the top-level directory of repository.
func (*Client) PushDefault ¶ added in v2.66.0
func (c *Client) PushDefault(ctx context.Context) (PushDefault, error)
PushDefault returns the value of push.default in the config. If the value is not set, it returns "simple" (the default git value). See https://git-scm.com/docs/git-config#Documentation/git-config.txt-pushdefault
func (*Client) PushRevision ¶ added in v2.71.0
PushRevision gets the value of the @{push} revision syntax An error here doesn't necessarily mean something is broken, but may mean that the @{push} revision syntax couldn't be resolved, such as in non-centralized workflows with push.default = simple. Downstream consumers should consider how to handle this error.
func (*Client) ReadBranchConfig ¶ added in v2.18.0
ReadBranchConfig parses the `branch.BRANCH.(remote|merge|pushremote|gh-merge-base)` part of git config. If no branch config is found or there is an error in the command, it returns an empty BranchConfig. Downstream consumers of ReadBranchConfig should consider the behavior they desire if this errors, as an empty config is not necessarily breaking.
func (*Client) RemotePushDefault ¶ added in v2.66.0
RemotePushDefault returns the value of remote.pushDefault in the config. If the value is not set, it returns an empty string.
func (*Client) RemoteURL ¶ added in v2.90.0
RemoteURL returns the fetch URL configured for the named remote.
func (*Client) SetBranchConfig ¶ added in v2.64.0
SetBranchConfig sets the named value on the given branch.
func (*Client) SetRemoteBranches ¶ added in v2.31.0
func (*Client) SetRemoteResolution ¶ added in v2.18.0
func (*Client) ToplevelDir ¶ added in v2.18.0
ToplevelDir returns the top-level directory path of the current repository.
func (*Client) TrackingBranchNames ¶ added in v2.26.0
func (*Client) UncommittedChangeCount ¶ added in v2.18.0
func (*Client) UnsetRemoteResolution ¶ added in v2.21.0
func (*Client) UpdateRemoteURL ¶ added in v2.18.0
func (*Client) WorktreePrune ¶ added in v2.99.0
WorktreePrune removes administrative files for worktrees that no longer exist on disk.
func (*Client) WorktreeRemove ¶ added in v2.99.0
WorktreeRemove removes the worktree at the given path via `git worktree remove <path>`.
type CommandModifier ¶ added in v2.19.0
type CommandModifier func(*Command)
Allow individual commands to be modified from the default client options.
func WithRepoDir ¶ added in v2.19.0
func WithRepoDir(repoDir string) CommandModifier
func WithStderr ¶ added in v2.19.0
func WithStderr(stderr io.Writer) CommandModifier
func WithStdin ¶ added in v2.19.0
func WithStdin(stdin io.Reader) CommandModifier
func WithStdout ¶ added in v2.19.0
func WithStdout(stdout io.Writer) CommandModifier
type CredentialPattern ¶ added in v2.63.0
type CredentialPattern struct {
// contains filtered or unexported fields
}
CredentialPattern is used to inform AuthenticatedCommand which patterns Git should match against when trying to find credentials. It is a little over-engineered as a type because we want AuthenticatedCommand to have a clear compilation error when this is not provided, as opposed to using a string which might compile with `client.AuthenticatedCommand(ctx, "fetch")`.
It is only usable when constructed by another function in the package because the empty pattern, without allMatching set to true, will result in an error in AuthenticatedCommand.
Callers can currently opt-in to a slightly less secure mode for backwards compatibility by using AllMatchingCredentialsPattern.
func CredentialPatternFromGitURL ¶ added in v2.63.0
func CredentialPatternFromGitURL(gitURL string) (CredentialPattern, error)
CredentialPatternFromGitURL takes a git remote URL e.g. "https://github.com/cli/cli.git" or "git@github.com:cli/cli.git" and returns the credential pattern that should be used for it.
func CredentialPatternFromHost ¶ added in v2.63.1
func CredentialPatternFromHost(host string) CredentialPattern
CredentialPatternFromHost expects host to be in the form "github.com" and returns the credential pattern that should be used for it. It does not perform any canonicalisation e.g. "api.github.com" will not work as expected.
type NotInstalled ¶
type NotInstalled struct {
// contains filtered or unexported fields
}
func (*NotInstalled) Error ¶
func (e *NotInstalled) Error() string
func (*NotInstalled) Unwrap ¶ added in v2.18.0
func (e *NotInstalled) Unwrap() error
type PushDefault ¶ added in v2.71.0
type PushDefault string
PushDefault defines the action git push should take if no refspec is given. See: https://git-scm.com/docs/git-config#Documentation/git-config.txt-pushdefault
const ( PushDefaultNothing PushDefault = "nothing" PushDefaultCurrent PushDefault = "current" PushDefaultUpstream PushDefault = "upstream" PushDefaultTracking PushDefault = "tracking" PushDefaultSimple PushDefault = "simple" PushDefaultMatching PushDefault = "matching" )
func ParsePushDefault ¶ added in v2.71.0
func ParsePushDefault(s string) (PushDefault, error)
type RemoteTrackingRef ¶ added in v2.71.0
RemoteTrackingRef is the structured form of the string "refs/remotes/<remote>/<branch>". For example, the @{push} revision syntax could report "refs/remotes/origin/main" which would be parsed into RemoteTrackingRef{Remote: "origin", Branch: "main"}.
func ParseRemoteTrackingRef ¶ added in v2.71.0
func ParseRemoteTrackingRef(s string) (RemoteTrackingRef, error)
➜ git rev-parse --symbolic-full-name bar/baz@{push} refs/remotes/foo/bar/baz ```
When using this ref, git assumes it means `remote: foo` `branch: bar/baz`.
func (RemoteTrackingRef) String ¶ added in v2.71.0
func (r RemoteTrackingRef) String() string
type Worktree ¶ added in v2.99.0
type Worktree struct {
// Path is the absolute path to the worktree's working directory.
Path string
// Ref is the fully qualified ref checked out in the worktree
// (e.g. "refs/heads/main"). It is empty when the worktree has a detached
// HEAD or is the bare main worktree.
Ref string
// Prunable indicates that the worktree's administrative files reference
// a working directory that no longer exists.
Prunable bool
}
Worktree represents a single entry from `git worktree list --porcelain`.
func WorktreeForBranch ¶ added in v2.99.0
WorktreeForBranch returns the worktree that has branch checked out, or nil when the branch is not associated with any worktree.