git

package
v11.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package git runs Git commands in a controlled and typesafe way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAhead

func IsAhead(branchName, remoteText string) (bool, domain.RemoteBranchName)

func IsAheadAndBehind

func IsAheadAndBehind(branchName, remoteText string) (bool, domain.RemoteBranchName)

func IsBehind

func IsBehind(branchName, remoteText string) (bool, domain.RemoteBranchName)

func IsInSync

func IsInSync(branchName, remoteText string) (bool, domain.RemoteBranchName)

func IsRemoteGone

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.LocalBranchWithPrevious // 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) 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.

func (*BackendCommands) Version

func (self *BackendCommands) Version() (major int, minor int, err error)

Version indicates whether the needed Git version is installed.

type BackendRunner

type BackendRunner interface {
	Query(executable string, args ...string) (string, error)
	QueryTrim(executable string, args ...string) (string, error)
	Run(executable string, args ...string) error
	RunMany(commands [][]string) error
}

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 FrontendRunner interface {
	Run(executable string, args ...string) error
	RunMany(commands [][]string) error
}

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)

Directories

Path Synopsis
Package giturl provides facilities to work with the special URL formats used in Git remotes.
Package giturl provides facilities to work with the special URL formats used in Git remotes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL