Documentation
¶
Overview ¶
Package gitconfig provides an interface to git configuration properties as returned by "git config --list". gitconfig provides access to local, global and system configuration, as well as the effective configuration for the given git working copy. gitconfig attempts to use the locally installed "git" executable using https://github.com/denormal/go-gittools.
See https://git-scm.com/docs/git-config for more information.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( MissingGitError = gittools.MissingGitError MissingWorkingCopyError = gittools.MissingWorkingCopyError )
var ( InvalidBooleanError = errors.New("invalid boolean value") InvalidIntegerError = errors.New("invalid integer value") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config interface {
// All returns a list of all properties associated with this configuration.
All() []Property
// Get attempts to retrieve the property with the specified name from the
// current configuration, returning the property or nil if no property with
// that name is found.
Get(name string) Property
// Find returns the list of all configuration properties with names matching
// the given pattern. If the pattern ends with "*", the rest of the pattern
// will be treated as a prefix, with Find returning all properties whose
// name shares the prefix. If pattern does not end with "*", Find behaves as
// Get and looks for the exact property name.
Find(pattern string) []Property
// String returns a string representation of the configuration, returning
// the properties in name order.
String() string
}
Config is the interface to a block of git configuration, either local, global or system.
func NewConfig ¶
NewConfig returns the configuration instance for the list of configuration properties p. If p contains properties with the same name, the property listed last will be the property set in the returned Config instance.
func NewGlobalConfig ¶
NewGlobalConfig returns the Config instance for the global git configuration. If there is a problem extracting this configuration, and Error is returned.
func NewLocalConfig ¶
NewLocalConfig returns the Config instance for the local git configuration, for the repository represented by path. If there is a problem extracting this configuration, and Error is returned. If path is "", the current working directory of the process will be used.
func NewSystemConfig ¶
NewSystemConfig returns the Config instance for the system git configuration. If there is a problem extracting this configuration, and Error is returned.
type GitConfig ¶
type GitConfig interface {
Config
// Path returns the absolute path used to initialise this GitConfig.
Path() string
// Root returns the root directory of the git working copy. If this
// GitConfig is initialised by a path that is not located within a
// working copy, Root will return the empty string.
Root() string
// Local returns the local git configuration for the git working copy.
// If the path used to initialise this GitConfig is not part of a working
// copy, Local() returns nil.
Local() Config
// System returns the system git configuration.
System() Config
// Global returns the global git configuration for the current user.
Global() Config
}
GitConfig is the interface to git configuration, encompassing local, global and system configuration for a git working copy.
func New ¶
New returns a GitConfig instance representing the git working copy in the current working directory. If the current working directory is not part of a git working copy, the local configuration of the GitConfig will be nil. An error is returned if there is a problem accessing the current working directory, or if there is a problem parsing the configuration properties.
Example ¶
// attempt to load git configuration from within the current directory
config, err := gitconfig.New()
if err != nil {
fmt.Printf(
"error encountered loading git configuration: %s",
err.Error(),
)
} else {
email := config.Get("user.email")
if email != nil {
fmt.Printf("the git user's email is %q\n", email)
}
fmt.Println("the core.* git configuration properties are:")
for _, property := range config.Find("core.*") {
fmt.Printf("\t%s=%s\n", property.Name(), property)
}
}
func NewWithPath ¶
NewWithPath returns a GitConfig instance representing the git working copy path. If path is not part of a git working copy, the local configuration of the GitConfig will be nil. An error is returned if there is a problem accessing the path, or if there is a problem parsing the configuration properties.
If path is "", the current working directory of the process will be used.
type Property ¶
type Property interface {
// Name returns the name of the property.
Name() string
// String returns the string representation of the property value.
String() string
// Bool returns the boolean value of the property. If the property value
// is not a valid boolean, an error will be returned.
Bool() (bool, error)
// List returns the list representation of the property. List splits the
// string representation of the property value at colons ":".
List() []string
// Int returns the integer representation of the property. If the property
// value is not a valid integer, an error will be returned.
Int() (int, error)
}
Property represents the name/value pair for a configuration property.
func NewProperty ¶
NewProperty returns a Property instance with the given name and value v.