git

package
v12.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package git provides access to Git.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAhead

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

func IsAheadAndBehind

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

func IsBehind

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

func IsInSync

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

func IsRemoteGone

func IsRemoteGone(branchName, remoteText string) (bool, gitdomain.RemoteBranchName)

IsRemoteGone indicates whether the given remoteText indicates a deleted tracking branch.

func ParseVerboseBranchesOutput

func ParseVerboseBranchesOutput(output string) (gitdomain.BranchInfos, gitdomain.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 {
	Config             *config.Config                 // the known state of the Git repository
	CurrentBranchCache *cache.LocalBranchWithPrevious // caches the currently checked out Git branch
	DryRun             bool
	RemotesCache       *cache.Remotes // caches Git remotes
	Runner             BackendRunner  // executes shell commands in the directory of the Git repo
}

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 gitdomain.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 gitdomain.LocalBranchName) bool

func (*BackendCommands) BranchHasUnmergedChanges

func (self *BackendCommands) BranchHasUnmergedChanges(branch, parent gitdomain.LocalBranchName) (bool, error)

BranchHasUnmergedChanges indicates whether the branch with the given name contains changes that were not merged into the main branch.

func (*BackendCommands) BranchesSnapshot

func (self *BackendCommands) BranchesSnapshot() (gitdomain.BranchesSnapshot, error)

BranchesSnapshot provides detailed information about the sync status of all branches.

func (*BackendCommands) CheckoutBranch

func (self *BackendCommands) CheckoutBranch(name gitdomain.LocalBranchName) error

CheckoutBranch checks out the Git branch with the given name.

func (*BackendCommands) CheckoutBranchUncached

func (self *BackendCommands) CheckoutBranchUncached(name gitdomain.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 gitdomain.LocalBranchName) (gitdomain.SHAs, error)

func (*BackendCommands) CommitsInFeatureBranch

func (self *BackendCommands) CommitsInFeatureBranch(branch, parent gitdomain.LocalBranchName) (gitdomain.SHAs, error)

func (*BackendCommands) CommitsInPerennialBranch

func (self *BackendCommands) CommitsInPerennialBranch() (gitdomain.SHAs, error)

func (*BackendCommands) CurrentBranch

func (self *BackendCommands) CurrentBranch() (gitdomain.LocalBranchName, error)

CurrentBranch provides the name of the currently checked out branch.

func (*BackendCommands) CurrentBranchUncached

func (self *BackendCommands) CurrentBranchUncached() (gitdomain.LocalBranchName, error)

CurrentBranch provides the currently checked out branch.

func (*BackendCommands) CurrentSHA

func (self *BackendCommands) CurrentSHA() (gitdomain.SHA, error)

CurrentSHA provides the SHA of the currently checked out branch/commit.

func (*BackendCommands) DefaultBranch

func (self *BackendCommands) DefaultBranch() gitdomain.LocalBranchName

func (*BackendCommands) FirstExistingBranch

func (self *BackendCommands) FirstExistingBranch(branches gitdomain.LocalBranchNames, mainBranch gitdomain.LocalBranchName) gitdomain.LocalBranchName

func (*BackendCommands) HasLocalBranch

func (self *BackendCommands) HasLocalBranch(name gitdomain.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 gitdomain.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() gitdomain.LocalBranchName

PreviouslyCheckedOutBranch provides the name of the branch that was previously checked out in this repo.

func (*BackendCommands) Remotes

func (self *BackendCommands) Remotes() (gitdomain.Remotes, error)

Remotes provides the names of all Git remotes in this repository.

func (*BackendCommands) RemotesUncached

func (self *BackendCommands) RemotesUncached() (gitdomain.Remotes, error)

Remotes provides the names of all Git remotes in this repository.

func (*BackendCommands) RemoveOutdatedConfiguration

func (self *BackendCommands) RemoveOutdatedConfiguration(localBranches gitdomain.LocalBranchNames) error

RemoveOutdatedConfiguration removes outdated Git Town configuration.

func (*BackendCommands) RepoStatus

func (self *BackendCommands) RepoStatus() (gitdomain.RepoStatus, error)

RepoStatus provides a summary of the state the current workspace is in right now: rebasing, has conflicts, has open changes, etc.

func (*BackendCommands) RootDirectory

func (self *BackendCommands) RootDirectory() gitdomain.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 gitdomain.BranchName) (gitdomain.SHA, error)

SHAForBranch provides the SHA for the local branch with the given name.

func (*BackendCommands) ShouldPushBranch

func (self *BackendCommands) ShouldPushBranch(branch gitdomain.LocalBranchName, trackingBranch gitdomain.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) StashSize

func (self *BackendCommands) StashSize() (gitdomain.StashSize, error)

StashSize 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 {
	Runner                 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) CheckoutBranch

func (self *FrontendCommands) CheckoutBranch(name gitdomain.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 gitdomain.LocalBranchName, parent gitdomain.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 gitdomain.SHA, branch gitdomain.LocalBranchName, noPushHook configdomain.NoPushHook) error

CreateRemoteBranch creates a remote branch from the given local SHA.

func (*FrontendCommands) CreateTrackingBranch

func (self *FrontendCommands) CreateTrackingBranch(branch gitdomain.LocalBranchName, remote gitdomain.Remote, noPushHook configdomain.NoPushHook) error

PushBranch pushes the branch with the given name to origin.

func (*FrontendCommands) DeleteHostingPlatform

func (self *FrontendCommands) DeleteHostingPlatform() error

DeleteHostingPlatform removes the hosting platform config entry.

func (*FrontendCommands) DeleteLastCommit

func (self *FrontendCommands) DeleteLastCommit() error

DeleteLastCommit resets HEAD to the previous commit.

func (*FrontendCommands) DeleteLocalBranch

func (self *FrontendCommands) DeleteLocalBranch(name gitdomain.LocalBranchName) error

DeleteLocalBranch removes the local branch with the given name.

func (*FrontendCommands) DeleteOriginHostname

func (self *FrontendCommands) DeleteOriginHostname() error

DeleteOriginHostname removes the origin hostname override

func (*FrontendCommands) DeleteTrackingBranch

func (self *FrontendCommands) DeleteTrackingBranch(name gitdomain.RemoteBranchName) error

DeleteTrackingBranch removes the tracking branch of the given local branch.

func (*FrontendCommands) DiffParent

func (self *FrontendCommands) DiffParent(branch, parentBranch gitdomain.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 gitdomain.LocalBranchName) error

FetchUpstream fetches updates from the upstream remote.

func (*FrontendCommands) ForcePushBranch

func (self *FrontendCommands) ForcePushBranch(noPushHook configdomain.NoPushHook) error

PushBranch pushes the branch with the given name to origin.

func (*FrontendCommands) MergeBranchNoEdit

func (self *FrontendCommands) MergeBranchNoEdit(branch gitdomain.BranchName) error

MergeBranchNoEdit merges the given branch into the current branch, using the default commit message.

func (*FrontendCommands) NavigateToDir

func (self *FrontendCommands) NavigateToDir(dir gitdomain.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 configdomain.NoPushHook) 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 gitdomain.BranchName) error

Rebase initiates a Git rebase of the current branch against the given branch.

func (*FrontendCommands) RemoveGitAlias

func (self *FrontendCommands) RemoveGitAlias(aliasableCommand configdomain.AliasableCommand) error

RemoveGitAlias removes the given Git alias.

func (*FrontendCommands) ResetCurrentBranchToSHA

func (self *FrontendCommands) ResetCurrentBranchToSHA(sha gitdomain.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 gitdomain.RemoteBranchName, sha gitdomain.SHA) error

ResetRemoteBranchToSHA sets the given remote branch to the given SHA.

func (*FrontendCommands) RevertCommit

func (self *FrontendCommands) RevertCommit(sha gitdomain.SHA) error

RevertCommit reverts the commit with the given SHA.

func (*FrontendCommands) SetGitAlias

func (self *FrontendCommands) SetGitAlias(aliasableCommand configdomain.AliasableCommand) error

SetGitAlias sets the given Git alias.

func (*FrontendCommands) SetGitHubToken

func (self *FrontendCommands) SetGitHubToken(value configdomain.GitHubToken) error

SetGitHubToken sets the given API token for the GitHub API.

func (*FrontendCommands) SetGitLabToken

func (self *FrontendCommands) SetGitLabToken(value configdomain.GitLabToken) error

SetGitLabToken sets the given API token for the GitHub API.

func (*FrontendCommands) SetGiteaToken

func (self *FrontendCommands) SetGiteaToken(value configdomain.GiteaToken) error

SetGiteaToken sets the given API token for the Gitea API.

func (*FrontendCommands) SetHostingPlatform

func (self *FrontendCommands) SetHostingPlatform(platform configdomain.HostingPlatform) error

SetHostingPlatform sets the given code hosting platform.

func (*FrontendCommands) SetOriginHostname

func (self *FrontendCommands) SetOriginHostname(hostname configdomain.HostingOriginHostname) error

SetHostingPlatform sets the given code hosting platform.

func (*FrontendCommands) SquashMerge

func (self *FrontendCommands) SquashMerge(branch gitdomain.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 {
	Backend         BackendCommands
	CommandsCounter *gohacks.Counter
	Config          *config.Config
	FinalMessages   *stringslice.Collector
	Frontend        FrontendCommands
}

ProdRunner provides Git functionality for production code.

type SetCachedCurrentBranchFunc

type SetCachedCurrentBranchFunc func(gitdomain.LocalBranchName)

Directories

Path Synopsis
Package gitdomain defines basic concepts from the domain of Git: branches, remotes, commit SHAs, etc.
Package gitdomain defines basic concepts from the domain of Git: branches, remotes, commit SHAs, etc.
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