Documentation
¶
Index ¶
- Constants
- Variables
- func CacheSet(key string, cfg GitConfig, size int64, modTime time.Time)
- func Exist(name string) bool
- func FindGitConfig(dir string) (string, error)
- func GlobalConfigFile() (string, error)
- func IsDir(name string) bool
- func IsFile(name string) bool
- func SystemConfigFile() string
- type GitConfig
- func CacheGet(key string) (GitConfig, bool)
- func DefaultConfig() GitConfig
- func GlobalConfig() (GitConfig, error)
- func Load(name string) (GitConfig, error)
- func LoadAll(name string) (GitConfig, error)
- func NewGitConfig() GitConfig
- func Parse(bytes []byte, filename string) (GitConfig, uint, error)
- func SystemConfig() (GitConfig, error)
- func (v GitConfig) Add(key string, value interface{})
- func (v GitConfig) Get(key string) string
- func (v GitConfig) GetAll(key string) []string
- func (v GitConfig) GetBool(key string, defaultValue bool) bool
- func (v GitConfig) GetBoolE(key string, defaultValue bool) (bool, error)
- func (v GitConfig) GetInt(key string, defaultValue int) int
- func (v GitConfig) GetInt64(key string, defaultValue int64) int64
- func (v GitConfig) GetInt64E(key string, defaultValue int64) (int64, error)
- func (v GitConfig) GetIntE(key string, defaultValue int) (int, error)
- func (v GitConfig) GetUint64(key string, defaultValue uint64) uint64
- func (v GitConfig) GetUint64E(key string, defaultValue uint64) (uint64, error)
- func (v GitConfig) HasKey(key string) bool
- func (v GitConfig) Keys() []string
- func (v GitConfig) Merge(c GitConfig, scope scope) GitConfig
- func (v GitConfig) Save(file string) error
- func (v GitConfig) Sections() []string
- func (v GitConfig) Set(key string, value interface{})
- func (v GitConfig) String() string
- func (v GitConfig) Unset(key string)
- func (v GitConfig) UnsetAll(key string)
- type Repository
Examples ¶
Constants ¶
const ( ScopeInclude = 1 << iota ScopeSystem ScopeGlobal ScopeSelf ScopeAll = 0xFFFF ScopeMask = ^ScopeInclude )
Define scopes for config variables
Variables ¶
var ErrInvalidEscapeSequence = errors.New("unknown escape sequence")
ErrInvalidEscapeSequence indicates that the escape character ('\') was followed by an invalid character.
var ErrInvalidKeyChar = errors.New("invalid key character")
ErrInvalidKeyChar indicates that there was an invalid key character
var ErrInvalidSectionChar = errors.New("invalid character in section")
ErrInvalidSectionChar indicates that there was an invalid character in section
var ErrMissingClosingBracket = errors.New("missing closing section bracket")
ErrMissingClosingBracket indicates that there was a missing closing bracket in section
var ErrMissingEquals = errors.New("expected '='")
ErrMissingEquals indicates that an equals sign ('=') was expected but not found
var ErrMissingStartQuote = errors.New("missing start quote")
ErrMissingStartQuote indicates that there was a missing start quote
var ErrNotBoolValue = errors.New("not a bool value")
ErrNotBoolValue indicates fail to convert config variable to bool
var ErrNotExist = errors.New("config file or dir not exist")
ErrNotExist indicates file or dir not exist
var ErrNotInGitDir = errors.New("not in a git dir")
ErrNotInGitDir indicates not in a git dir
var ErrPartialBOM = errors.New("partial UTF8-BOM")
ErrPartialBOM indicates that the file begins with a partial UTF8-BOM
var ErrSectionNewLine = errors.New("newline in section")
ErrSectionNewLine indicates that there was a newline in section
var ErrUnexpectedEOF = errors.New("unexpected EOF")
ErrUnexpectedEOF indicates that there was an unexpected EOF
var ErrUnfinishedQuote = errors.New("unfinished quote")
ErrUnfinishedQuote indicates that a value has an odd number of (unescaped) quotes
Functions ¶
func FindGitConfig ¶
FindGitConfig returns local git config file
func GlobalConfigFile ¶
GlobalConfigFile returns global git config file
func SystemConfigFile ¶
func SystemConfigFile() string
SystemConfigFile returns system git config file
Types ¶
type GitConfig ¶
type GitConfig map[string]gitConfigKeys
GitConfig maps section to key-value pairs
func DefaultConfig ¶ added in v1.1.0
func DefaultConfig() GitConfig
DefaultConfig returns global and system wide config
func GlobalConfig ¶
GlobalConfig returns global user config, reload if necessary
func NewGitConfig ¶
func NewGitConfig() GitConfig
NewGitConfig returns GitConfig with initialized maps
func Parse ¶
Parse takes given bytes as configuration file (according to gitconfig syntax)
Example ¶
gitconfig := "configs/danyel.gitconfig" bytes, err := ioutil.ReadFile(gitconfig) if err != nil { log.Fatalf("Couldn't read file %v\n", gitconfig) } config, lineno, err := Parse(bytes, gitconfig) if err != nil { log.Fatalf("Error on line %d: %v\n", lineno, err) } fmt.Println() fmt.Println(lineno) fmt.Println(config.Get("user.name")) fmt.Println(config.Get("user.email"))
Output: 10 Danyel Bayraktar [email protected]
func SystemConfig ¶
SystemConfig returns system git config, reload if necessary
func (GitConfig) GetBoolE ¶ added in v1.1.0
GetBoolE gets boolean from key with default value with error
func (GitConfig) GetInt64E ¶ added in v1.1.0
GetInt64E return int64 value of key with default with error
func (GitConfig) GetIntE ¶ added in v1.1.0
GetIntE return integer value of key with default with error
func (GitConfig) GetUint64E ¶ added in v1.1.0
GetUint64E return uint64 value of key with default with error
func (GitConfig) Merge ¶
Merge will merge another GitConfig, and new value(s) of the same key will append to the end of value list, and new value has higher priority.
type Repository ¶ added in v1.1.0
type Repository struct {
// contains filtered or unexported fields
}
Repository defines struct for a Git repository.
func FindRepository ¶ added in v1.1.0
func FindRepository(dir string) (*Repository, error)
FindRepository locates repository object search from the given dir.
func (Repository) Config ¶ added in v1.1.0
func (v Repository) Config() GitConfig
Config returns git config object
func (Repository) GitCommonDir ¶ added in v1.1.0
func (v Repository) GitCommonDir() string
GitCommonDir returns commondir where contains "config" file
func (Repository) GitDir ¶ added in v1.1.0
func (v Repository) GitDir() string
GitDir returns GitDir
func (Repository) IsBare ¶ added in v1.1.0
func (v Repository) IsBare() bool
IsBare indicates a repository is a bare repository.
func (Repository) WorkDir ¶ added in v1.1.0
func (v Repository) WorkDir() string
WorkDir returns workdir