Documentation ¶
Overview ¶
Package config provides facilities to read and write the Git Town configuration. Git Town stores its configuration in the Git configuration under the prefix "git-town". It supports both the Git configuration for the local repository as well as the global Git configuration in `~/.gitconfig`. You can manually read the Git configuration entries for Git Town by running `git config --get-regexp git-town`.
Index ¶
- Variables
- func DetermineOriginURL(originURL, originOverride string, originURLCache OriginURLCache) *giturl.Parts
- func ParseBool(text string) (bool, error)
- type Alias
- type Git
- func (self Git) GlobalConfigClone() GitConfigCache
- func (self Git) GlobalConfigValue(key Key) string
- func (self Git) LocalConfigClone() GitConfigCache
- func (self Git) LocalConfigKeysMatching(pattern string) []Key
- func (self Git) LocalConfigValue(key Key) string
- func (self Git) LocalOrGlobalConfigValue(key Key) string
- func (self *Git) Reload()
- func (self *Git) RemoveGlobalConfigValue(key Key) error
- func (self *Git) RemoveLocalConfigValue(key Key) error
- func (self *Git) SetGlobalConfigValue(key Key, value string) error
- func (self *Git) SetLocalConfigValue(key Key, value string) error
- type GitConfig
- type GitConfigCache
- type GitTown
- func (self *GitTown) AddToPerennialBranches(branches ...domain.LocalBranchName) error
- func (self *GitTown) BranchTypes() domain.BranchTypes
- func (self *GitTown) DeprecatedNewBranchPushFlagGlobal() string
- func (self *GitTown) DeprecatedNewBranchPushFlagLocal() string
- func (self *GitTown) DeprecatedPushVerifyFlagGlobal() string
- func (self *GitTown) DeprecatedPushVerifyFlagLocal() string
- func (self *GitTown) GitAlias(alias Alias) string
- func (self *GitTown) GitHubToken() string
- func (self *GitTown) GitLabToken() string
- func (self *GitTown) GiteaToken() string
- func (self *GitTown) HasBranchInformation() bool
- func (self *GitTown) HostingService() (Hosting, error)
- func (self *GitTown) HostingServiceName() string
- func (self *GitTown) IsMainBranch(branch domain.LocalBranchName) bool
- func (self *GitTown) IsOffline() (bool, error)
- func (self *GitTown) Lineage(deleteEntry func(Key) error) Lineage
- func (self *GitTown) MainBranch() domain.LocalBranchName
- func (self *GitTown) OriginOverride() string
- func (self *GitTown) OriginURL() *giturl.Parts
- func (self *GitTown) OriginURLString() string
- func (self *GitTown) PerennialBranches() domain.LocalBranchNames
- func (self *GitTown) PullBranchStrategy() (PullBranchStrategy, error)
- func (self *GitTown) PushHook() (bool, error)
- func (self *GitTown) PushHookGlobal() (bool, error)
- func (self *GitTown) RemoveFromPerennialBranches(branch domain.LocalBranchName) error
- func (self *GitTown) RemoveLocalGitConfiguration() error
- func (self *GitTown) RemoveMainBranchConfiguration() error
- func (self *GitTown) RemoveParent(branch domain.LocalBranchName)
- func (self *GitTown) RemovePerennialBranchConfiguration() error
- func (self *GitTown) SetCodeHostingDriver(value string) error
- func (self *GitTown) SetCodeHostingOriginHostname(value string) error
- func (self *GitTown) SetColorUI(value string) error
- func (self *GitTown) SetMainBranch(branch domain.LocalBranchName) error
- func (self *GitTown) SetNewBranchPush(value bool, global bool) error
- func (self *GitTown) SetOffline(value bool) error
- func (self *GitTown) SetParent(branch, parentBranch domain.LocalBranchName) error
- func (self *GitTown) SetPerennialBranches(branches domain.LocalBranchNames) error
- func (self *GitTown) SetPullBranchStrategy(strategy PullBranchStrategy) error
- func (self *GitTown) SetPushHookGlobally(value bool) error
- func (self *GitTown) SetPushHookLocally(value bool) error
- func (self *GitTown) SetShouldShipDeleteRemoteBranch(value bool) error
- func (self *GitTown) SetShouldSyncUpstream(value bool) error
- func (self *GitTown) SetSyncStrategy(value SyncStrategy) error
- func (self *GitTown) SetSyncStrategyGlobal(value SyncStrategy) error
- func (self *GitTown) SetTestOrigin(value string) error
- func (self *GitTown) ShouldNewBranchPush() (bool, error)
- func (self *GitTown) ShouldNewBranchPushGlobal() (bool, error)
- func (self *GitTown) ShouldShipDeleteOriginBranch() (bool, error)
- func (self *GitTown) ShouldSyncUpstream() (bool, error)
- func (self *GitTown) SyncStrategy() (SyncStrategy, error)
- func (self *GitTown) SyncStrategyGlobal() (SyncStrategy, error)
- type Hosting
- type Key
- type Lineage
- func (self Lineage) Ancestors(branch domain.LocalBranchName) domain.LocalBranchNames
- func (self Lineage) BranchAndAncestors(branchName domain.LocalBranchName) domain.LocalBranchNames
- func (self Lineage) BranchNames() domain.LocalBranchNames
- func (self Lineage) BranchesAndAncestors(branchNames domain.LocalBranchNames) domain.LocalBranchNames
- func (self Lineage) Children(branch domain.LocalBranchName) domain.LocalBranchNames
- func (self Lineage) HasParents(branch domain.LocalBranchName) bool
- func (self Lineage) IsAncestor(ancestor, other domain.LocalBranchName) bool
- func (self Lineage) OrderHierarchically(branches domain.LocalBranchNames)
- func (self Lineage) Parent(branch domain.LocalBranchName) domain.LocalBranchName
- func (self Lineage) RemoveBranch(branch domain.LocalBranchName)
- func (self Lineage) Roots() domain.LocalBranchNames
- type OriginURLCache
- type PullBranchStrategy
- type SyncStrategy
Constants ¶
This section is empty.
Variables ¶
var ( AliasAppend = Alias{"append"} //nolint:gochecknoglobals AliasDiffParent = Alias{"diff-parent"} //nolint:gochecknoglobals AliasHack = Alias{"hack"} //nolint:gochecknoglobals AliasKill = Alias{"kill"} //nolint:gochecknoglobals AliasNewPullRequest = Alias{"new-pull-request"} //nolint:gochecknoglobals AliasPrepend = Alias{"prepend"} //nolint:gochecknoglobals AliasRenameBranch = Alias{"rename-branch"} //nolint:gochecknoglobals AliasRepo = Alias{"repo"} //nolint:gochecknoglobals AliasShip = Alias{"ship"} //nolint:gochecknoglobals AliasSync = Alias{"sync"} //nolint:gochecknoglobals )
var ( HostingBitbucket = Hosting{"bitbucket"} //nolint:gochecknoglobals HostingGitHub = Hosting{"github"} //nolint:gochecknoglobals HostingGitLab = Hosting{"gitlab"} //nolint:gochecknoglobals HostingGitea = Hosting{"gitea"} //nolint:gochecknoglobals HostingNone = Hosting{""} //nolint:gochecknoglobals )
var ( KeyAliasAppend = Key{"alias." + AliasAppend.name} //nolint:gochecknoglobals KeyAliasDiffParent = Key{"alias." + AliasDiffParent.name} //nolint:gochecknoglobals KeyAliasHack = Key{"alias." + AliasHack.name} //nolint:gochecknoglobals KeyAliasKill = Key{"alias." + AliasKill.name} //nolint:gochecknoglobals KeyAliasNewPullRequest = Key{"alias." + AliasNewPullRequest.name} //nolint:gochecknoglobals KeyAliasPrepend = Key{"alias." + AliasPrepend.name} //nolint:gochecknoglobals KeyAliasRenameBranch = Key{"alias." + AliasRenameBranch.name} //nolint:gochecknoglobals KeyAliasRepo = Key{"alias." + AliasRepo.name} //nolint:gochecknoglobals KeyAliasShip = Key{"alias." + AliasShip.name} //nolint:gochecknoglobals KeyAliasSync = Key{"alias." + AliasSync.name} //nolint:gochecknoglobals KeyCodeHostingDriver = Key{"git-town.code-hosting-driver"} //nolint:gochecknoglobals KeyCodeHostingOriginHostname = Key{"git-town.code-hosting-origin-hostname"} //nolint:gochecknoglobals KeyDeprecatedNewBranchPushFlag = Key{"git-town.new-branch-push-flag"} //nolint:gochecknoglobals KeyDeprecatedPushVerify = Key{"git-town.push-verify"} //nolint:gochecknoglobals KeyGiteaToken = Key{"git-town.gitea-token"} //nolint:gochecknoglobals KeyGithubToken = Key{"git-town.github-token"} //nolint:gochecknoglobals KeyGitlabToken = Key{"git-town.gitlab-token"} //nolint:gochecknoglobals KeyMainBranch = Key{"git-town.main-branch-name"} //nolint:gochecknoglobals KeyOffline = Key{"git-town.offline"} //nolint:gochecknoglobals KeyPerennialBranches = Key{"git-town.perennial-branch-names"} //nolint:gochecknoglobals KeyPullBranchStrategy = Key{"git-town.pull-branch-strategy"} //nolint:gochecknoglobals KeyPushHook = Key{"git-town.push-hook"} //nolint:gochecknoglobals KeyPushNewBranches = Key{"git-town.push-new-branches"} //nolint:gochecknoglobals KeyShipDeleteRemoteBranch = Key{"git-town.ship-delete-remote-branch"} //nolint:gochecknoglobals KeySyncUpstream = Key{"git-town.sync-upstream"} //nolint:gochecknoglobals KeySyncStrategy = Key{"git-town.sync-strategy"} //nolint:gochecknoglobals KeyTestingRemoteURL = Key{"git-town.testing.remote-url"} //nolint:gochecknoglobals )
var ( PullBranchStrategyMerge = PullBranchStrategy{"merge"} //nolint:gochecknoglobals PullBranchStrategyRebase = PullBranchStrategy{"rebase"} //nolint:gochecknoglobals )
var ( SyncStrategyMerge = SyncStrategy{"merge"} //nolint:gochecknoglobals SyncStrategyRebase = SyncStrategy{"rebase"} //nolint:gochecknoglobals )
Functions ¶
func DetermineOriginURL ¶
func DetermineOriginURL(originURL, originOverride string, originURLCache OriginURLCache) *giturl.Parts
Types ¶
type Alias ¶
type Alias struct {
// contains filtered or unexported fields
}
Alias defines Git Town commands that can be aliased. This is a type-safe enum, see https://npf.io/2022/05/safer-enums.
type Git ¶
type Git struct {
// contains filtered or unexported fields
}
Git manages configuration data stored in Git metadata. Supports configuration in the local repo and the global Git configuration.
func NewGit ¶
NewConfiguration provides a Configuration instance reflecting the configuration values in the given directory.
func (Git) GlobalConfigClone ¶
func (self Git) GlobalConfigClone() GitConfigCache
func (Git) GlobalConfigValue ¶
func (Git) LocalConfigClone ¶
func (self Git) LocalConfigClone() GitConfigCache
func (Git) LocalConfigKeysMatching ¶
func (Git) LocalConfigValue ¶
func (Git) LocalOrGlobalConfigValue ¶
LocalOrGlobalConfigValue provides the configuration value with the given key from the local and global Git configuration. Local configuration takes precedence.
func (*Git) Reload ¶
func (self *Git) Reload()
Reload refreshes the cached configuration information.
func (*Git) RemoveGlobalConfigValue ¶
func (*Git) RemoveLocalConfigValue ¶
removeLocalConfigurationValue deletes the configuration value with the given key from the local Git Town configuration.
func (*Git) SetGlobalConfigValue ¶
SetGlobalConfigValue sets the given configuration setting in the global Git configuration.
type GitConfig ¶
type GitConfig struct { Global GitConfigCache Local GitConfigCache }
GitConfig is an in-memory representation of the total Git configuration, global and local.
func LoadGitConfig ¶
func LoadGitConfig(runner runner) GitConfig
type GitConfigCache ¶
func LoadGitConfigCache ¶
func LoadGitConfigCache(runner runner, global bool) GitConfigCache
LoadGit provides the Git configuration from the given directory or the global one if the global flag is set.
func (GitConfigCache) Clone ¶
func (self GitConfigCache) Clone() GitConfigCache
Clone provides a copy of this GitConfiguration instance.
func (GitConfigCache) KeysMatching ¶
func (self GitConfigCache) KeysMatching(pattern string) []Key
KeysMatching provides the keys in this GitConfigCache that match the given regex.
type GitTown ¶
type GitTown struct { Git // contains filtered or unexported fields }
GitTown provides type-safe access to Git Town configuration settings stored in the local and global Git configuration.
func NewGitTown ¶
func (*GitTown) AddToPerennialBranches ¶
func (self *GitTown) AddToPerennialBranches(branches ...domain.LocalBranchName) error
AddToPerennialBranches registers the given branch names as perennial branches. The branches must exist.
func (*GitTown) BranchTypes ¶
func (self *GitTown) BranchTypes() domain.BranchTypes
func (*GitTown) DeprecatedNewBranchPushFlagGlobal ¶
func (*GitTown) DeprecatedNewBranchPushFlagLocal ¶
func (*GitTown) DeprecatedPushVerifyFlagGlobal ¶
func (*GitTown) DeprecatedPushVerifyFlagLocal ¶
func (*GitTown) GitAlias ¶
GitAlias provides the currently set alias for the given Git Town command.
func (*GitTown) GitHubToken ¶
GitHubToken provides the content of the GitHub API token stored in the local or global Git Town configuration.
func (*GitTown) GitLabToken ¶
GitLabToken provides the content of the GitLab API token stored in the local or global Git Town configuration.
func (*GitTown) GiteaToken ¶
GiteaToken provides the content of the Gitea API token stored in the local or global Git Town configuration.
func (*GitTown) HasBranchInformation ¶
HasBranchInformation indicates whether this configuration contains any branch hierarchy entries.
func (*GitTown) HostingService ¶
HostingService provides the type-safe name of the code hosting connector to use. This function caches its result and can be queried repeatedly.
func (*GitTown) HostingServiceName ¶
HostingServiceName provides the name of the code hosting connector to use.
func (*GitTown) IsMainBranch ¶
func (self *GitTown) IsMainBranch(branch domain.LocalBranchName) bool
IsMainBranch indicates whether the branch with the given name is the main branch of the repository.
func (*GitTown) MainBranch ¶
func (self *GitTown) MainBranch() domain.LocalBranchName
MainBranch provides the name of the main branch.
func (*GitTown) OriginOverride ¶
OriginOverride provides the override for the origin hostname from the Git Town configuration.
func (*GitTown) OriginURL ¶
OriginURL provides the URL for the "origin" remote. Tests can stub this through the GIT_TOWN_REMOTE environment variable. Caches its result so can be called repeatedly.
func (*GitTown) OriginURLString ¶
OriginURLString provides the URL for the "origin" remote. Tests can stub this through the GIT_TOWN_REMOTE environment variable.
func (*GitTown) PerennialBranches ¶
func (self *GitTown) PerennialBranches() domain.LocalBranchNames
PerennialBranches returns all branches that are marked as perennial.
func (*GitTown) PullBranchStrategy ¶
func (self *GitTown) PullBranchStrategy() (PullBranchStrategy, error)
PullBranchStrategy provides the currently configured pull branch strategy.
func (*GitTown) PushHookGlobal ¶
PushHook provides the currently configured push-hook setting.
func (*GitTown) RemoveFromPerennialBranches ¶
func (self *GitTown) RemoveFromPerennialBranches(branch domain.LocalBranchName) error
RemoveFromPerennialBranches removes the given branch as a perennial branch.
func (*GitTown) RemoveLocalGitConfiguration ¶
RemoveLocalGitConfiguration removes all Git Town configuration.
func (*GitTown) RemoveMainBranchConfiguration ¶
RemoveMainBranchConfiguration removes the configuration entry for the main branch name.
func (*GitTown) RemoveParent ¶
func (self *GitTown) RemoveParent(branch domain.LocalBranchName)
RemoveParent removes the parent branch entry for the given branch from the Git configuration.
func (*GitTown) RemovePerennialBranchConfiguration ¶
RemovePerennialBranchConfiguration removes the configuration entry for the perennial branches.
func (*GitTown) SetCodeHostingDriver ¶
SetCodeHostingDriver sets the "github.code-hosting-driver" setting.
func (*GitTown) SetCodeHostingOriginHostname ¶
SetCodeHostingOriginHostname sets the "github.code-hosting-driver" setting.
func (*GitTown) SetColorUI ¶
SetColorUI configures whether Git output contains color codes.
func (*GitTown) SetMainBranch ¶
func (self *GitTown) SetMainBranch(branch domain.LocalBranchName) error
SetMainBranch marks the given branch as the main branch in the Git Town configuration.
func (*GitTown) SetNewBranchPush ¶
SetNewBranchPush updates whether the current repository is configured to push freshly created branches to origin.
func (*GitTown) SetOffline ¶
SetOffline updates whether Git Town is in offline mode.
func (*GitTown) SetParent ¶
func (self *GitTown) SetParent(branch, parentBranch domain.LocalBranchName) error
SetParent marks the given branch as the direct parent of the other given branch in the Git Town configuration.
func (*GitTown) SetPerennialBranches ¶
func (self *GitTown) SetPerennialBranches(branches domain.LocalBranchNames) error
SetPerennialBranches marks the given branches as perennial branches.
func (*GitTown) SetPullBranchStrategy ¶
func (self *GitTown) SetPullBranchStrategy(strategy PullBranchStrategy) error
SetPullBranchStrategy updates the configured pull branch strategy.
func (*GitTown) SetPushHookGlobally ¶
SetPushHook updates the configured pull branch strategy.
func (*GitTown) SetPushHookLocally ¶
SetPushHookLocally updates the configured pull branch strategy.
func (*GitTown) SetShouldShipDeleteRemoteBranch ¶
SetShouldShipDeleteRemoteBranch updates the configured pull branch strategy.
func (*GitTown) SetShouldSyncUpstream ¶
SetShouldSyncUpstream updates the configured pull branch strategy.
func (*GitTown) SetSyncStrategy ¶
func (self *GitTown) SetSyncStrategy(value SyncStrategy) error
func (*GitTown) SetSyncStrategyGlobal ¶
func (self *GitTown) SetSyncStrategyGlobal(value SyncStrategy) error
func (*GitTown) SetTestOrigin ¶
SetTestOrigin sets the origin to be used for testing.
func (*GitTown) ShouldNewBranchPush ¶
ShouldNewBranchPush indicates whether the current repository is configured to push freshly created branches up to origin.
func (*GitTown) ShouldNewBranchPushGlobal ¶
ShouldNewBranchPushGlobal indictes whether the global configuration requires to push freshly created branches to origin.
func (*GitTown) ShouldShipDeleteOriginBranch ¶
ShouldShipDeleteOriginBranch indicates whether to delete the remote branch after shipping.
func (*GitTown) ShouldSyncUpstream ¶
ShouldSyncUpstream indicates whether this repo should sync with its upstream.
func (*GitTown) SyncStrategy ¶
func (self *GitTown) SyncStrategy() (SyncStrategy, error)
func (*GitTown) SyncStrategyGlobal ¶
func (self *GitTown) SyncStrategyGlobal() (SyncStrategy, error)
type Hosting ¶
type Hosting struct {
// contains filtered or unexported fields
}
Hosting defines legal values for the "git-town.code-hosting-driver" config setting. This is a type-safe enum, see https://npf.io/2022/05/safer-enums.
func NewHosting ¶
NewHosting provides the HostingService enum matching the given text.
type Key ¶
type Key struct {
Name string
}
Key contains all the keys used in Git Town configuration.
func NewAliasKey ¶
func NewParentKey ¶
func NewParentKey(branch domain.LocalBranchName) Key
func (Key) MarshalJSON ¶
MarshalJSON is used when serializing this LocalBranchName to JSON.
func (*Key) UnmarshalJSON ¶
UnmarshalJSON is used when de-serializing JSON into a Location.
type Lineage ¶
type Lineage map[domain.LocalBranchName]domain.LocalBranchName
Lineage encapsulates all data and functionality around parent branches. branch --> its parent.
func (Lineage) Ancestors ¶
func (self Lineage) Ancestors(branch domain.LocalBranchName) domain.LocalBranchNames
Ancestors provides the names of all parent branches of the branch with the given name.
func (Lineage) BranchAndAncestors ¶
func (self Lineage) BranchAndAncestors(branchName domain.LocalBranchName) domain.LocalBranchNames
BranchAndAncestors provides the full lineage for the branch with the given name, including the branch.
func (Lineage) BranchNames ¶
func (self Lineage) BranchNames() domain.LocalBranchNames
BranchNames provides the names of all branches in this Lineage, sorted alphabetically.
func (Lineage) BranchesAndAncestors ¶
func (self Lineage) BranchesAndAncestors(branchNames domain.LocalBranchNames) domain.LocalBranchNames
BranchesAndAncestors provides the full lineage for the branches with the given names, including the branches themselves.
func (Lineage) Children ¶
func (self Lineage) Children(branch domain.LocalBranchName) domain.LocalBranchNames
Children provides the names of all branches that have the given branch as their parent.
func (Lineage) HasParents ¶
func (self Lineage) HasParents(branch domain.LocalBranchName) bool
HasParents returns whether or not the given branch has at least one parent.
func (Lineage) IsAncestor ¶
func (self Lineage) IsAncestor(ancestor, other domain.LocalBranchName) bool
IsAncestor indicates whether the given branch is an ancestor of the other given branch.
func (Lineage) OrderHierarchically ¶
func (self Lineage) OrderHierarchically(branches domain.LocalBranchNames)
OrderHierarchically sorts the given branches in place so that ancestor branches come before their descendants and everything is sorted alphabetically.
func (Lineage) Parent ¶
func (self Lineage) Parent(branch domain.LocalBranchName) domain.LocalBranchName
Parent provides the name of the parent branch for the given branch or nil if the branch has no parent.
func (Lineage) RemoveBranch ¶
func (self Lineage) RemoveBranch(branch domain.LocalBranchName)
RemoveBranch removes the given branch completely from this lineage.
func (Lineage) Roots ¶
func (self Lineage) Roots() domain.LocalBranchNames
Roots provides the branches with children and no parents.
type OriginURLCache ¶
type PullBranchStrategy ¶
type PullBranchStrategy struct {
// contains filtered or unexported fields
}
PullBranchStrategy defines legal values for the "pull-branch-strategy" configuration setting.
func NewPullBranchStrategy ¶
func NewPullBranchStrategy(text string) (PullBranchStrategy, error)
func (PullBranchStrategy) String ¶
func (self PullBranchStrategy) String() string
type SyncStrategy ¶
type SyncStrategy struct {
// contains filtered or unexported fields
}
SyncStrategy defines legal values for the "sync-strategy" configuration setting.
func ToSyncStrategy ¶
func ToSyncStrategy(text string) (SyncStrategy, error)
func (SyncStrategy) String ¶
func (self SyncStrategy) String() string