git

package
v7.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2022 License: MIT Imports: 14 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

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

func (sc *BoolCache) Initialized() bool

Initialized indicates if we have a current branch.

func (*BoolCache) Invalidate

func (sc *BoolCache) Invalidate()

Invalidate removes the cached value.

func (*BoolCache) Set

func (sc *BoolCache) Set(newValue bool)

Set allows collaborators to signal when the current branch has changed.

func (*BoolCache) Value

func (sc *BoolCache) Value() bool

Value provides the current 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.

func (*Commit) Set

func (commit *Commit) Set(name, value string) error

Set assigns the given value to the property with the given Gherkin table name.

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) Activate

func (dr *DryRun) Activate(currentBranch string)

Activate enables dry-run.

func (*DryRun) ChangeBranch

func (dr *DryRun) ChangeBranch(name string)

ChangeBranch allows code to indicate to DryRun that the current branch has changed.

func (*DryRun) CurrentBranch

func (dr *DryRun) CurrentBranch() string

CurrentBranch provides the name of the current branch.

func (*DryRun) IsActive

func (dr *DryRun) IsActive() bool

IsActive indicates whether dry-run is active.

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) Run

func (shell LoggingShell) Run(cmd string, args ...string) (*run.Result, error)

Run runs the given command in this ShellRunner's directory.

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

func (shell LoggingShell) RunStringWith(fullCmd string, options run.Options) (*run.Result, error)

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

func (r *ProdRepo) NavigateToRootIfNecessary() error

NavigateToRootIfNecessary changes into the root directory of the current repository.

func (*ProdRepo) RemoveOutdatedConfiguration

func (r *ProdRepo) RemoveOutdatedConfiguration() error

RemoveOutdatedConfiguration removes outdated Git Town configuration.

type PushArgs added in v7.9.0

type PushArgs struct {
	BranchName     string
	Force          bool
	ForceWithLease bool
	NoPushVerify   bool
	ToOrigin       bool
}

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

func (r *Runner) AbortMerge() error

AbortMerge cancels a currently ongoing Git merge operation.

func (*Runner) AbortRebase

func (r *Runner) AbortRebase() error

AbortRebase cancels a currently ongoing Git rebase operation.

func (*Runner) AddRemote

func (r *Runner) AddRemote(name, url string) error

AddRemote adds a Git remote with the given name and URL to this repository.

func (*Runner) AddSubmodule

func (r *Runner) AddSubmodule(url string) error

AddSubmodule adds a Git submodule with the given URL to this repository.

func (*Runner) Author

func (r *Runner) Author() (string, error)

Author provides the locally Git configured user.

func (*Runner) BranchHasUnmergedCommits

func (r *Runner) BranchHasUnmergedCommits(branch string) (bool, error)

BranchHasUnmergedCommits indicates whether the branch with the given name contains commits that are not merged into the main branch.

func (*Runner) CheckoutBranch

func (r *Runner) CheckoutBranch(name string) error

CheckoutBranch checks out the Git branch with the given name in this repo.

func (*Runner) CommentOutSquashCommitMessage

func (r *Runner) CommentOutSquashCommitMessage(prefix string) error

CommentOutSquashCommitMessage comments out the message for the current squash merge Adds the given prefix with the newline if provided.

func (*Runner) Commit

func (r *Runner) Commit(message, author string) error

Commit performs a commit of the staged changes with an optional custom message and author.

func (*Runner) CommitNoEdit

func (r *Runner) CommitNoEdit() error

CommitNoEdit commits all staged files with the default commit message.

func (*Runner) CommitStagedChanges

func (r *Runner) CommitStagedChanges(message string) error

CommitStagedChanges commits the currently staged changes.

func (*Runner) Commits

func (r *Runner) Commits(fields []string) ([]Commit, error)

Commits provides a list of the commits in this Git repository with the given fields.

func (*Runner) CommitsInBranch

func (r *Runner) CommitsInBranch(branch string, fields []string) ([]Commit, error)

CommitsInBranch provides all commits in the given Git branch.

func (*Runner) ConnectTrackingBranch

func (r *Runner) ConnectTrackingBranch(name string) error

ConnectTrackingBranch connects the branch with the given name to its counterpart at origin. The branch must exist.

func (*Runner) ContinueRebase

func (r *Runner) ContinueRebase() error

ContinueRebase continues the currently ongoing rebase.

func (*Runner) CreateBranch

func (r *Runner) CreateBranch(name, parent string) error

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

func (r *Runner) CreateChildFeatureBranch(name string, parent string) error

CreateChildFeatureBranch creates a branch with the given name and parent in this repository. The parent branch must already exist.

func (*Runner) CreateCommit

func (r *Runner) CreateCommit(commit Commit) error

CreateCommit creates a commit with the given properties in this Git repo.

func (*Runner) CreateFeatureBranch

func (r *Runner) CreateFeatureBranch(name string) error

CreateFeatureBranch creates a feature branch with the given name in this repository.

func (*Runner) CreateFeatureBranchNoParent

func (r *Runner) CreateFeatureBranchNoParent(name string) error

CreateFeatureBranchNoParent creates a feature branch with no defined parent in this repository.

func (*Runner) CreateFile

func (r *Runner) CreateFile(name, content string) error

CreateFile creates a file with the given name and content in this repository.

func (*Runner) CreatePerennialBranches

func (r *Runner) CreatePerennialBranches(names ...string) error

CreatePerennialBranches creates perennial branches with the given names in this repository.

func (*Runner) CreateRemoteBranch

func (r *Runner) CreateRemoteBranch(localSha, branchName string, noPushVerify bool) error

CreateRemoteBranch creates a remote branch from the given local SHA.

func (*Runner) CreateStandaloneTag

func (r *Runner) CreateStandaloneTag(name string) error

CreateStandaloneTag creates a tag not on a branch.

func (*Runner) CreateTag

func (r *Runner) CreateTag(name string) error

CreateTag creates a tag with the given name.

func (*Runner) CurrentBranch

func (r *Runner) CurrentBranch() (string, error)

CurrentBranch provides the currently checked out branch for this repo.

func (*Runner) CurrentSha

func (r *Runner) CurrentSha() (string, error)

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

func (*Runner) DeleteLastCommit

func (r *Runner) DeleteLastCommit() error

DeleteLastCommit resets HEAD to the previous commit.

func (*Runner) DeleteLocalBranch

func (r *Runner) DeleteLocalBranch(name string, force bool) error

DeleteLocalBranch removes the local branch with the given name.

func (*Runner) DeleteMainBranchConfiguration

func (r *Runner) DeleteMainBranchConfiguration() error

DeleteMainBranchConfiguration removes the configuration for which branch is the main branch.

func (*Runner) DeleteRemoteBranch

func (r *Runner) DeleteRemoteBranch(name string) error

DeleteRemoteBranch removes the remote branch of the given local branch.

func (*Runner) DiffParent

func (r *Runner) DiffParent(branch, parentBranch string) error

DiffParent displays the diff between the given branch and its given parent branch.

func (*Runner) DiscardOpenChanges

func (r *Runner) DiscardOpenChanges() error

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) Fetch

func (r *Runner) Fetch() error

Fetch retrieves the updates from the origin repo.

func (*Runner) FetchUpstream

func (r *Runner) FetchUpstream(branch string) error

FetchUpstream fetches updates from the upstream remote.

func (*Runner) FileContent

func (r *Runner) FileContent(filename string) (string, error)

FileContent provides the current content of a file.

func (*Runner) FileContentInCommit

func (r *Runner) FileContentInCommit(sha string, filename string) (string, error)

FileContentInCommit provides the content of the file with the given name in the commit with the given SHA.

func (*Runner) FilesInBranch

func (r *Runner) FilesInBranch(branch string) ([]string, error)

FilesInBranch provides the list of the files present in the given branch.

func (*Runner) FilesInCommit

func (r *Runner) FilesInCommit(sha string) ([]string, error)

FilesInCommit provides the names of the files that the commit with the given SHA changes.

func (*Runner) HasBranchesOutOfSync

func (r *Runner) HasBranchesOutOfSync() (bool, error)

HasBranchesOutOfSync indicates whether one or more local branches are out of sync with their tracking branch.

func (*Runner) HasConflicts

func (r *Runner) HasConflicts() (bool, error)

HasConflicts returns whether the local repository currently has unresolved merge conflicts.

func (*Runner) HasFile

func (r *Runner) HasFile(name, content string) (bool, error)

HasFile indicates whether this repository contains a file with the given name and content.

func (*Runner) HasGitTownConfigNow

func (r *Runner) HasGitTownConfigNow() (bool, error)

HasGitTownConfigNow indicates whether this repository contain Git Town specific configuration.

func (*Runner) HasLocalBranch

func (r *Runner) HasLocalBranch(name string) (bool, error)

HasLocalBranch indicates whether this repo has a local branch with the given name.

func (*Runner) HasLocalOrOriginBranch added in v7.8.0

func (r *Runner) HasLocalOrOriginBranch(name string) (bool, error)

HasLocalOrRemoteBranch indicates whether this repo or origin have a branch with the given name.

func (*Runner) HasMergeInProgress

func (r *Runner) HasMergeInProgress() (bool, error)

HasMergeInProgress indicates whether this Git repository currently has a merge in progress.

func (*Runner) HasOpenChanges

func (r *Runner) HasOpenChanges() (bool, error)

HasOpenChanges indicates whether this repo has open changes.

func (*Runner) HasOrigin added in v7.8.0

func (r *Runner) HasOrigin() (bool, error)

HasOrigin indicates whether this repo has an origin remote.

func (*Runner) HasRebaseInProgress

func (r *Runner) HasRebaseInProgress() (bool, error)

HasRebaseInProgress indicates whether this Git repository currently has a rebase in progress.

func (*Runner) HasRemote

func (r *Runner) HasRemote(name string) (bool, error)

HasRemote indicates whether this repo has a remote with the given name.

func (*Runner) HasShippableChanges

func (r *Runner) HasShippableChanges(branch string) (bool, error)

HasShippableChanges indicates whether the given branch has changes not currently in the main branch.

func (*Runner) HasTrackingBranch

func (r *Runner) HasTrackingBranch(name string) (bool, error)

HasTrackingBranch indicates whether the local branch with the given name has a remote tracking branch.

func (*Runner) IsBranchInSync

func (r *Runner) IsBranchInSync(branchName string) (bool, error)

IsBranchInSync returns whether the branch with the given name is in sync with its tracking branch.

func (*Runner) IsRepository

func (r *Runner) IsRepository() bool

IsRepository returns whether or not the current directory is in a repository.

func (*Runner) LastCommitMessage

func (r *Runner) LastCommitMessage() (string, error)

LastCommitMessage provides the commit message for the last commit.

func (*Runner) LocalAndOriginBranches added in v7.8.0

func (r *Runner) LocalAndOriginBranches() ([]string, error)

LocalAndOriginBranches provides the names of all local branches in this repo.

func (*Runner) LocalBranches

func (r *Runner) LocalBranches() ([]string, error)

LocalBranches provides the names of all branches in the local repository, ordered alphabetically.

func (*Runner) LocalBranchesMainFirst

func (r *Runner) LocalBranchesMainFirst() ([]string, error)

LocalBranchesMainFirst provides the names of all local branches in this repo.

func (*Runner) LocalBranchesWithDeletedTrackingBranches

func (r *Runner) LocalBranchesWithDeletedTrackingBranches() ([]string, error)

LocalBranchesWithDeletedTrackingBranches provides the names of all branches whose remote tracking branches have been deleted.

func (*Runner) LocalBranchesWithoutMain

func (r *Runner) LocalBranchesWithoutMain() ([]string, error)

LocalBranchesWithoutMain provides the names of all branches in the local repository, ordered alphabetically without the main branch.

func (*Runner) MergeBranchNoEdit

func (r *Runner) MergeBranchNoEdit(branch string) error

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

func (*Runner) PopStash

func (r *Runner) PopStash() error

PopStash restores stashed-away changes into the workspace.

func (*Runner) PreviouslyCheckedOutBranch

func (r *Runner) PreviouslyCheckedOutBranch() (string, error)

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

func (*Runner) Pull

func (r *Runner) Pull() error

Pull fetches updates from origin and updates the currently checked out branch.

func (*Runner) PushBranch

func (r *Runner) PushBranch(options ...PushArgs) error

PushBranch pushes the branch with the given name to origin.

func (*Runner) PushTags

func (r *Runner) PushTags() error

PushTags pushes new the Git tags to origin.

func (*Runner) Rebase

func (r *Runner) Rebase(target string) error

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

func (*Runner) RemoteBranches

func (r *Runner) RemoteBranches() ([]string, error)

RemoteBranches provides the names of the remote branches in this repo.

func (*Runner) Remotes

func (r *Runner) Remotes() ([]string, error)

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

func (*Runner) RemoveBranch

func (r *Runner) RemoveBranch(name string) error

RemoveBranch deletes the branch with the given name from this repo.

func (*Runner) RemoveRemote

func (r *Runner) RemoveRemote(name string) error

RemoveRemote deletes the Git remote with the given name.

func (*Runner) RemoveUnnecessaryFiles

func (r *Runner) RemoveUnnecessaryFiles() error

RemoveUnnecessaryFiles trims all files that aren't necessary in this repo.

func (*Runner) ResetToSha

func (r *Runner) ResetToSha(sha string, hard bool) error

ResetToSha undoes all commits on the current branch all the way until the given SHA.

func (*Runner) RevertCommit

func (r *Runner) RevertCommit(sha string) error

RevertCommit reverts the commit with the given SHA.

func (*Runner) RootDirectory

func (r *Runner) RootDirectory() (string, error)

RootDirectory provides the path of the rood directory of the current repository, i.e. the directory that contains the ".git" folder.

func (*Runner) ShaForBranch

func (r *Runner) ShaForBranch(name string) (string, error)

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

func (*Runner) ShaForCommit

func (r *Runner) ShaForCommit(name string) (string, error)

ShaForCommit provides the SHA for the commit with the given name.

func (*Runner) ShouldPushBranch

func (r *Runner) ShouldPushBranch(branch string) (bool, error)

ShouldPushBranch returns whether the local branch with the given name contains commits that have not been pushed to its tracking branch.

func (*Runner) SquashMerge

func (r *Runner) SquashMerge(branch string) error

SquashMerge squash-merges the given branch into the current branch.

func (*Runner) StageFiles

func (r *Runner) StageFiles(names ...string) error

StageFiles adds the file with the given name to the Git index.

func (*Runner) StartCommit

func (r *Runner) StartCommit() error

StartCommit starts a commit and stops at asking the user for the commit message.

func (*Runner) Stash

func (r *Runner) Stash() error

Stash adds the current files to the Git stash.

func (*Runner) StashSize

func (r *Runner) StashSize() (int, error)

StashSize provides the number of stashes in this repository.

func (*Runner) Tags

func (r *Runner) Tags() ([]string, error)

Tags provides a list of the tags in this repository.

func (*Runner) TrackingBranchName

func (r *Runner) TrackingBranchName(branch string) string

TrackingBranchName provides the name of the remote branch tracking the local branch with the given name.

func (*Runner) UncommittedFiles

func (r *Runner) UncommittedFiles() ([]string, error)

UncommittedFiles provides the names of the files not committed into Git.

func (*Runner) Version

func (r *Runner) Version() (major int, minor int, err error)

Version indicates whether the needed Git version is installed.

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.

func (*StringCache) Value

func (sc *StringCache) Value() string

Value provides the current value.

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.

Jump to

Keyboard shortcuts

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