Documentation
¶
Index ¶
- Constants
- Variables
- func IsURL(u string) bool
- func ParseURL(rawURL string) (*url.URL, error)
- 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) 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) 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
- type Command
- type CommandModifier
- type Commit
- type CredentialPattern
- type GitError
- type NotInstalled
- type PushDefault
- type Ref
- type Remote
- type RemoteSet
- type RemoteTrackingRef
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 ¶
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 ¶
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 ¶
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 ¶
func (*Client) CheckoutNewBranch ¶
func (*Client) CommitBody ¶
func (*Client) CurrentBranch ¶
CurrentBranch reads the checked-out branch for the git repository.
func (*Client) DeleteLocalBranch ¶
func (*Client) DeleteLocalTag ¶
func (*Client) HasLocalBranch ¶
func (*Client) PathFromRoot ¶
Show current directory relative to the top-level directory of repository.
func (*Client) PushDefault ¶
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 ¶
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 ¶
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 ¶
RemotePushDefault returns the value of remote.pushDefault in the config. If the value is not set, it returns an empty string.
func (*Client) SetBranchConfig ¶
SetBranchConfig sets the named value on the given branch.
func (*Client) SetRemoteBranches ¶
func (*Client) SetRemoteResolution ¶
func (*Client) ToplevelDir ¶
ToplevelDir returns the top-level directory path of the current repository.
func (*Client) TrackingBranchNames ¶
func (*Client) UncommittedChangeCount ¶
func (*Client) UnsetRemoteResolution ¶
type CommandModifier ¶
type CommandModifier func(*Command)
Allow individual commands to be modified from the default client options.
func WithRepoDir ¶
func WithRepoDir(repoDir string) CommandModifier
func WithStderr ¶
func WithStderr(stderr io.Writer) CommandModifier
func WithStdin ¶
func WithStdin(stdin io.Reader) CommandModifier
func WithStdout ¶
func WithStdout(stdout io.Writer) CommandModifier
type CredentialPattern ¶
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 an slightly less secure mode for backwards compatibility by using AllMatchingCredentialsPattern.
func CredentialPatternFromGitURL ¶
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 ¶
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 ¶
func (e *NotInstalled) Unwrap() error
type PushDefault ¶
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 ¶
func ParsePushDefault(s string) (PushDefault, error)
type RemoteTrackingRef ¶
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 ¶
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 ¶
func (r RemoteTrackingRef) String() string