Documentation ¶
Overview ¶
Package git runs Git commands in a controlled and typesafe way.
Index ¶
- type BoolCache
- type Commit
- type DryRun
- type LoggingShell
- func (shell LoggingShell) PrintCommand(cmd string, args ...string) error
- func (shell LoggingShell) Run(cmd string, args ...string) (*run.Result, error)
- func (shell LoggingShell) RunMany(commands [][]string) error
- func (shell LoggingShell) RunString(fullCmd string) (*run.Result, error)
- func (shell LoggingShell) RunStringWith(fullCmd string, options run.Options) (*run.Result, error)
- func (shell LoggingShell) WorkingDir() string
- type ProdRepo
- type PushArgs
- type Runner
- func (r *Runner) AbortMerge() error
- func (r *Runner) AbortRebase() error
- func (r *Runner) AddRemote(name, url string) error
- func (r *Runner) AddSubmodule(url string) error
- func (r *Runner) Author() (string, error)
- func (r *Runner) BranchHasUnmergedCommits(branch string) (bool, error)
- func (r *Runner) CheckoutBranch(name string) error
- func (r *Runner) CommentOutSquashCommitMessage(prefix string) error
- func (r *Runner) Commit(message, author string) error
- func (r *Runner) CommitNoEdit() error
- func (r *Runner) CommitStagedChanges(message string) error
- func (r *Runner) Commits(fields []string) ([]Commit, error)
- func (r *Runner) CommitsInBranch(branch string, fields []string) ([]Commit, error)
- func (r *Runner) ConnectTrackingBranch(name string) error
- func (r *Runner) ContinueRebase() error
- func (r *Runner) CreateBranch(name, parent string) error
- func (r *Runner) CreateChildFeatureBranch(name string, parent string) error
- func (r *Runner) CreateCommit(commit Commit) error
- func (r *Runner) CreateFeatureBranch(name string) error
- func (r *Runner) CreateFeatureBranchNoParent(name string) error
- func (r *Runner) CreateFile(name, content string) error
- func (r *Runner) CreatePerennialBranches(names ...string) error
- func (r *Runner) CreateRemoteBranch(localSha, branchName string, noPushVerify bool) error
- func (r *Runner) CreateStandaloneTag(name string) error
- func (r *Runner) CreateTag(name string) error
- func (r *Runner) CurrentBranch() (string, error)
- func (r *Runner) CurrentSha() (string, error)
- func (r *Runner) DeleteLastCommit() error
- func (r *Runner) DeleteLocalBranch(name string, force bool) error
- func (r *Runner) DeleteMainBranchConfiguration() error
- func (r *Runner) DeleteRemoteBranch(name string) error
- func (r *Runner) DiffParent(branch, parentBranch string) error
- func (r *Runner) DiscardOpenChanges() error
- func (r *Runner) ExpectedPreviouslyCheckedOutBranch(initialPreviouslyCheckedOutBranch, initialBranch string) (string, error)
- func (r *Runner) Fetch() error
- func (r *Runner) FetchUpstream(branch string) error
- func (r *Runner) FileContent(filename string) (string, error)
- func (r *Runner) FileContentInCommit(sha string, filename string) (string, error)
- func (r *Runner) FilesInBranch(branch string) ([]string, error)
- func (r *Runner) FilesInCommit(sha string) ([]string, error)
- func (r *Runner) HasBranchesOutOfSync() (bool, error)
- func (r *Runner) HasConflicts() (bool, error)
- func (r *Runner) HasFile(name, content string) (bool, error)
- func (r *Runner) HasGitTownConfigNow() (bool, error)
- func (r *Runner) HasLocalBranch(name string) (bool, error)
- func (r *Runner) HasLocalOrOriginBranch(name string) (bool, error)
- func (r *Runner) HasMergeInProgress() (bool, error)
- func (r *Runner) HasOpenChanges() (bool, error)
- func (r *Runner) HasOrigin() (bool, error)
- func (r *Runner) HasRebaseInProgress() (bool, error)
- func (r *Runner) HasRemote(name string) (bool, error)
- func (r *Runner) HasShippableChanges(branch string) (bool, error)
- func (r *Runner) HasTrackingBranch(name string) (bool, error)
- func (r *Runner) IsBranchInSync(branchName string) (bool, error)
- func (r *Runner) IsRepository() bool
- func (r *Runner) LastCommitMessage() (string, error)
- func (r *Runner) LocalAndOriginBranches() ([]string, error)
- func (r *Runner) LocalBranches() ([]string, error)
- func (r *Runner) LocalBranchesMainFirst() ([]string, error)
- func (r *Runner) LocalBranchesWithDeletedTrackingBranches() ([]string, error)
- func (r *Runner) LocalBranchesWithoutMain() ([]string, error)
- func (r *Runner) MergeBranchNoEdit(branch string) error
- func (r *Runner) PopStash() error
- func (r *Runner) PreviouslyCheckedOutBranch() (string, error)
- func (r *Runner) Pull() error
- func (r *Runner) PushBranch(options ...PushArgs) error
- func (r *Runner) PushTags() error
- func (r *Runner) Rebase(target string) error
- func (r *Runner) RemoteBranches() ([]string, error)
- func (r *Runner) Remotes() ([]string, error)
- func (r *Runner) RemoveBranch(name string) error
- func (r *Runner) RemoveRemote(name string) error
- func (r *Runner) RemoveUnnecessaryFiles() error
- func (r *Runner) ResetToSha(sha string, hard bool) error
- func (r *Runner) RevertCommit(sha string) error
- func (r *Runner) RootDirectory() (string, error)
- func (r *Runner) ShaForBranch(name string) (string, error)
- func (r *Runner) ShaForCommit(name string) (string, error)
- func (r *Runner) ShouldPushBranch(branch string) (bool, error)
- func (r *Runner) SquashMerge(branch string) error
- func (r *Runner) StageFiles(names ...string) error
- func (r *Runner) StartCommit() error
- func (r *Runner) Stash() error
- func (r *Runner) StashSize() (int, error)
- func (r *Runner) Tags() ([]string, error)
- func (r *Runner) TrackingBranchName(branch string) string
- func (r *Runner) UncommittedFiles() ([]string, error)
- func (r *Runner) Version() (major int, minor int, err error)
- type StringCache
- type StringSliceCache
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BoolCache ¶
type BoolCache struct {
// contains filtered or unexported fields
}
BoolCache caches a boolean variable. The zero value is an empty cache.
func (*BoolCache) Initialized ¶
Initialized indicates if we have a current branch.
func (*BoolCache) Invalidate ¶
func (sc *BoolCache) Invalidate()
Invalidate removes the cached value.
type Commit ¶
type Commit struct { Author string Branch string FileContent string FileName string Locations []string Message string SHA string }
Commit describes a Git commit.
type DryRun ¶
type DryRun struct {
// contains filtered or unexported fields
}
DryRun implements the dry-run feature. The zero value is a deactivate DruRun.
func (*DryRun) ChangeBranch ¶
ChangeBranch allows code to indicate to DryRun that the current branch has changed.
func (*DryRun) CurrentBranch ¶
CurrentBranch provides the name of the current branch.
type LoggingShell ¶
type LoggingShell struct {
// contains filtered or unexported fields
}
LoggingShell is an implementation of the Shell interface that runs commands in the current working directory and streams the command output to the application output. It is used by Git Town commands to run Git commands that show up in their output.
func NewLoggingShell ¶
func NewLoggingShell(silent *Runner, dryRun *DryRun) *LoggingShell
NewLoggingShell provides StreamingShell instances.
func (LoggingShell) PrintCommand ¶
func (shell LoggingShell) PrintCommand(cmd string, args ...string) error
PrintCommand prints the given command-line operation on the console.
func (LoggingShell) RunMany ¶
func (shell LoggingShell) RunMany(commands [][]string) error
RunMany runs all given commands in current directory. Commands are provided as a list of argv-style strings. Failed commands abort immediately with the encountered error.
func (LoggingShell) RunString ¶
func (shell LoggingShell) RunString(fullCmd string) (*run.Result, error)
RunString runs the given command (including possible arguments) in this ShellInDir's directory.
func (LoggingShell) RunStringWith ¶
RunStringWith runs the given command (including possible arguments) in this ShellInDir's directory.
func (LoggingShell) WorkingDir ¶
func (shell LoggingShell) WorkingDir() string
WorkingDir provides the directory that this Shell operates in.
type ProdRepo ¶
type ProdRepo struct { Config config.Config // the git.Configuration instance for this repo DryRun *DryRun Logging Runner // the Runner instance to Git operations that show up in the output LoggingShell *LoggingShell // the LoggingShell instance used Silent Runner // the Runner instance for silent Git operations }
ProdRepo is a Git Repo in production code.
func NewProdRepo ¶
func NewProdRepo() *ProdRepo
NewProdRepo provides a Repo instance in the current working directory.
func (*ProdRepo) NavigateToRootIfNecessary ¶
NavigateToRootIfNecessary changes into the root directory of the current repository.
func (*ProdRepo) RemoveOutdatedConfiguration ¶
RemoveOutdatedConfiguration removes outdated Git Town configuration.
type Runner ¶
type Runner struct { run.Shell // for running console commands Config config.Config // caches Git configuration settings CurrentBranchCache *StringCache // caches the currently checked out Git branch DryRun *DryRun // tracks dry-run information IsRepoCache *BoolCache // caches whether the current directory is a Git repo RemoteBranchCache *StringSliceCache // caches the remote branches of this Git repo RemotesCache *StringSliceCache // caches Git remotes RootDirCache *StringCache // caches the base of the Git directory }
Runner executes Git commands.
func (*Runner) AbortMerge ¶
AbortMerge cancels a currently ongoing Git merge operation.
func (*Runner) AbortRebase ¶
AbortRebase cancels a currently ongoing Git rebase operation.
func (*Runner) AddRemote ¶
AddRemote adds a Git remote with the given name and URL to this repository.
func (*Runner) AddSubmodule ¶
AddSubmodule adds a Git submodule with the given URL to this repository.
func (*Runner) BranchHasUnmergedCommits ¶
BranchHasUnmergedCommits indicates whether the branch with the given name contains commits that are not merged into the main branch.
func (*Runner) CheckoutBranch ¶
CheckoutBranch checks out the Git branch with the given name in this repo.
func (*Runner) CommentOutSquashCommitMessage ¶
CommentOutSquashCommitMessage comments out the message for the current squash merge Adds the given prefix with the newline if provided.
func (*Runner) Commit ¶
Commit performs a commit of the staged changes with an optional custom message and author.
func (*Runner) CommitNoEdit ¶
CommitNoEdit commits all staged files with the default commit message.
func (*Runner) CommitStagedChanges ¶
CommitStagedChanges commits the currently staged changes.
func (*Runner) Commits ¶
Commits provides a list of the commits in this Git repository with the given fields.
func (*Runner) CommitsInBranch ¶
CommitsInBranch provides all commits in the given Git branch.
func (*Runner) ConnectTrackingBranch ¶
ConnectTrackingBranch connects the branch with the given name to its counterpart at origin. The branch must exist.
func (*Runner) ContinueRebase ¶
ContinueRebase continues the currently ongoing rebase.
func (*Runner) CreateBranch ¶
CreateBranch creates a new branch with the given name. The created branch is a normal branch. To create feature branches, use CreateFeatureBranch.
func (*Runner) CreateChildFeatureBranch ¶
CreateChildFeatureBranch creates a branch with the given name and parent in this repository. The parent branch must already exist.
func (*Runner) CreateCommit ¶
CreateCommit creates a commit with the given properties in this Git repo.
func (*Runner) CreateFeatureBranch ¶
CreateFeatureBranch creates a feature branch with the given name in this repository.
func (*Runner) CreateFeatureBranchNoParent ¶
CreateFeatureBranchNoParent creates a feature branch with no defined parent in this repository.
func (*Runner) CreateFile ¶
CreateFile creates a file with the given name and content in this repository.
func (*Runner) CreatePerennialBranches ¶
CreatePerennialBranches creates perennial branches with the given names in this repository.
func (*Runner) CreateRemoteBranch ¶
CreateRemoteBranch creates a remote branch from the given local SHA.
func (*Runner) CreateStandaloneTag ¶
CreateStandaloneTag creates a tag not on a branch.
func (*Runner) CurrentBranch ¶
CurrentBranch provides the currently checked out branch for this repo.
func (*Runner) CurrentSha ¶
CurrentSha provides the SHA of the currently checked out branch/commit.
func (*Runner) DeleteLastCommit ¶
DeleteLastCommit resets HEAD to the previous commit.
func (*Runner) DeleteLocalBranch ¶
DeleteLocalBranch removes the local branch with the given name.
func (*Runner) DeleteMainBranchConfiguration ¶
DeleteMainBranchConfiguration removes the configuration for which branch is the main branch.
func (*Runner) DeleteRemoteBranch ¶
DeleteRemoteBranch removes the remote branch of the given local branch.
func (*Runner) DiffParent ¶
DiffParent displays the diff between the given branch and its given parent branch.
func (*Runner) DiscardOpenChanges ¶
DiscardOpenChanges deletes all uncommitted changes.
func (*Runner) ExpectedPreviouslyCheckedOutBranch ¶
func (r *Runner) ExpectedPreviouslyCheckedOutBranch(initialPreviouslyCheckedOutBranch, initialBranch string) (string, error)
ExpectedPreviouslyCheckedOutBranch returns what is the expected previously checked out branch given the inputs.
func (*Runner) FetchUpstream ¶
FetchUpstream fetches updates from the upstream remote.
func (*Runner) FileContent ¶
FileContent provides the current content of a file.
func (*Runner) FileContentInCommit ¶
FileContentInCommit provides the content of the file with the given name in the commit with the given SHA.
func (*Runner) FilesInBranch ¶
FilesInBranch provides the list of the files present in the given branch.
func (*Runner) FilesInCommit ¶
FilesInCommit provides the names of the files that the commit with the given SHA changes.
func (*Runner) HasBranchesOutOfSync ¶
HasBranchesOutOfSync indicates whether one or more local branches are out of sync with their tracking branch.
func (*Runner) HasConflicts ¶
HasConflicts returns whether the local repository currently has unresolved merge conflicts.
func (*Runner) HasFile ¶
HasFile indicates whether this repository contains a file with the given name and content.
func (*Runner) HasGitTownConfigNow ¶
HasGitTownConfigNow indicates whether this repository contain Git Town specific configuration.
func (*Runner) HasLocalBranch ¶
HasLocalBranch indicates whether this repo has a local branch with the given name.
func (*Runner) HasLocalOrOriginBranch ¶ added in v7.8.0
HasLocalOrRemoteBranch indicates whether this repo or origin have a branch with the given name.
func (*Runner) HasMergeInProgress ¶
HasMergeInProgress indicates whether this Git repository currently has a merge in progress.
func (*Runner) HasOpenChanges ¶
HasOpenChanges indicates whether this repo has open changes.
func (*Runner) HasOrigin ¶ added in v7.8.0
HasOrigin indicates whether this repo has an origin remote.
func (*Runner) HasRebaseInProgress ¶
HasRebaseInProgress indicates whether this Git repository currently has a rebase in progress.
func (*Runner) HasShippableChanges ¶
HasShippableChanges indicates whether the given branch has changes not currently in the main branch.
func (*Runner) HasTrackingBranch ¶
HasTrackingBranch indicates whether the local branch with the given name has a remote tracking branch.
func (*Runner) IsBranchInSync ¶
IsBranchInSync returns whether the branch with the given name is in sync with its tracking branch.
func (*Runner) IsRepository ¶
IsRepository returns whether or not the current directory is in a repository.
func (*Runner) LastCommitMessage ¶
LastCommitMessage provides the commit message for the last commit.
func (*Runner) LocalAndOriginBranches ¶ added in v7.8.0
LocalAndOriginBranches provides the names of all local branches in this repo.
func (*Runner) LocalBranches ¶
LocalBranches provides the names of all branches in the local repository, ordered alphabetically.
func (*Runner) LocalBranchesMainFirst ¶
LocalBranchesMainFirst provides the names of all local branches in this repo.
func (*Runner) LocalBranchesWithDeletedTrackingBranches ¶
LocalBranchesWithDeletedTrackingBranches provides the names of all branches whose remote tracking branches have been deleted.
func (*Runner) LocalBranchesWithoutMain ¶
LocalBranchesWithoutMain provides the names of all branches in the local repository, ordered alphabetically without the main branch.
func (*Runner) MergeBranchNoEdit ¶
MergeBranchNoEdit merges the given branch into the current branch, using the default commit message.
func (*Runner) PreviouslyCheckedOutBranch ¶
PreviouslyCheckedOutBranch provides the name of the branch that was previously checked out in this repo.
func (*Runner) Pull ¶
Pull fetches updates from origin and updates the currently checked out branch.
func (*Runner) PushBranch ¶
PushBranch pushes the branch with the given name to origin.
func (*Runner) Rebase ¶
Rebase initiates a Git rebase of the current branch against the given branch.
func (*Runner) RemoteBranches ¶
RemoteBranches provides the names of the remote branches in this repo.
func (*Runner) RemoveBranch ¶
RemoveBranch deletes the branch with the given name from this repo.
func (*Runner) RemoveRemote ¶
RemoveRemote deletes the Git remote with the given name.
func (*Runner) RemoveUnnecessaryFiles ¶
RemoveUnnecessaryFiles trims all files that aren't necessary in this repo.
func (*Runner) ResetToSha ¶
ResetToSha undoes all commits on the current branch all the way until the given SHA.
func (*Runner) RevertCommit ¶
RevertCommit reverts the commit with the given SHA.
func (*Runner) RootDirectory ¶
RootDirectory provides the path of the rood directory of the current repository, i.e. the directory that contains the ".git" folder.
func (*Runner) ShaForBranch ¶
ShaForBranch provides the SHA for the local branch with the given name.
func (*Runner) ShaForCommit ¶
ShaForCommit provides the SHA for the commit with the given name.
func (*Runner) ShouldPushBranch ¶
ShouldPushBranch returns whether the local branch with the given name contains commits that have not been pushed to its tracking branch.
func (*Runner) SquashMerge ¶
SquashMerge squash-merges the given branch into the current branch.
func (*Runner) StageFiles ¶
StageFiles adds the file with the given name to the Git index.
func (*Runner) StartCommit ¶
StartCommit starts a commit and stops at asking the user for the commit message.
func (*Runner) TrackingBranchName ¶
TrackingBranchName provides the name of the remote branch tracking the local branch with the given name.
func (*Runner) UncommittedFiles ¶
UncommittedFiles provides the names of the files not committed into Git.
type StringCache ¶
type StringCache struct {
// contains filtered or unexported fields
}
StringCache caches a string value. The zero value is an empty cache.
func (*StringCache) Initialized ¶
func (sc *StringCache) Initialized() bool
Initialized indicates if we have a current branch.
func (*StringCache) Invalidate ¶
func (sc *StringCache) Invalidate()
Invalidate removes the cached value.
func (*StringCache) Set ¶
func (sc *StringCache) Set(newValue string)
Set allows collaborators to signal when the current branch has changed.
type StringSliceCache ¶
type StringSliceCache struct {
// contains filtered or unexported fields
}
StringSliceCache caches a string slice value. The zero value is an empty cache.
func (*StringSliceCache) Initialized ¶
func (ssc *StringSliceCache) Initialized() bool
Initialized indicates if we have a current branch.
func (*StringSliceCache) Invalidate ¶
func (ssc *StringSliceCache) Invalidate()
Invalidate removes the cached value.
func (*StringSliceCache) Set ¶
func (ssc *StringSliceCache) Set(newValue []string)
Set allows collaborators to signal when the current branch has changed.
func (*StringSliceCache) Value ¶
func (ssc *StringSliceCache) Value() []string
Value provides the current value.