Documentation ¶
Overview ¶
Package gitdomain defines basic concepts from the domain of Git: branches, remotes, commit SHAs, etc.
Index ¶
- Constants
- Variables
- func NewLocalBranchNameOption(id string) Option[LocalBranchName]
- type Author
- type BranchInfo
- func (self BranchInfo) GetLocal() (bool, LocalBranchName, SHA)
- func (self BranchInfo) GetRemote() (bool, RemoteBranchName, SHA)
- func (self BranchInfo) GetSHAs() (hasBothSHA bool, localSHA, remoteSHA SHA)
- func (self BranchInfo) HasLocalBranch() (hasLocalBranch bool, branchName LocalBranchName, sha SHA)
- func (self BranchInfo) HasOnlyLocalBranch() bool
- func (self BranchInfo) HasOnlyRemoteBranch() bool
- func (self BranchInfo) HasRemoteBranch() (hasRemoteBranch bool, remoteBranchName RemoteBranchName, remoteBranchSHA SHA)
- func (self BranchInfo) HasTrackingBranch() bool
- func (self BranchInfo) IsOmniBranch() (isOmni bool, branch LocalBranchName, sha SHA)
- func (self BranchInfo) String() string
- type BranchInfos
- func (self BranchInfos) FindByLocalName(branchName LocalBranchName) Option[BranchInfo]
- func (self BranchInfos) FindByRemoteName(remoteBranch RemoteBranchName) *BranchInfo
- func (self BranchInfos) FindMatchingRecord(other BranchInfo) Option[BranchInfo]
- func (self BranchInfos) HasLocalBranch(branch LocalBranchName) bool
- func (self BranchInfos) HasLocalBranches(branches LocalBranchNames) bool
- func (self BranchInfos) HasMatchingTrackingBranchFor(localBranch LocalBranchName) bool
- func (self BranchInfos) LocalBranches() BranchInfos
- func (self BranchInfos) LocalBranchesWithDeletedTrackingBranches() BranchInfos
- func (self BranchInfos) Names() LocalBranchNames
- func (self BranchInfos) Remove(branchName LocalBranchName) BranchInfos
- func (self BranchInfos) Select(names ...LocalBranchName) (BranchInfos, error)
- func (self BranchInfos) UpdateLocalSHA(branch LocalBranchName, sha SHA) error
- type BranchName
- type BranchesSnapshot
- type Commit
- type CommitMessage
- type CommitMessageParts
- type CommitMessages
- type Commits
- type LocalBranchName
- type LocalBranchNames
- func (self LocalBranchNames) AppendAllMissing(others ...LocalBranchName) LocalBranchNames
- func (self LocalBranchNames) Contains(branch LocalBranchName) bool
- func (self LocalBranchNames) Hoist(needle LocalBranchName) LocalBranchNames
- func (self LocalBranchNames) Join(sep string) string
- func (self *LocalBranchNames) Prepend(branch LocalBranchName)
- func (self LocalBranchNames) Remove(toRemove ...LocalBranchName) LocalBranchNames
- func (self LocalBranchNames) RemoveWorktreeMarkers() LocalBranchNames
- func (self LocalBranchNames) Sort()
- func (self LocalBranchNames) String() string
- func (self LocalBranchNames) Strings() []string
- type Location
- type ManyRunner
- type Querier
- type Remote
- type RemoteBranchName
- type RemoteBranchNames
- type Remotes
- type RepoRootDir
- type RepoStatus
- type Runner
- type RunnerQuerier
- type SHA
- type SHAs
- type StashSize
- type SyncStatus
Constants ¶
const ( RemoteNone = Remote("") RemoteOrigin = Remote("origin") RemoteOther = Remote("other") RemoteUpstream = Remote("upstream") )
Variables ¶
var AllRemotes = []Remote{ RemoteNone, RemoteOrigin, RemoteOther, RemoteUpstream, }
Functions ¶
func NewLocalBranchNameOption ¶ added in v14.2.1
func NewLocalBranchNameOption(id string) Option[LocalBranchName]
Types ¶
type Author ¶ added in v14.1.0
type Author string
Author represents the author of a commit in the format "name <email>"
type BranchInfo ¶
type BranchInfo struct { // LocalName contains the local name of the branch. LocalName Option[LocalBranchName] // LocalSHA contains the SHA that this branch had locally before Git Town ran. LocalSHA Option[SHA] // RemoteName contains the fully qualified name of the tracking branch, i.e. "origin/foo". RemoteName Option[RemoteBranchName] // RemoteSHA contains the SHA of the tracking branch before Git Town ran. RemoteSHA Option[SHA] // SyncStatus of the branch SyncStatus SyncStatus }
BranchInfo describes the sync status of a branch in relation to its tracking branch.
func (BranchInfo) GetLocal ¶ added in v14.2.1
func (self BranchInfo) GetLocal() (bool, LocalBranchName, SHA)
provides both the name and SHA of the local branch
func (BranchInfo) GetRemote ¶ added in v14.2.1
func (self BranchInfo) GetRemote() (bool, RemoteBranchName, SHA)
provides both the name and SHA of the remote branch
func (BranchInfo) GetSHAs ¶ added in v14.2.1
func (self BranchInfo) GetSHAs() (hasBothSHA bool, localSHA, remoteSHA SHA)
provides the SHAs of the local and remote branch
func (BranchInfo) HasLocalBranch ¶
func (self BranchInfo) HasLocalBranch() (hasLocalBranch bool, branchName LocalBranchName, sha SHA)
func (BranchInfo) HasOnlyLocalBranch ¶
func (self BranchInfo) HasOnlyLocalBranch() bool
func (BranchInfo) HasOnlyRemoteBranch ¶
func (self BranchInfo) HasOnlyRemoteBranch() bool
func (BranchInfo) HasRemoteBranch ¶
func (self BranchInfo) HasRemoteBranch() (hasRemoteBranch bool, remoteBranchName RemoteBranchName, remoteBranchSHA SHA)
func (BranchInfo) HasTrackingBranch ¶
func (self BranchInfo) HasTrackingBranch() bool
func (BranchInfo) IsOmniBranch ¶
func (self BranchInfo) IsOmniBranch() (isOmni bool, branch LocalBranchName, sha SHA)
Indicates whether the branch described by this BranchInfo is omni and provides all relevant data around this scenario. An omni branch has the same SHA locally and remotely.
func (BranchInfo) String ¶ added in v14.2.1
func (self BranchInfo) String() string
type BranchInfos ¶
type BranchInfos []BranchInfo
BranchInfos contains the BranchInfos for all branches in a repo. Tracking branches on the origin remote don't get their own entry, they are listed in the `TrackingBranch` property of the local branch they track.
func (BranchInfos) FindByLocalName ¶
func (self BranchInfos) FindByLocalName(branchName LocalBranchName) Option[BranchInfo]
FindByLocalName provides the branch with the given name if one exists.
func (BranchInfos) FindByRemoteName ¶
func (self BranchInfos) FindByRemoteName(remoteBranch RemoteBranchName) *BranchInfo
FindByRemoteName provides the local branch that has the given remote branch as its tracking branch or nil if no such branch exists.
func (BranchInfos) FindMatchingRecord ¶
func (self BranchInfos) FindMatchingRecord(other BranchInfo) Option[BranchInfo]
func (BranchInfos) HasLocalBranch ¶
func (self BranchInfos) HasLocalBranch(branch LocalBranchName) bool
HasLocalBranch indicates whether the given local branch is already known to this BranchInfos instance.
func (BranchInfos) HasLocalBranches ¶
func (self BranchInfos) HasLocalBranches(branches LocalBranchNames) bool
HasLocalBranches indicates whether this BranchInfos instance contains all the given branches.
func (BranchInfos) HasMatchingTrackingBranchFor ¶
func (self BranchInfos) HasMatchingTrackingBranchFor(localBranch LocalBranchName) bool
HasMatchingRemoteBranchFor indicates whether there is already a remote branch matching the given local branch.
func (BranchInfos) LocalBranches ¶
func (self BranchInfos) LocalBranches() BranchInfos
LocalBranches provides only the branches that exist on the local machine.
func (BranchInfos) LocalBranchesWithDeletedTrackingBranches ¶
func (self BranchInfos) LocalBranchesWithDeletedTrackingBranches() BranchInfos
LocalBranchesWithDeletedTrackingBranches provides only the branches that exist locally and have a deleted tracking branch.
func (BranchInfos) Names ¶
func (self BranchInfos) Names() LocalBranchNames
Names provides the names of all local branches in this BranchesSyncStatus instance.
func (BranchInfos) Remove ¶
func (self BranchInfos) Remove(branchName LocalBranchName) BranchInfos
func (BranchInfos) Select ¶
func (self BranchInfos) Select(names ...LocalBranchName) (BranchInfos, error)
Select provides the BranchSyncStatus elements with the given names.
func (BranchInfos) UpdateLocalSHA ¶
func (self BranchInfos) UpdateLocalSHA(branch LocalBranchName, sha SHA) error
type BranchName ¶
type BranchName string
BranchName is the name of a local or remote Git branch.
func NewBranchName ¶
func NewBranchName(id string) BranchName
func (BranchName) IsLocal ¶
func (self BranchName) IsLocal() bool
IsLocal indicates whether the branch with this BranchName exists locally.
func (BranchName) LocalName ¶
func (self BranchName) LocalName() LocalBranchName
LocalName provides the local version of this branch name.
func (BranchName) RemoteName ¶
func (self BranchName) RemoteName() RemoteBranchName
RemoteName provides the remote version of this branch name.
func (BranchName) String ¶
func (self BranchName) String() string
Implementation of the fmt.Stringer interface.
type BranchesSnapshot ¶
type BranchesSnapshot struct { // the branch that was checked out at the time the snapshot was taken Active Option[LocalBranchName] // Branches is a read-only copy of the branches that exist in this repo at the time the snapshot was taken. // Don't use these branches for business logic since businss logic might want to modify its in-memory cache of branches // as it adds or removes branches. Branches BranchInfos }
BranchesSnapshot is a snapshot of the Git branches at a particular point in time.
func EmptyBranchesSnapshot ¶
func EmptyBranchesSnapshot() BranchesSnapshot
type Commit ¶
type Commit struct { Message CommitMessage SHA SHA }
type CommitMessage ¶
type CommitMessage string
CommitMessage is the entire textual messages of a Git commit.
func (CommitMessage) Parts ¶
func (self CommitMessage) Parts() CommitMessageParts
Parts separates the parts of the given commit message.
func (CommitMessage) String ¶
func (self CommitMessage) String() string
String implements the fmt.Stringer interface.
type CommitMessageParts ¶
type CommitMessageParts struct { Subject string // the first line of the commit message Text string // the commit message text minus the first line and empty lines separating it from the rest of the message }
CommitMessageParts describes the parts of a Git commit message.
type CommitMessages ¶
type CommitMessages []CommitMessage
func NewCommitMessages ¶
func NewCommitMessages(messages ...string) CommitMessages
type Commits ¶
type Commits []Commit
func (Commits) ContainsSHA ¶
ContainsSHA indicates whether this commits list contains a commit with the given SHA.
func (Commits) Messages ¶
func (self Commits) Messages() CommitMessages
type LocalBranchName ¶
type LocalBranchName string
LocalBranchName is the name of a local Git branch. The zero value is an empty local branch name, i.e. a local branch name that is unknown or not configured.
func NewLocalBranchName ¶
func NewLocalBranchName(id string) LocalBranchName
func (LocalBranchName) AtRemote ¶
func (self LocalBranchName) AtRemote(remote Remote) RemoteBranchName
AtRemote provides the RemoteBranchName of this branch at the given remote.
func (LocalBranchName) BranchName ¶
func (self LocalBranchName) BranchName() BranchName
BranchName widens the type of this LocalBranchName to a more generic BranchName.
func (LocalBranchName) Location ¶
func (self LocalBranchName) Location() Location
Location widens the type of this LocalBranchName to a more generic Location.
func (LocalBranchName) String ¶
func (self LocalBranchName) String() string
Implementation of the fmt.Stringer interface.
func (LocalBranchName) TrackingBranch ¶
func (self LocalBranchName) TrackingBranch() RemoteBranchName
TrackingBranch provides the name of the tracking branch for this local branch.
type LocalBranchNames ¶
type LocalBranchNames []LocalBranchName
func NewLocalBranchNames ¶
func NewLocalBranchNames(names ...string) LocalBranchNames
func ParseLocalBranchNames ¶ added in v14.2.1
func ParseLocalBranchNames(names string) LocalBranchNames
ParseLocalBranchNamesRef constructs a LocalBranchNames instance containing the branches listed in the given space-separated string.
func (LocalBranchNames) AppendAllMissing ¶
func (self LocalBranchNames) AppendAllMissing(others ...LocalBranchName) LocalBranchNames
AppendAllMissing provides a LocalBranchNames list consisting of the sum of this and elements of other list that aren't in this list.
func (LocalBranchNames) Contains ¶
func (self LocalBranchNames) Contains(branch LocalBranchName) bool
Contains indicates whether this collection contains the given branch.
func (LocalBranchNames) Hoist ¶
func (self LocalBranchNames) Hoist(needle LocalBranchName) LocalBranchNames
Hoist moves the given needle to the front of the list.
func (LocalBranchNames) Join ¶
func (self LocalBranchNames) Join(sep string) string
Join provides the names of all branches in this collection connected by the given separator.
func (*LocalBranchNames) Prepend ¶
func (self *LocalBranchNames) Prepend(branch LocalBranchName)
func (LocalBranchNames) Remove ¶
func (self LocalBranchNames) Remove(toRemove ...LocalBranchName) LocalBranchNames
Remove removes the given branch names from this collection.
func (LocalBranchNames) RemoveWorktreeMarkers ¶
func (self LocalBranchNames) RemoveWorktreeMarkers() LocalBranchNames
RemoveWorktreeMarkers removes the workspace markers from the branch names in this list.
func (LocalBranchNames) Sort ¶
func (self LocalBranchNames) Sort()
Sort orders the branches in this collection alphabetically.
func (LocalBranchNames) String ¶
func (self LocalBranchNames) String() string
func (LocalBranchNames) Strings ¶
func (self LocalBranchNames) Strings() []string
Strings provides the names of all branches in this collection as strings.
type Location ¶
type Location string
Location is a location within a Git repo. Examples for locations are SHA addresses of commits or branch names.
func NewLocation ¶
type ManyRunner ¶ added in v14.2.2
type RemoteBranchName ¶
type RemoteBranchName string
RemoteBranchName is the name of a remote branch, e.g. "origin/foo".
func NewRemoteBranchName ¶
func NewRemoteBranchName(id string) RemoteBranchName
func (RemoteBranchName) BranchName ¶
func (self RemoteBranchName) BranchName() BranchName
BranchName widens the type of this RemoteBranchName to a more generic BranchName.
func (RemoteBranchName) LocalBranchName ¶
func (self RemoteBranchName) LocalBranchName() LocalBranchName
LocalBranchName provides the name of the local branch that this remote branch tracks.
func (RemoteBranchName) Parts ¶
func (self RemoteBranchName) Parts() (Remote, LocalBranchName)
func (RemoteBranchName) Remote ¶
func (self RemoteBranchName) Remote() Remote
func (RemoteBranchName) String ¶
func (self RemoteBranchName) String() string
Implementation of the fmt.Stringer interface.
type RemoteBranchNames ¶
type RemoteBranchNames []RemoteBranchName
func (RemoteBranchNames) Sort ¶
func (self RemoteBranchNames) Sort()
Sort orders the branches in this collection alphabetically.
func (RemoteBranchNames) Strings ¶
func (self RemoteBranchNames) Strings() []string
Strings provides these remote branch names as strings.
type Remotes ¶
type Remotes []Remote
Remotes answers questions which Git remotes a repo has.
func NewRemotes ¶
func (Remotes) HasUpstream ¶
type RepoRootDir ¶
type RepoRootDir string
RepoRootDir represents the root directory of a Git repository.
func NewRepoRootDir ¶
func NewRepoRootDir(dir string) RepoRootDir
func (RepoRootDir) String ¶
func (self RepoRootDir) String() string
type RepoStatus ¶
type RunnerQuerier ¶ added in v14.2.2
type RunnerQuerier interface { Runner ManyRunner Querier }
type SHA ¶
type SHA string
SHA represents a Git SHA as a dedicated data type. This helps avoid stringly-typed code.
func NewSHA ¶
NewSHA creates a new SHA instance with the given value. The value is verified for correctness.
func (SHA) TruncateTo ¶
TruncateTo provides a new SHA instance that contains a shorter checksum.
type SyncStatus ¶
type SyncStatus string
SyncStatus encodes the places a branch can exist at. This is a type-safe enum, see https://npf.io/2022/05/safer-enums.
const ( SyncStatusUpToDate SyncStatus = "up to date" // the branch exists locally and remotely, the local branch is up to date SyncStatusNotInSync SyncStatus = "not in sync" // the branch exists locally and remotely, the local branch is behind the remote tracking branch SyncStatusLocalOnly SyncStatus = "local only" // the branch was created locally and hasn't been pushed to the remote yet SyncStatusRemoteOnly SyncStatus = "remote only" // the branch exists only at the remote SyncStatusDeletedAtRemote SyncStatus = "deleted at remote" // the branch was deleted on the remote SyncStatusOtherWorktree SyncStatus = "active in another worktree" // the branch is active in another worktree and should not be synced )
func (SyncStatus) String ¶
func (self SyncStatus) String() string
Source Files ¶
- author.go
- branch_info.go
- branch_infos.go
- branch_name.go
- branches_snapshot.go
- commit.go
- commit_message.go
- commit_messages.go
- commits.go
- core.go
- local_branch_name.go
- local_branch_names.go
- location.go
- querier.go
- remote.go
- remote_branch_name.go
- remote_branch_names.go
- remotes.go
- repo_root_dir.go
- repo_status.go
- runner.go
- sha.go
- shas.go
- stash_size.go
- sync_status.go