aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/dotgit/dotgit.go
diff options
context:
space:
mode:
authorWes Morgan <wesmorgan@icloud.com>2020-04-06 10:32:06 -0600
committerWes Morgan <wesmorgan@icloud.com>2020-04-06 10:32:06 -0600
commitecb64c048179fbc6086e7eff23136802720c8972 (patch)
tree5fba37333c2dcabccadee73f2c152f6b5df46fab /storage/filesystem/dotgit/dotgit.go
parent8fddd7abcc436d77e9f7449a7b7aa15ee13f7c60 (diff)
downloadgo-git-ecb64c048179fbc6086e7eff23136802720c8972.tar.gz
Add Merged config
...for reading and writing global (~/.git/config) and reading system (/etc/gitconfig) configs in addition to local repo config
Diffstat (limited to 'storage/filesystem/dotgit/dotgit.go')
-rw-r--r--storage/filesystem/dotgit/dotgit.go50
1 files changed, 35 insertions, 15 deletions
diff --git a/storage/filesystem/dotgit/dotgit.go b/storage/filesystem/dotgit/dotgit.go
index 3ce9dae..503ce18 100644
--- a/storage/filesystem/dotgit/dotgit.go
+++ b/storage/filesystem/dotgit/dotgit.go
@@ -21,15 +21,17 @@ import (
)
const (
- suffix = ".git"
- packedRefsPath = "packed-refs"
- configPath = "config"
- indexPath = "index"
- shallowPath = "shallow"
- modulePath = "modules"
- objectsPath = "objects"
- packPath = "pack"
- refsPath = "refs"
+ suffix = ".git"
+ packedRefsPath = "packed-refs"
+ localConfigPath = "config"
+ globalConfigPath = ".gitconfig"
+ systemConfigPath = "/etc/gitconfig"
+ indexPath = "index"
+ shallowPath = "shallow"
+ modulePath = "modules"
+ objectsPath = "objects"
+ packPath = "pack"
+ refsPath = "refs"
tmpPackedRefsPrefix = "._packed-refs"
@@ -152,14 +154,32 @@ func (d *DotGit) Close() error {
return nil
}
-// ConfigWriter returns a file pointer for write to the config file
-func (d *DotGit) ConfigWriter() (billy.File, error) {
- return d.fs.Create(configPath)
+// LocalConfigWriter returns a file pointer for write to the local config file
+func (d *DotGit) LocalConfigWriter() (billy.File, error) {
+ return d.fs.Create(localConfigPath)
}
-// Config returns a file pointer for read to the config file
-func (d *DotGit) Config() (billy.File, error) {
- return d.fs.Open(configPath)
+// LocalConfig returns a file pointer for read to the local config file
+func (d *DotGit) LocalConfig() (billy.File, error) {
+ return d.fs.Open(localConfigPath)
+}
+
+// GlobalConfigWriter returns a file pointer for write to the global config file
+func (d *DotGit) GlobalConfigWriter() (billy.File, error) {
+ return osfs.New(os.Getenv("HOME")).Create(globalConfigPath)
+}
+
+// GlobalConfig returns a file pointer for read to the global config file
+func (d *DotGit) GlobalConfig() (billy.File, error) {
+ return osfs.New(os.Getenv("HOME")).Open(globalConfigPath)
+}
+
+// SystemConfigWriter doesn't exist because we typically do not have permission
+// to write to files in /etc.
+
+// SystemConfig returns a file pointer for read to the system config file
+func (d *DotGit) SystemConfig() (billy.File, error) {
+ return osfs.New("/").Open(systemConfigPath)
}
// IndexWriter returns a file pointer for write to the index file