Documentation ¶
Overview ¶
Package git runs Git commands in a controlled and typesafe way.
Index ¶
- func IsAhead(branchName, remoteText string) (bool, domain.RemoteBranchName)
- func IsAheadAndBehind(branchName, remoteText string) (bool, domain.RemoteBranchName)
- func IsBehind(branchName, remoteText string) (bool, domain.RemoteBranchName)
- func IsInSync(branchName, remoteText string) (bool, domain.RemoteBranchName)
- func IsRemoteGone(branchName, remoteText string) (bool, domain.RemoteBranchName)
- func ParseVerboseBranchesOutput(output string) (domain.BranchInfos, domain.LocalBranchName)
- type BackendCommands
- func (self *BackendCommands) Author() (string, error)
- func (self *BackendCommands) BranchAuthors(branch, parent domain.LocalBranchName) ([]string, error)
- func (self *BackendCommands) BranchExists(branch domain.LocalBranchName) bool
- func (self *BackendCommands) BranchHasUnmergedChanges(branch, parent domain.LocalBranchName) (bool, error)
- func (self *BackendCommands) BranchHasUnmergedCommits(branch domain.LocalBranchName, parent domain.Location) (bool, error)
- func (self *BackendCommands) BranchesSnapshot() (domain.BranchesSnapshot, error)
- func (self *BackendCommands) CheckoutBranch(name domain.LocalBranchName) error
- func (self *BackendCommands) CheckoutBranchUncached(name domain.LocalBranchName) error
- func (self *BackendCommands) CommentOutSquashCommitMessage(prefix string) error
- func (self *BackendCommands) CommitsInBranch(branch, parent domain.LocalBranchName) (domain.SHAs, error)
- func (self *BackendCommands) CommitsInFeatureBranch(branch, parent domain.LocalBranchName) (domain.SHAs, error)
- func (self *BackendCommands) CommitsInPerennialBranch() (domain.SHAs, error)
- func (self *BackendCommands) CreateFeatureBranch(name domain.LocalBranchName) error
- func (self *BackendCommands) CurrentBranch() (domain.LocalBranchName, error)
- func (self *BackendCommands) CurrentBranchUncached() (domain.LocalBranchName, error)
- func (self *BackendCommands) CurrentSHA() (domain.SHA, error)
- func (self *BackendCommands) ExpectedPreviouslyCheckedOutBranch(...) (domain.LocalBranchName, error)
- func (self *BackendCommands) FirstExistingBranch(branches domain.LocalBranchNames, mainBranch domain.LocalBranchName) domain.LocalBranchName
- func (self *BackendCommands) HasLocalBranch(name domain.LocalBranchName) bool
- func (self *BackendCommands) HasMergeInProgress() bool
- func (self *BackendCommands) HasShippableChanges(branch, mainBranch domain.LocalBranchName) (bool, error)
- func (self *BackendCommands) LastCommitMessage() (string, error)
- func (self *BackendCommands) PreviouslyCheckedOutBranch() domain.LocalBranchName
- func (self *BackendCommands) Remotes() (domain.Remotes, error)
- func (self *BackendCommands) RemotesUncached() (domain.Remotes, error)
- func (self *BackendCommands) RemoveOutdatedConfiguration(allBranches domain.BranchInfos) error
- func (self *BackendCommands) RepoStatus() (domain.RepoStatus, error)
- func (self *BackendCommands) RootDirectory() domain.RepoRootDir
- func (self *BackendCommands) SHAForBranch(name domain.BranchName) (domain.SHA, error)
- func (self *BackendCommands) ShouldPushBranch(branch domain.LocalBranchName, trackingBranch domain.RemoteBranchName) (bool, error)
- func (self *BackendCommands) StashSnapshot() (domain.StashSnapshot, error)
- func (self *BackendCommands) Version() (major int, minor int, err error)
- type BackendRunner
- type FrontendCommands
- func (self *FrontendCommands) AbortMerge() error
- func (self *FrontendCommands) AbortRebase() error
- func (self *FrontendCommands) AddGitAlias(alias config.Alias) error
- func (self *FrontendCommands) CheckoutBranch(name domain.LocalBranchName) error
- func (self *FrontendCommands) Commit(message, author string) error
- func (self *FrontendCommands) CommitNoEdit() error
- func (self *FrontendCommands) CommitStagedChanges(message string) error
- func (self *FrontendCommands) ContinueRebase() error
- func (self *FrontendCommands) CreateBranch(name domain.LocalBranchName, parent domain.Location) error
- func (self *FrontendCommands) CreateRemoteBranch(localSHA domain.SHA, branch domain.LocalBranchName, noPushHook bool) error
- func (self *FrontendCommands) CreateTrackingBranch(branch domain.LocalBranchName, remote domain.Remote, noPushHook bool) error
- func (self *FrontendCommands) DeleteLastCommit() error
- func (self *FrontendCommands) DeleteLocalBranch(name domain.LocalBranchName, force bool) error
- func (self *FrontendCommands) DeleteRemoteBranch(name domain.RemoteBranchName) error
- func (self *FrontendCommands) DiffParent(branch, parentBranch domain.LocalBranchName) error
- func (self *FrontendCommands) DiscardOpenChanges() error
- func (self *FrontendCommands) Fetch() error
- func (self *FrontendCommands) FetchUpstream(branch domain.LocalBranchName) error
- func (self *FrontendCommands) ForcePushBranch(noPushHook bool) error
- func (self *FrontendCommands) MergeBranchNoEdit(branch domain.BranchName) error
- func (self *FrontendCommands) NavigateToDir(dir domain.RepoRootDir) error
- func (self *FrontendCommands) PopStash() error
- func (self *FrontendCommands) Pull() error
- func (self *FrontendCommands) PushCurrentBranch(noPushHook bool) error
- func (self *FrontendCommands) PushTags() error
- func (self *FrontendCommands) Rebase(target domain.BranchName) error
- func (self *FrontendCommands) RemoveGitAlias(alias config.Alias) error
- func (self *FrontendCommands) ResetCurrentBranchToSHA(sha domain.SHA, hard bool) error
- func (self *FrontendCommands) ResetRemoteBranchToSHA(branch domain.RemoteBranchName, sha domain.SHA) error
- func (self *FrontendCommands) RevertCommit(sha domain.SHA) error
- func (self *FrontendCommands) SquashMerge(branch domain.LocalBranchName) error
- func (self *FrontendCommands) StageFiles(names ...string) error
- func (self *FrontendCommands) StartCommit() error
- func (self *FrontendCommands) Stash() error
- func (self *FrontendCommands) UndoLastCommit() error
- type FrontendRunner
- type ProdRunner
- type RepoConfig
- type SetCachedCurrentBranchFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAhead ¶ added in v10.0.1
func IsAhead(branchName, remoteText string) (bool, domain.RemoteBranchName)
func IsAheadAndBehind ¶ added in v10.0.1
func IsAheadAndBehind(branchName, remoteText string) (bool, domain.RemoteBranchName)
func IsBehind ¶ added in v10.0.1
func IsBehind(branchName, remoteText string) (bool, domain.RemoteBranchName)
func IsInSync ¶ added in v10.0.1
func IsInSync(branchName, remoteText string) (bool, domain.RemoteBranchName)
func IsRemoteGone ¶ added in v10.0.1
func IsRemoteGone(branchName, remoteText string) (bool, domain.RemoteBranchName)
IsRemoteGone indicates whether the given remoteText indicates a deleted tracking branch.
func ParseVerboseBranchesOutput ¶
func ParseVerboseBranchesOutput(output string) (domain.BranchInfos, domain.LocalBranchName)
ParseVerboseBranchesOutput provides the branches in the given Git output as well as the name of the currently checked out branch.
Types ¶
type BackendCommands ¶
type BackendCommands struct { BackendRunner // executes shell commands in the directory of the Git repo Config *RepoConfig // the known state of the Git repository CurrentBranchCache *cache.LocalBranch // caches the currently checked out Git branch RemotesCache *cache.Remotes // caches Git remotes }
BackendCommands are Git commands that Git Town executes to determine which frontend commands to run. They don't change the user's repo, execute instantaneously, and Git Town needs to know their output. They are invisible to the end user unless the "verbose" option is set.
func (*BackendCommands) Author ¶
func (self *BackendCommands) Author() (string, error)
Author provides the locally Git configured user.
func (*BackendCommands) BranchAuthors ¶
func (self *BackendCommands) BranchAuthors(branch, parent domain.LocalBranchName) ([]string, error)
BranchAuthors provides the user accounts that contributed to the given branch. Returns lines of "name <email>".
func (*BackendCommands) BranchExists ¶
func (self *BackendCommands) BranchExists(branch domain.LocalBranchName) bool
func (*BackendCommands) BranchHasUnmergedChanges ¶
func (self *BackendCommands) BranchHasUnmergedChanges(branch, parent domain.LocalBranchName) (bool, error)
BranchHasUnmergedChanges indicates whether the branch with the given name contains changes that were not merged into the main branch.
func (*BackendCommands) BranchHasUnmergedCommits ¶
func (self *BackendCommands) BranchHasUnmergedCommits(branch domain.LocalBranchName, parent domain.Location) (bool, error)
BranchHasUnmergedCommits indicates whether the branch with the given name contains commits that are not merged into the main branch.
func (*BackendCommands) BranchesSnapshot ¶
func (self *BackendCommands) BranchesSnapshot() (domain.BranchesSnapshot, error)
BranchesSnapshot provides detailed information about the sync status of all branches.
func (*BackendCommands) CheckoutBranch ¶
func (self *BackendCommands) CheckoutBranch(name domain.LocalBranchName) error
CheckoutBranch checks out the Git branch with the given name.
func (*BackendCommands) CheckoutBranchUncached ¶
func (self *BackendCommands) CheckoutBranchUncached(name domain.LocalBranchName) error
CheckoutBranch checks out the Git branch with the given name.
func (*BackendCommands) CommentOutSquashCommitMessage ¶
func (self *BackendCommands) CommentOutSquashCommitMessage(prefix string) error
CommentOutSquashCommitMessage comments out the message for the current squash merge Adds the given prefix with the newline if provided.
func (*BackendCommands) CommitsInBranch ¶
func (self *BackendCommands) CommitsInBranch(branch, parent domain.LocalBranchName) (domain.SHAs, error)
func (*BackendCommands) CommitsInFeatureBranch ¶
func (self *BackendCommands) CommitsInFeatureBranch(branch, parent domain.LocalBranchName) (domain.SHAs, error)
func (*BackendCommands) CommitsInPerennialBranch ¶
func (self *BackendCommands) CommitsInPerennialBranch() (domain.SHAs, error)
func (*BackendCommands) CreateFeatureBranch ¶
func (self *BackendCommands) CreateFeatureBranch(name domain.LocalBranchName) error
CreateFeatureBranch creates a feature branch with the given name in this repository.
func (*BackendCommands) CurrentBranch ¶
func (self *BackendCommands) CurrentBranch() (domain.LocalBranchName, error)
CurrentBranch provides the name of the currently checked out branch.
func (*BackendCommands) CurrentBranchUncached ¶
func (self *BackendCommands) CurrentBranchUncached() (domain.LocalBranchName, error)
CurrentBranch provides the currently checked out branch.
func (*BackendCommands) CurrentSHA ¶
func (self *BackendCommands) CurrentSHA() (domain.SHA, error)
CurrentSHA provides the SHA of the currently checked out branch/commit.
func (*BackendCommands) ExpectedPreviouslyCheckedOutBranch ¶
func (self *BackendCommands) ExpectedPreviouslyCheckedOutBranch(initialPreviouslyCheckedOutBranch, initialBranch, mainBranch domain.LocalBranchName) (domain.LocalBranchName, error)
ExpectedPreviouslyCheckedOutBranch returns what is the expected previously checked out branch given the inputs.
func (*BackendCommands) FirstExistingBranch ¶
func (self *BackendCommands) FirstExistingBranch(branches domain.LocalBranchNames, mainBranch domain.LocalBranchName) domain.LocalBranchName
func (*BackendCommands) HasLocalBranch ¶
func (self *BackendCommands) HasLocalBranch(name domain.LocalBranchName) bool
HasLocalBranch indicates whether this repo has a local branch with the given name.
func (*BackendCommands) HasMergeInProgress ¶
func (self *BackendCommands) HasMergeInProgress() bool
HasMergeInProgress indicates whether this Git repository currently has a merge in progress.
func (*BackendCommands) HasShippableChanges ¶
func (self *BackendCommands) HasShippableChanges(branch, mainBranch domain.LocalBranchName) (bool, error)
HasShippableChanges indicates whether the given branch has changes not currently in the main branch.
func (*BackendCommands) LastCommitMessage ¶
func (self *BackendCommands) LastCommitMessage() (string, error)
LastCommitMessage provides the commit message for the last commit.
func (*BackendCommands) PreviouslyCheckedOutBranch ¶
func (self *BackendCommands) PreviouslyCheckedOutBranch() domain.LocalBranchName
PreviouslyCheckedOutBranch provides the name of the branch that was previously checked out in this repo.
func (*BackendCommands) Remotes ¶
func (self *BackendCommands) Remotes() (domain.Remotes, error)
Remotes provides the names of all Git remotes in this repository.
func (*BackendCommands) RemotesUncached ¶
func (self *BackendCommands) RemotesUncached() (domain.Remotes, error)
Remotes provides the names of all Git remotes in this repository.
func (*BackendCommands) RemoveOutdatedConfiguration ¶
func (self *BackendCommands) RemoveOutdatedConfiguration(allBranches domain.BranchInfos) error
RemoveOutdatedConfiguration removes outdated Git Town configuration.
func (*BackendCommands) RepoStatus ¶
func (self *BackendCommands) RepoStatus() (domain.RepoStatus, error)
HasConflicts returns whether the local repository currently has unresolved merge conflicts.
func (*BackendCommands) RootDirectory ¶
func (self *BackendCommands) RootDirectory() domain.RepoRootDir
RootDirectory provides the path of the rood directory of the current repository, i.e. the directory that contains the ".git" folder.
func (*BackendCommands) SHAForBranch ¶
func (self *BackendCommands) SHAForBranch(name domain.BranchName) (domain.SHA, error)
SHAForBranch provides the SHA for the local branch with the given name.
func (*BackendCommands) ShouldPushBranch ¶
func (self *BackendCommands) ShouldPushBranch(branch domain.LocalBranchName, trackingBranch domain.RemoteBranchName) (bool, error)
ShouldPushBranch returns whether the local branch with the given name contains commits that have not been pushed to its tracking branch.
func (*BackendCommands) StashSnapshot ¶
func (self *BackendCommands) StashSnapshot() (domain.StashSnapshot, error)
StashSnapshot provides the number of stashes in this repository.
type BackendRunner ¶
type FrontendCommands ¶
type FrontendCommands struct { FrontendRunner SetCachedCurrentBranch SetCachedCurrentBranchFunc }
FrontendCommands are Git commands that Git Town executes for the user to change the user's repository. They can take a while to execute (fetch, push) and stream their output to the user. Git Town only needs to know the exit code of frontend commands.
func (*FrontendCommands) AbortMerge ¶
func (self *FrontendCommands) AbortMerge() error
AbortMerge cancels a currently ongoing Git merge operation.
func (*FrontendCommands) AbortRebase ¶
func (self *FrontendCommands) AbortRebase() error
AbortRebase cancels a currently ongoing Git rebase operation.
func (*FrontendCommands) AddGitAlias ¶
func (self *FrontendCommands) AddGitAlias(alias config.Alias) error
AddGitAlias sets the given Git alias.
func (*FrontendCommands) CheckoutBranch ¶
func (self *FrontendCommands) CheckoutBranch(name domain.LocalBranchName) error
CheckoutBranch checks out the Git branch with the given name in this repo.
func (*FrontendCommands) Commit ¶
func (self *FrontendCommands) Commit(message, author string) error
Commit performs a commit of the staged changes with an optional custom message and author.
func (*FrontendCommands) CommitNoEdit ¶
func (self *FrontendCommands) CommitNoEdit() error
CommitNoEdit commits all staged files with the default commit message.
func (*FrontendCommands) CommitStagedChanges ¶
func (self *FrontendCommands) CommitStagedChanges(message string) error
CommitStagedChanges commits the currently staged changes.
func (*FrontendCommands) ContinueRebase ¶
func (self *FrontendCommands) ContinueRebase() error
ContinueRebase continues the currently ongoing rebase.
func (*FrontendCommands) CreateBranch ¶
func (self *FrontendCommands) CreateBranch(name domain.LocalBranchName, parent domain.Location) error
CreateBranch creates a new branch with the given name. The created branch is a normal branch. To create feature branches, use CreateFeatureBranch.
func (*FrontendCommands) CreateRemoteBranch ¶
func (self *FrontendCommands) CreateRemoteBranch(localSHA domain.SHA, branch domain.LocalBranchName, noPushHook bool) error
CreateRemoteBranch creates a remote branch from the given local SHA.
func (*FrontendCommands) CreateTrackingBranch ¶
func (self *FrontendCommands) CreateTrackingBranch(branch domain.LocalBranchName, remote domain.Remote, noPushHook bool) error
PushBranch pushes the branch with the given name to origin.
func (*FrontendCommands) DeleteLastCommit ¶
func (self *FrontendCommands) DeleteLastCommit() error
DeleteLastCommit resets HEAD to the previous commit.
func (*FrontendCommands) DeleteLocalBranch ¶
func (self *FrontendCommands) DeleteLocalBranch(name domain.LocalBranchName, force bool) error
DeleteLocalBranch removes the local branch with the given name.
func (*FrontendCommands) DeleteRemoteBranch ¶
func (self *FrontendCommands) DeleteRemoteBranch(name domain.RemoteBranchName) error
DeleteRemoteBranch removes the remote branch of the given local branch.
func (*FrontendCommands) DiffParent ¶
func (self *FrontendCommands) DiffParent(branch, parentBranch domain.LocalBranchName) error
DiffParent displays the diff between the given branch and its given parent branch.
func (*FrontendCommands) DiscardOpenChanges ¶
func (self *FrontendCommands) DiscardOpenChanges() error
DiscardOpenChanges deletes all uncommitted changes.
func (*FrontendCommands) Fetch ¶
func (self *FrontendCommands) Fetch() error
Fetch retrieves the updates from the origin repo.
func (*FrontendCommands) FetchUpstream ¶
func (self *FrontendCommands) FetchUpstream(branch domain.LocalBranchName) error
FetchUpstream fetches updates from the upstream remote.
func (*FrontendCommands) ForcePushBranch ¶
func (self *FrontendCommands) ForcePushBranch(noPushHook bool) error
PushBranch pushes the branch with the given name to origin.
func (*FrontendCommands) MergeBranchNoEdit ¶
func (self *FrontendCommands) MergeBranchNoEdit(branch domain.BranchName) error
MergeBranchNoEdit merges the given branch into the current branch, using the default commit message.
func (*FrontendCommands) NavigateToDir ¶
func (self *FrontendCommands) NavigateToDir(dir domain.RepoRootDir) error
NavigateToDir changes into the root directory of the current repository.
func (*FrontendCommands) PopStash ¶
func (self *FrontendCommands) PopStash() error
PopStash restores stashed-away changes into the workspace.
func (*FrontendCommands) Pull ¶
func (self *FrontendCommands) Pull() error
Pull fetches updates from origin and updates the currently checked out branch.
func (*FrontendCommands) PushCurrentBranch ¶
func (self *FrontendCommands) PushCurrentBranch(noPushHook bool) error
PushCurrentBranch pushes the current branch to its tracking branch.
func (*FrontendCommands) PushTags ¶
func (self *FrontendCommands) PushTags() error
PushTags pushes new the Git tags to origin.
func (*FrontendCommands) Rebase ¶
func (self *FrontendCommands) Rebase(target domain.BranchName) error
Rebase initiates a Git rebase of the current branch against the given branch.
func (*FrontendCommands) RemoveGitAlias ¶
func (self *FrontendCommands) RemoveGitAlias(alias config.Alias) error
RemoveGitAlias removes the given Git alias.
func (*FrontendCommands) ResetCurrentBranchToSHA ¶
func (self *FrontendCommands) ResetCurrentBranchToSHA(sha domain.SHA, hard bool) error
ResetCurrentBranchToSHA undoes all commits on the current branch all the way until the given SHA.
func (*FrontendCommands) ResetRemoteBranchToSHA ¶
func (self *FrontendCommands) ResetRemoteBranchToSHA(branch domain.RemoteBranchName, sha domain.SHA) error
ResetRemoteBranchToSHA sets the given remote branch to the given SHA.
func (*FrontendCommands) RevertCommit ¶
func (self *FrontendCommands) RevertCommit(sha domain.SHA) error
RevertCommit reverts the commit with the given SHA.
func (*FrontendCommands) SquashMerge ¶
func (self *FrontendCommands) SquashMerge(branch domain.LocalBranchName) error
SquashMerge squash-merges the given branch into the current branch.
func (*FrontendCommands) StageFiles ¶
func (self *FrontendCommands) StageFiles(names ...string) error
StageFiles adds the file with the given name to the Git index.
func (*FrontendCommands) StartCommit ¶
func (self *FrontendCommands) StartCommit() error
StartCommit starts a commit and stops at asking the user for the commit message.
func (*FrontendCommands) Stash ¶
func (self *FrontendCommands) Stash() error
Stash adds the current files to the Git stash.
func (*FrontendCommands) UndoLastCommit ¶
func (self *FrontendCommands) UndoLastCommit() error
type FrontendRunner ¶
type ProdRunner ¶
type ProdRunner struct { Config RepoConfig Backend BackendCommands Frontend FrontendCommands CommandsCounter *gohacks.Counter FinalMessages *stringslice.Collector }
ProdRunner provides Git functionality for production code.
type RepoConfig ¶
type RepoConfig struct { *config.GitTown DryRun bool // single source of truth for whether to dry-run Git commands in this repo }
RepoConfig represents the known state of a Git repository.
type SetCachedCurrentBranchFunc ¶
type SetCachedCurrentBranchFunc func(domain.LocalBranchName)