config

package
v0.0.0-...-2ee2aa9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package config contains structs to interact with git configuration as well as to configure the library

Index

Constants

View Source
const (
	// DefaultDotGitDirName corresponds to the default name of the git
	// directory
	DefaultDotGitDirName = ".git"
)

Variables

View Source
var (
	// ErrNoWorkTreeAlone is thrown when a work tree path is given without
	// a git path
	ErrNoWorkTreeAlone = errors.New("cannot specify a work tree without also specifying a git dir")
	// ErrInvalidGitfileFormat is thrown when the file version of the .git
	// is invalid
	ErrInvalidGitfileFormat = errors.New("invalid gitfile format")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// FS represents the file system implementation to use to look for
	// files and directories.
	// Defaults to the regular filesystem.
	FS afero.Fs

	// GitDirPath represents the path to the .git directory.
	// Maps to $GIT_DIR if set.
	// Defaults to finding a ".git" folder in the current directory,
	// going up in the tree until reaching /.
	GitDirPath string
	// CommonDirPath represents the root path of the non-worktree-related
	// files that are in the .git directory.
	// https://git-scm.com/docs/git#Documentation/git.txt-codeGITCOMMONDIRcode
	// Maps to $GIT_COMMON_DIR.
	// Defaults to $GitDirPath.
	CommonDirPath string
	// WorkTreePath represents the path to the .git directory.
	// Maps to $GIT_WORK_TREE.
	// Defaults to $(GitDirPath)/.. or $(current-dir) depending on if
	// GitDirPath was set or not.
	WorkTreePath string
	// ObjectDirPath represents the path to the .git/objects directory.
	// Maps to $GIT_OBJECT_DIRECTORY.
	// Defaults to $(CommonDirPath)/.git/objects.
	ObjectDirPath string
	// LocalConfig represents the config file to load.
	// Maps to $GIT_CONFIG.
	// Defaults to $(GitDirPath)/config if not sets.
	LocalConfig string
	// Prefix contains the base for finding the system configuration file.
	// $(prefix)/etc/gitconfig.
	// Maps to $PREFIX.
	// Defaults to an empty string.
	Prefix string
	// SkipSystemConfig states whether we should use the system config or not.
	// Maps to $GIT_CONFIG_NOSYSTEM.
	// Defaults to false.
	SkipSystemConfig bool
	// contains filtered or unexported fields
}

Config represents the config of a repository, whether it's from the various config files or from the options that can be set using the env https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables

If you decide to create a Config by yourself, make sure to set correct values everywhere

func LoadConfig

func LoadConfig(e *env.Env, p LoadConfigOptions) (*Config, error)

LoadConfig returns a new Config that fetches the data from the env This is what you want to use to give your users some control over git. If you want something more direct without control, use NewGitOptionsSkipEnv()

func LoadConfigSkipEnv

func LoadConfigSkipEnv(opts LoadConfigOptions) (*Config, error)

LoadConfigSkipEnv returns a new Config that skips the env and uses the default values

func (*Config) FromFile

func (cfg *Config) FromFile() *FileAggregate

FromFile returns a FileAggregate containing all the config values set in the gitconfig files

func (*Config) Reload

func (cfg *Config) Reload() (err error)

Reload reloads all of git's config file

type FileAggregate

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

FileAggregate represents the aggregate of all the config files impacting a repository

func NewFileAggregate

func NewFileAggregate(e *env.Env, cfg *Config) (confFile *FileAggregate, err error)

NewFileAggregate loads all the available config files and returns an object with accessor

func (*FileAggregate) DefaultBranch

func (cfg *FileAggregate) DefaultBranch() (name string, ok bool)

DefaultBranch returns the branch name to use when creating a new repository. The branch name isn't checked and may be an invalid value

func (*FileAggregate) IsBare

func (cfg *FileAggregate) IsBare() (isBare, ok bool)

IsBare returns whether the repository is bare or not.

func (*FileAggregate) RepoFormatVersion

func (cfg *FileAggregate) RepoFormatVersion() (version int, ok bool)

RepoFormatVersion returns the version of the format of the repo

func (*FileAggregate) Save

func (cfg *FileAggregate) Save() error

Save persists the changes made to the config files

func (*FileAggregate) UpdateIsBare

func (cfg *FileAggregate) UpdateIsBare(isBare bool)

UpdateIsBare updates the core.bare option.

func (*FileAggregate) UpdateRepoFormatVersion

func (cfg *FileAggregate) UpdateRepoFormatVersion(ver string)

UpdateRepoFormatVersion updates the version of the format of the repo.

func (*FileAggregate) WorkTree

func (cfg *FileAggregate) WorkTree() (workTree string, ok bool)

WorkTree returns the path of the work-tree.

type LoadConfigOptions

type LoadConfigOptions struct {
	// FS represents the file system implementation to use to look for.
	// files and directories.
	// Defaults to the regular filesystem.
	FS afero.Fs
	// WorkingDirectory represents the current working directory.
	// Defaults to the current working directory.
	WorkingDirectory string
	// WorkTreePath corresponds to the directory that should contain the .git.
	// Set this value to change the default behavior and overwrite
	// $GIT_WORK_TREE.
	WorkTreePath string
	// GitDirPath corresponds to the .git directory
	// Set this value to change the default behavior and overwrite
	// $GIT_DIR.
	GitDirPath string
	// IsBare defines if the repo is bare. It means that the repo and the
	// work tree are separated
	IsBare bool
	// SkipGitDirLookUp will disable automatic lookup of the .git directory.
	// Defaults to false which means that if no path is provided
	// to $GitDirPath or $GIT_DIR, the method will look for a .git dir in
	// $WorkingDirectory and will go up the tree until it finds one.
	//
	// You should only set this value to true if you want to initialize a
	// new repository.
	SkipGitDirLookUp bool
}

LoadConfigOptions represents all the params used to set the default values of a Config object

Jump to

Keyboard shortcuts

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