go-git: github.com/go-git/go-git/config Index | Files

package config

import "github.com/go-git/go-git/config"

Package config contains the abstraction of multiple config files

Index

Package Files

branch.go config.go modules.go refspec.go url.go

Constants

const (
    // DefaultFetchRefSpec is the default refspec used for fetch.
    DefaultFetchRefSpec = "+refs/heads/*:refs/remotes/%s/*"
    // DefaultPushRefSpec is the default refspec used for push.
    DefaultPushRefSpec = "refs/heads/*:refs/heads/*"
)
const (

    // DefaultPackWindow holds the number of previous objects used to
    // generate deltas. The value 10 is the same used by git command.
    DefaultPackWindow = uint(10)
)

Variables

var (
    ErrInvalid               = errors.New("config invalid key in remote or branch")
    ErrRemoteConfigNotFound  = errors.New("remote config not found")
    ErrRemoteConfigEmptyURL  = errors.New("remote config: empty URL")
    ErrRemoteConfigEmptyName = errors.New("remote config: empty name")
)
var (
    ErrModuleEmptyURL  = errors.New("module config: empty URL")
    ErrModuleEmptyPath = errors.New("module config: empty path")
    ErrModuleBadPath   = errors.New("submodule has an invalid path")
)
var (
    ErrRefSpecMalformedSeparator = errors.New("malformed refspec, separators are wrong")
    ErrRefSpecMalformedWildcard  = errors.New("malformed refspec, mismatched number of wildcards")
)

func MatchAny Uses

func MatchAny(l []RefSpec, n plumbing.ReferenceName) bool

MatchAny returns true if any of the RefSpec match with the given ReferenceName.

func Paths Uses

func Paths(scope Scope) ([]string, error)

Paths returns the config file location for a given scope.

type Branch Uses

type Branch struct {
    // Name of branch
    Name string
    // Remote name of remote to track
    Remote string
    // Merge is the local refspec for the branch
    Merge plumbing.ReferenceName
    // Rebase instead of merge when pulling. Valid values are
    // "true" and "interactive".  "false" is undocumented and
    // typically represented by the non-existence of this field
    Rebase string
    // contains filtered or unexported fields
}

Branch contains information on the local branches and which remote to track

func (*Branch) Validate Uses

func (b *Branch) Validate() error

Validate validates fields of branch

type Config Uses

type Config struct {
    Core struct {
        // IsBare if true this repository is assumed to be bare and has no
        // working directory associated with it.
        IsBare bool
        // Worktree is the path to the root of the working tree.
        Worktree string
        // CommentChar is the character indicating the start of a
        // comment for commands like commit and tag
        CommentChar string
    }

    User struct {
        // Name is the personal name of the author and the commiter of a commit.
        Name string
        // Email is the email of the author and the commiter of a commit.
        Email string
    }

    Author struct {
        // Name is the personal name of the author of a commit.
        Name string
        // Email is the email of the author of a commit.
        Email string
    }

    Committer struct {
        // Name is the personal name of the commiter of a commit.
        Name string
        // Email is the email of the  the commiter of a commit.
        Email string
    }

    Pack struct {
        // Window controls the size of the sliding window for delta
        // compression.  The default is 10.  A value of 0 turns off
        // delta compression entirely.
        Window uint
    }

    Init struct {
        // DefaultBranch Allows overriding the default branch name
        // e.g. when initializing a new repository or when cloning
        // an empty repository.
        DefaultBranch string
    }

    // Remotes list of repository remotes, the key of the map is the name
    // of the remote, should equal to RemoteConfig.Name.
    Remotes map[string]*RemoteConfig
    // Submodules list of repository submodules, the key of the map is the name
    // of the submodule, should equal to Submodule.Name.
    Submodules map[string]*Submodule
    // Branches list of branches, the key is the branch name and should
    // equal Branch.Name
    Branches map[string]*Branch
    // URLs list of url rewrite rules, if repo url starts with URL.InsteadOf value, it will be replaced with the
    // key instead.
    URLs map[string]*URL
    // Raw contains the raw information of a config file. The main goal is
    // preserve the parsed information from the original format, to avoid
    // dropping unsupported fields.
    Raw *format.Config
}

Config contains the repository configuration https://www.kernel.org/pub/software/scm/git/docs/git-config.html#FILES

func LoadConfig Uses

func LoadConfig(scope Scope) (*Config, error)

LoadConfig loads a config file from a given scope. The returned Config, contains exclusively information fom the given scope. If couldn't find a config file to the given scope, a empty one is returned.

func NewConfig Uses

func NewConfig() *Config

NewConfig returns a new empty Config.

func ReadConfig Uses

func ReadConfig(r io.Reader) (*Config, error)

ReadConfig reads a config file from a io.Reader.

func (*Config) Marshal Uses

func (c *Config) Marshal() ([]byte, error)

Marshal returns Config encoded as a git-config file.

func (*Config) Unmarshal Uses

func (c *Config) Unmarshal(b []byte) error

Unmarshal parses a git-config file and stores it.

func (*Config) Validate Uses

func (c *Config) Validate() error

Validate validates the fields and sets the default values.

type ConfigStorer Uses

type ConfigStorer interface {
    Config() (*Config, error)
    SetConfig(*Config) error
}

ConfigStorer generic storage of Config object

type Modules Uses

type Modules struct {
    // Submodules is a map of submodules being the key the name of the submodule.
    Submodules map[string]*Submodule
    // contains filtered or unexported fields
}

Modules defines the submodules properties, represents a .gitmodules file https://www.kernel.org/pub/software/scm/git/docs/gitmodules.html

func NewModules Uses

func NewModules() *Modules

NewModules returns a new empty Modules

func (*Modules) Marshal Uses

func (m *Modules) Marshal() ([]byte, error)

Marshal returns Modules encoded as a git-config file.

func (*Modules) Unmarshal Uses

func (m *Modules) Unmarshal(b []byte) error

Unmarshal parses a git-config file and stores it.

type RefSpec Uses

type RefSpec string

RefSpec is a mapping from local branches to remote references. The format of the refspec is an optional +, followed by <src>:<dst>, where <src> is the pattern for references on the remote side and <dst> is where those references will be written locally. The + tells Git to update the reference even if it isn’t a fast-forward. eg.: "+refs/heads/*:refs/remotes/origin/*"

https://git-scm.com/book/en/v2/Git-Internals-The-Refspec

func (RefSpec) Dst Uses

func (s RefSpec) Dst(n plumbing.ReferenceName) plumbing.ReferenceName

Dst returns the destination for the given remote reference.

func (RefSpec) IsDelete Uses

func (s RefSpec) IsDelete() bool

IsDelete returns true if the refspec indicates a delete (empty src).

func (RefSpec) IsExactSHA1 Uses

func (s RefSpec) IsExactSHA1() bool

IsExactSHA1 returns true if the source is a SHA1 hash.

func (RefSpec) IsForceUpdate Uses

func (s RefSpec) IsForceUpdate() bool

IsForceUpdate returns if update is allowed in non fast-forward merges.

func (RefSpec) IsWildcard Uses

func (s RefSpec) IsWildcard() bool

IsWildcard returns true if the RefSpec contains a wildcard.

func (RefSpec) Match Uses

func (s RefSpec) Match(n plumbing.ReferenceName) bool

Match match the given plumbing.ReferenceName against the source.

func (RefSpec) Reverse Uses

func (s RefSpec) Reverse() RefSpec

func (RefSpec) Src Uses

func (s RefSpec) Src() string

Src return the src side.

func (RefSpec) String Uses

func (s RefSpec) String() string

func (RefSpec) Validate Uses

func (s RefSpec) Validate() error

Validate validates the RefSpec

type RemoteConfig Uses

type RemoteConfig struct {
    // Name of the remote
    Name string
    // URLs the URLs of a remote repository. It must be non-empty. Fetch will
    // always use the first URL, while push will use all of them.
    URLs []string

    // Fetch the default set of "refspec" for fetch operation
    Fetch []RefSpec
    // contains filtered or unexported fields
}

RemoteConfig contains the configuration for a given remote repository.

func (*RemoteConfig) IsFirstURLLocal Uses

func (c *RemoteConfig) IsFirstURLLocal() bool

func (*RemoteConfig) Validate Uses

func (c *RemoteConfig) Validate() error

Validate validates the fields and sets the default values.

type Scope Uses

type Scope int

Scope defines the scope of a config file, such as local, global or system.

const (
    LocalScope Scope = iota
    GlobalScope
    SystemScope
)

Available ConfigScope's

type Submodule Uses

type Submodule struct {
    // Name module name
    Name string
    // Path defines the path, relative to the top-level directory of the Git
    // working tree.
    Path string
    // URL defines a URL from which the submodule repository can be cloned.
    URL string
    // Branch is a remote branch name for tracking updates in the upstream
    // submodule. Optional value.
    Branch string
    // contains filtered or unexported fields
}

Submodule defines a submodule.

func (*Submodule) Validate Uses

func (m *Submodule) Validate() error

Validate validates the fields and sets the default values.

type URL Uses

type URL struct {
    // Name new base url
    Name string
    // Any URL that starts with this value will be rewritten to start, instead, with <base>.
    // When more than one insteadOf strings match a given URL, the longest match is used.
    InsteadOf string
    // contains filtered or unexported fields
}

Url defines Url rewrite rules

func (*URL) ApplyInsteadOf Uses

func (u *URL) ApplyInsteadOf(url string) string

func (*URL) Validate Uses

func (b *URL) Validate() error

Validate validates fields of branch

Package config imports 15 packages (graph). Updated 2020-12-03. Refresh now. Tools for package owners.