config

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: 14 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var (
	AliasAppend       = Alias{"append"}        //nolint:gochecknoglobals
	AliasDiffParent   = Alias{"diff-parent"}   //nolint:gochecknoglobals
	AliasHack         = Alias{"hack"}          //nolint:gochecknoglobals
	AliasKill         = Alias{"kill"}          //nolint:gochecknoglobals
	AliasPrepend      = Alias{"prepend"}       //nolint:gochecknoglobals
	AliasPropose      = Alias{"propose"}       //nolint:gochecknoglobals
	AliasRenameBranch = Alias{"rename-branch"} //nolint:gochecknoglobals
	AliasRepo         = Alias{"repo"}          //nolint:gochecknoglobals
	AliasShip         = Alias{"ship"}          //nolint:gochecknoglobals
	AliasSync         = Alias{"sync"}          //nolint:gochecknoglobals
)
View Source
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
)
View Source
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
	KeyAliasPrepend                   = Key{"alias." + AliasPrepend.name}            //nolint:gochecknoglobals
	KeyAliasPropose                   = Key{"alias." + AliasPropose.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
	KeyCodeHostingOriginHostname      = Key{"git-town.code-hosting-origin-hostname"} //nolint:gochecknoglobals
	KeyCodeHostingPlatform            = Key{"git-town.code-hosting-platform"}        //nolint:gochecknoglobals
	KeyDeprecatedCodeHostingDriver    = Key{"git-town.code-hosting-driver"}          //nolint:gochecknoglobals
	KeyDeprecatedMainBranchName       = Key{"git-town.main-branch-name"}             //nolint:gochecknoglobals
	KeyDeprecatedNewBranchPushFlag    = Key{"git-town.new-branch-push-flag"}         //nolint:gochecknoglobals
	KeyDeprecatedPerennialBranchNames = Key{"git-town.perennial-branch-names"}       //nolint:gochecknoglobals
	KeyDeprecatedPullBranchStrategy   = Key{"git-town.pull-branch-strategy"}         //nolint:gochecknoglobals
	KeyDeprecatedPushVerify           = Key{"git-town.push-verify"}                  //nolint:gochecknoglobals
	KeyDeprecatedSyncStrategy         = Key{"git-town.sync-strategy"}                //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"}                  //nolint:gochecknoglobals
	KeyOffline                        = Key{"git-town.offline"}                      //nolint:gochecknoglobals
	KeyPerennialBranches              = Key{"git-town.perennial-branches"}           //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
	KeySyncBeforeShip                 = Key{"git-town.sync-before-ship"}             //nolint:gochecknoglobals
	KeySyncFeatureStrategy            = Key{"git-town.sync-feature-strategy"}        //nolint:gochecknoglobals
	KeySyncPerennialStrategy          = Key{"git-town.sync-perennial-strategy"}      //nolint:gochecknoglobals
	KeySyncStrategy                   = Key{"git-town.sync-strategy"}                //nolint:gochecknoglobals
	KeySyncUpstream                   = Key{"git-town.sync-upstream"}                //nolint:gochecknoglobals
	KeyTestingRemoteURL               = Key{"git-town.testing.remote-url"}           //nolint:gochecknoglobals
)
View Source
var (
	SyncFeatureStrategyMerge  = SyncFeatureStrategy{"merge"}  //nolint:gochecknoglobals
	SyncFeatureStrategyRebase = SyncFeatureStrategy{"rebase"} //nolint:gochecknoglobals
)
View Source
var (
	SyncPerennialStrategyMerge  = SyncPerennialStrategy{"merge"}  //nolint:gochecknoglobals
	SyncPerennialStrategyRebase = SyncPerennialStrategy{"rebase"} //nolint:gochecknoglobals
)

Functions

func DetermineOriginURL

func DetermineOriginURL(originURL, originOverride string, originURLCache OriginURLCache) *giturl.Parts

func ParseBool

func ParseBool(text string) (bool, error)

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.

func Aliases

func Aliases() []Alias

Aliases provides all AliasType values.

func (Alias) String

func (self Alias) String() string

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

func NewGit(gitConfig GitConfig, runner runner) Git

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 (self Git) GlobalConfigValue(key Key) string

func (Git) LocalConfigClone

func (self Git) LocalConfigClone() GitConfigCache

func (Git) LocalConfigKeysMatching

func (self Git) LocalConfigKeysMatching(pattern string) []Key

func (Git) LocalConfigValue

func (self Git) LocalConfigValue(key Key) string

func (Git) LocalOrGlobalConfigValue

func (self Git) LocalOrGlobalConfigValue(key Key) string

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 (self *Git) RemoveGlobalConfigValue(key Key) error

func (*Git) RemoveLocalConfigValue

func (self *Git) RemoveLocalConfigValue(key Key) error

removeLocalConfigurationValue deletes the configuration value with the given key from the local Git Town configuration.

func (*Git) SetGlobalConfigValue

func (self *Git) SetGlobalConfigValue(key Key, value string) error

SetGlobalConfigValue sets the given configuration setting in the global Git configuration.

func (*Git) SetLocalConfigValue

func (self *Git) SetLocalConfigValue(key Key, value string) error

SetLocalConfigValue sets the local configuration with the given key to the given value.

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

func (GitConfig) Clone

func (self GitConfig) Clone() GitConfig

type GitConfigCache

type GitConfigCache map[Key]string

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 NewGitTown(gitConfig GitConfig, runner runner) *GitTown

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) ContainsLineage added in v11.1.0

func (self *GitTown) ContainsLineage() bool

ContainsLineage indicates whether this configuration contains any lineage entries.

func (*GitTown) GitAlias

func (self *GitTown) GitAlias(alias Alias) string

GitAlias provides the currently set alias for the given Git Town command.

func (*GitTown) GitHubToken

func (self *GitTown) GitHubToken() string

GitHubToken provides the content of the GitHub API token stored in the local or global Git Town configuration.

func (*GitTown) GitLabToken

func (self *GitTown) GitLabToken() string

GitLabToken provides the content of the GitLab API token stored in the local or global Git Town configuration.

func (*GitTown) GiteaToken

func (self *GitTown) GiteaToken() string

GiteaToken provides the content of the Gitea API token stored in the local or global Git Town configuration.

func (*GitTown) HostingService

func (self *GitTown) HostingService() (Hosting, error)

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

func (self *GitTown) HostingServiceName() string

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

func (self *GitTown) IsOffline() (bool, error)

IsOffline indicates whether Git Town is currently in offline mode.

func (*GitTown) Lineage

func (self *GitTown) Lineage(deleteEntry func(Key) error) Lineage

Lineage provides the configured ancestry information for this Git repo.

func (*GitTown) MainBranch

func (self *GitTown) MainBranch() domain.LocalBranchName

MainBranch provides the name of the main branch.

func (*GitTown) OriginOverride

func (self *GitTown) OriginOverride() string

OriginOverride provides the override for the origin hostname from the Git Town configuration.

func (*GitTown) OriginURL

func (self *GitTown) OriginURL() *giturl.Parts

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

func (self *GitTown) OriginURLString() string

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

func (self *GitTown) PushHook() (bool, error)

PushHook provides the currently configured push-hook setting.

func (*GitTown) PushHookGlobal

func (self *GitTown) PushHookGlobal() (bool, error)

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

func (self *GitTown) RemoveLocalGitConfiguration() error

RemoveLocalGitConfiguration removes all Git Town configuration.

func (*GitTown) RemoveMainBranchConfiguration

func (self *GitTown) RemoveMainBranchConfiguration() error

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

func (self *GitTown) RemovePerennialBranchConfiguration() error

RemovePerennialBranchConfiguration removes the configuration entry for the perennial branches.

func (*GitTown) SetCodeHostingDriver

func (self *GitTown) SetCodeHostingDriver(value string) error

SetCodeHostingDriver sets the "github.code-hosting-driver" setting.

func (*GitTown) SetCodeHostingOriginHostname

func (self *GitTown) SetCodeHostingOriginHostname(value string) error

SetCodeHostingOriginHostname sets the "github.code-hosting-driver" setting.

func (*GitTown) SetColorUI

func (self *GitTown) SetColorUI(value string) error

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

func (self *GitTown) SetNewBranchPush(value bool, global bool) error

SetNewBranchPush updates whether the current repository is configured to push freshly created branches to origin.

func (*GitTown) SetOffline

func (self *GitTown) SetOffline(value bool) error

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

func (self *GitTown) SetPushHookGlobally(value bool) error

SetPushHook updates the configured push-hook strategy.

func (*GitTown) SetPushHookLocally

func (self *GitTown) SetPushHookLocally(value bool) error

SetPushHookLocally updates the locally configured push-hook strategy.

func (*GitTown) SetShouldShipDeleteRemoteBranch

func (self *GitTown) SetShouldShipDeleteRemoteBranch(value bool) error

SetShouldShipDeleteRemoteBranch updates the configured delete-remote-branch strategy.

func (*GitTown) SetShouldSyncUpstream

func (self *GitTown) SetShouldSyncUpstream(value bool) error

SetShouldSyncUpstream updates the configured sync-upstream strategy.

func (*GitTown) SetSyncFeatureStrategy

func (self *GitTown) SetSyncFeatureStrategy(value SyncFeatureStrategy) error

func (*GitTown) SetSyncFeatureStrategyGlobal

func (self *GitTown) SetSyncFeatureStrategyGlobal(value SyncFeatureStrategy) error

func (*GitTown) SetSyncPerennialStrategy

func (self *GitTown) SetSyncPerennialStrategy(strategy SyncPerennialStrategy) error

SetSyncPerennialStrategy updates the configured sync-perennial strategy.

func (*GitTown) SetTestOrigin

func (self *GitTown) SetTestOrigin(value string) error

SetTestOrigin sets the origin to be used for testing.

func (*GitTown) ShouldNewBranchPush

func (self *GitTown) ShouldNewBranchPush() (bool, error)

ShouldNewBranchPush indicates whether the current repository is configured to push freshly created branches up to origin.

func (*GitTown) ShouldNewBranchPushGlobal

func (self *GitTown) ShouldNewBranchPushGlobal() (bool, error)

ShouldNewBranchPushGlobal indictes whether the global configuration requires to push freshly created branches to origin.

func (*GitTown) ShouldShipDeleteOriginBranch

func (self *GitTown) ShouldShipDeleteOriginBranch() (bool, error)

ShouldShipDeleteOriginBranch indicates whether to delete the remote branch after shipping.

func (*GitTown) ShouldSyncUpstream

func (self *GitTown) ShouldSyncUpstream() (bool, error)

ShouldSyncUpstream indicates whether this repo should sync with its upstream.

func (*GitTown) SyncBeforeShip

func (self *GitTown) SyncBeforeShip() (bool, error)

SyncBeforeShip indicates whether a sync should be performed before a ship.

func (*GitTown) SyncFeatureStrategy

func (self *GitTown) SyncFeatureStrategy() (SyncFeatureStrategy, error)

func (*GitTown) SyncFeatureStrategyGlobal

func (self *GitTown) SyncFeatureStrategyGlobal() (SyncFeatureStrategy, error)

func (*GitTown) SyncPerennialStrategy

func (self *GitTown) SyncPerennialStrategy() (SyncPerennialStrategy, error)

SyncPerennialStrategy provides the currently configured sync-perennial strategy.

type Hosting

type Hosting struct {
	// contains filtered or unexported fields
}

Hosting defines legal values for the "git-town.code-hosting-platform" config setting. This is a type-safe enum, see https://npf.io/2022/05/safer-enums.

func NewHosting

func NewHosting(text string) (Hosting, error)

NewHosting provides the HostingService enum matching the given text.

func (Hosting) String

func (self Hosting) String() string

type Key

type Key struct {
	Name string
}

Key contains all the keys used in Git Town configuration.

func NewAliasKey

func NewAliasKey(aliasType Alias) Key

func NewParentKey

func NewParentKey(branch domain.LocalBranchName) Key

func ParseKey

func ParseKey(name string) *Key

func (Key) MarshalJSON

func (self Key) MarshalJSON() ([]byte, error)

MarshalJSON is used when serializing this LocalBranchName to JSON.

func (Key) String

func (self Key) String() string

func (*Key) UnmarshalJSON

func (self *Key) UnmarshalJSON(b []byte) error

UnmarshalJSON is used when de-serializing JSON into a Location.

type Lineage

Lineage encapsulates all data and functionality around parent branches. branch --> its parent Lineage only contains branches that have ancestors.

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 OriginURLCache map[string]*giturl.Parts

type SyncFeatureStrategy

type SyncFeatureStrategy struct {
	// contains filtered or unexported fields
}

SyncFeatureStrategy defines legal values for the "sync-feature-strategy" configuration setting.

func ToSyncFeatureStrategy

func ToSyncFeatureStrategy(text string) (SyncFeatureStrategy, error)

func (SyncFeatureStrategy) String

func (self SyncFeatureStrategy) String() string

type SyncPerennialStrategy

type SyncPerennialStrategy struct {
	// contains filtered or unexported fields
}

SyncPerennialStrategy defines legal values for the "sync-perennial-strategy" configuration setting.

func NewSyncPerennialStrategy

func NewSyncPerennialStrategy(text string) (SyncPerennialStrategy, error)

func (SyncPerennialStrategy) String

func (self SyncPerennialStrategy) String() string

Jump to

Keyboard shortcuts

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