-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc.go
More file actions
115 lines (115 loc) · 3.92 KB
/
doc.go
File metadata and controls
115 lines (115 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Package gitconfig implements a pure Go parser of Git SCM config files. The support
// is currently not matching git exactly, e.g. includes, urlmatches and multivars are currently
// not supported. And while we try to preserve the original file a much as possible
// when writing we currently don't exactly retain (insignificant) whitespaces.
//
// The reference for this implementation is https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-config.html
//
// # Usage
//
// Use gitconfig.LoadAll with an optional workspace argument to process configuration
// input from these locations in order (i.e. the later ones take precedence):
//
// - `system` - /etc/gitconfig
// - `global` - `$XDG_CONFIG_HOME/git/config` or `~/.gitconfig`
// - `local` - `<workdir>/config`
// - `worktree` - `<workdir>/config.worktree`
// - `command` - GIT_CONFIG_{COUNT,KEY,VALUE} environment variables
//
// Note: We do not support parsing command line flags directly, but one
// can use the SetEnv method to set flags from the command line in the config.
//
// # Customization
//
// `gopass` and other users of this package can easily customize file and environment
// names by utilizing the exported variables from the Configs struct:
//
// - SystemConfig - Path to system-wide config (e.g., /etc/gitconfig)
// - GlobalConfig - Path to user config (e.g., ~/.gitconfig) or "" to disable
// - LocalConfig - Per-repository config name (e.g., .git/config)
// - WorktreeConfig - Per-worktree config name (e.g., .git/config.worktree)
// - EnvPrefix - Environment variable prefix (defaults to GIT_CONFIG)
//
// Note: For tests users will want to set `NoWrites = true` to avoid overwriting
// their real configs.
//
// # Examples
//
// ## Loading and Reading Configuration
//
// Basic reading from all scopes (respects precedence):
//
// cfg := gitconfig.New()
// cfg.LoadAll(".")
// value := cfg.Get("user.name")
// fmt.Println(value) // Reads from highest priority scope available
//
// ## Reading from Specific Scopes
//
// Access configuration from a specific scope:
//
// cfg := gitconfig.New()
// cfg.LoadAll(".")
// local := cfg.GetLocal("core.editor")
// global := cfg.GetGlobal("user.email")
// system := cfg.GetSystem("core.pager")
//
// ## Customization for Other Applications
//
// Configure for a different application (like gopass):
//
// cfg := gitconfig.New()
// cfg.SystemConfig = "/etc/gopass/config"
// cfg.GlobalConfig = ""
// cfg.LocalConfig = ".gopass-config"
// cfg.EnvPrefix = "GOPASS_CONFIG"
// cfg.LoadAll(".")
// notifications := cfg.Get("core.notifications")
//
// ## Writing Configuration
//
// Modify and persist changes:
//
// cfg, _ := gitconfig.LoadConfig(".git/config")
// cfg.Set("user.name", "John Doe")
// cfg.Set("user.email", "john@example.com")
// cfg.Write() // Persist changes to disk
//
// ## Scope-Specific Writes
//
// Write to specific scopes in multi-scope configs:
//
// cfg := gitconfig.New()
// cfg.LoadAll(".")
// cfg.SetLocal("core.autocrlf", "true") // Write to .git/config
// cfg.SetGlobal("user.signingkey", "...") // Write to ~/.gitconfig
// cfg.SetSystem("core.pager", "less") // Write to /etc/gitconfig
//
// ## Error Handling
//
// Use errors.Is to detect common error categories:
//
// if err := cfg.Set("invalid", "value"); err != nil {
// if errors.Is(err, gitconfig.ErrInvalidKey) {
// // handle invalid key
// }
// }
//
// if err := cfgs.SetLocal("core.editor", "vim"); err != nil {
// if errors.Is(err, gitconfig.ErrWorkdirNotSet) {
// // call LoadAll or provide a workdir
// }
// }
//
// # Versioning and Compatibility
//
// We aim to support the latest stable release of Git only.
// Currently we do not provide any backwards compatibility
// and semantic versioning.
//
// # Known limitations
//
// * Worktree support is only partial
// * Bare boolean values are not supported (e.g. a setting were only the key is present)
// * includeIf suppport is only partial, i.e. we only support the gitdir option
package gitconfig