aboutsummaryrefslogtreecommitdiffstats
path: root/repository.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2020-05-24 11:23:04 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2020-05-24 11:23:04 +0200
commit86c0c010927fe59ae54563a9a86db200a18f4c2e (patch)
treef83e183db75f414163ab8422ac6e00c0f6eebf31 /repository.go
parent26d02b3fec4434d663445d580497204e79284db0 (diff)
downloadgo-git-86c0c010927fe59ae54563a9a86db200a18f4c2e.tar.gz
Repository.ConfigScoped and Repository.Commit with empty author support
Diffstat (limited to 'repository.go')
-rw-r--r--repository.go58
1 files changed, 46 insertions, 12 deletions
diff --git a/repository.go b/repository.go
index c83a136..60baf85 100644
--- a/repository.go
+++ b/repository.go
@@ -13,7 +13,6 @@ import (
"strings"
"time"
- "golang.org/x/crypto/openpgp"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/internal/revision"
"github.com/go-git/go-git/v5/plumbing"
@@ -24,6 +23,8 @@ import (
"github.com/go-git/go-git/v5/storage"
"github.com/go-git/go-git/v5/storage/filesystem"
"github.com/go-git/go-git/v5/utils/ioutil"
+ "github.com/imdario/mergo"
+ "golang.org/x/crypto/openpgp"
"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/osfs"
@@ -155,7 +156,7 @@ func setConfigWorktree(r *Repository, worktree, storage billy.Filesystem) error
return nil
}
- cfg, err := r.Storer.Config()
+ cfg, err := r.Config()
if err != nil {
return err
}
@@ -439,9 +440,42 @@ func (r *Repository) Config() (*config.Config, error) {
return r.Storer.Config()
}
+// ConfigScoped returns the repository config, merged with requested scope and
+// lower. For example if, config.GlobalScope is given the local and global config
+// are returned merged in one config value.
+func (r *Repository) ConfigScoped(scope config.Scope) (*config.Config, error) {
+ // TODO(mcuadros): v6, add this as ConfigOptions.Scoped
+
+ var err error
+ system := config.NewConfig()
+ if scope >= config.SystemScope {
+ system, err = config.LoadConfig(config.SystemScope)
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ global := config.NewConfig()
+ if scope >= config.GlobalScope {
+ global, err = config.LoadConfig(config.GlobalScope)
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ local, err := r.Storer.Config()
+ if err != nil {
+ return nil, err
+ }
+
+ _ = mergo.Merge(global, system)
+ _ = mergo.Merge(local, global)
+ return local, nil
+}
+
// Remote return a remote if exists
func (r *Repository) Remote(name string) (*Remote, error) {
- cfg, err := r.Storer.Config()
+ cfg, err := r.Config()
if err != nil {
return nil, err
}
@@ -456,7 +490,7 @@ func (r *Repository) Remote(name string) (*Remote, error) {
// Remotes returns a list with all the remotes
func (r *Repository) Remotes() ([]*Remote, error) {
- cfg, err := r.Storer.Config()
+ cfg, err := r.Config()
if err != nil {
return nil, err
}
@@ -480,7 +514,7 @@ func (r *Repository) CreateRemote(c *config.RemoteConfig) (*Remote, error) {
remote := NewRemote(r.Storer, c)
- cfg, err := r.Storer.Config()
+ cfg, err := r.Config()
if err != nil {
return nil, err
}
@@ -511,7 +545,7 @@ func (r *Repository) CreateRemoteAnonymous(c *config.RemoteConfig) (*Remote, err
// DeleteRemote delete a remote from the repository and delete the config
func (r *Repository) DeleteRemote(name string) error {
- cfg, err := r.Storer.Config()
+ cfg, err := r.Config()
if err != nil {
return err
}
@@ -526,7 +560,7 @@ func (r *Repository) DeleteRemote(name string) error {
// Branch return a Branch if exists
func (r *Repository) Branch(name string) (*config.Branch, error) {
- cfg, err := r.Storer.Config()
+ cfg, err := r.Config()
if err != nil {
return nil, err
}
@@ -545,7 +579,7 @@ func (r *Repository) CreateBranch(c *config.Branch) error {
return err
}
- cfg, err := r.Storer.Config()
+ cfg, err := r.Config()
if err != nil {
return err
}
@@ -560,7 +594,7 @@ func (r *Repository) CreateBranch(c *config.Branch) error {
// DeleteBranch delete a Branch from the repository and delete the config
func (r *Repository) DeleteBranch(name string) error {
- cfg, err := r.Storer.Config()
+ cfg, err := r.Config()
if err != nil {
return err
}
@@ -835,7 +869,7 @@ func (r *Repository) cloneRefSpec(o *CloneOptions) []config.RefSpec {
}
func (r *Repository) setIsBare(isBare bool) error {
- cfg, err := r.Storer.Config()
+ cfg, err := r.Config()
if err != nil {
return err
}
@@ -851,7 +885,7 @@ func (r *Repository) updateRemoteConfigIfNeeded(o *CloneOptions, c *config.Remot
c.Fetch = r.cloneRefSpec(o)
- cfg, err := r.Storer.Config()
+ cfg, err := r.Config()
if err != nil {
return err
}
@@ -1541,7 +1575,7 @@ func (r *Repository) createNewObjectPack(cfg *RepackConfig) (h plumbing.Hash, er
return h, err
}
defer ioutil.CheckClose(wc, &err)
- scfg, err := r.Storer.Config()
+ scfg, err := r.Config()
if err != nil {
return h, err
}