aboutsummaryrefslogtreecommitdiffstats
path: root/options_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2020-06-05 07:02:15 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2020-06-05 07:02:15 +0200
commit531a81eae684d8cae617d3d9a26923a66eb25d40 (patch)
treebad8ba6004f59497b00dd4edf098766a375f7beb /options_test.go
parent8019144b6534ff58ad234a355e5b143f1c99b45e (diff)
downloadgo-git-531a81eae684d8cae617d3d9a26923a66eb25d40.tar.gz
CreateTagOptions.Validate: load Tagger from config
Diffstat (limited to 'options_test.go')
-rw-r--r--options_test.go84
1 files changed, 84 insertions, 0 deletions
diff --git a/options_test.go b/options_test.go
index aa36dab..86d725a 100644
--- a/options_test.go
+++ b/options_test.go
@@ -1,6 +1,12 @@
package git
import (
+ "io/ioutil"
+ "os"
+ "path/filepath"
+
+ "github.com/go-git/go-git/v5/config"
+ "github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
. "gopkg.in/check.v1"
)
@@ -27,3 +33,81 @@ func (s *OptionsSuite) TestCommitOptionsCommitter(c *C) {
c.Assert(o.Committer, Equals, o.Author)
}
+
+func (s *OptionsSuite) TestCommitOptionsLoadGlobalConfigUser(c *C) {
+ cfg := config.NewConfig()
+ cfg.User.Name = "foo"
+ cfg.User.Email = "foo@foo.com"
+
+ s.writeGlobalConfig(c, cfg)
+ defer s.clearGlobalConfig(c)
+
+ o := CommitOptions{}
+ err := o.Validate(s.Repository)
+ c.Assert(err, IsNil)
+
+ c.Assert(o.Author.Name, Equals, "foo")
+ c.Assert(o.Author.Email, Equals, "foo@foo.com")
+ c.Assert(o.Committer.Name, Equals, "foo")
+ c.Assert(o.Committer.Email, Equals, "foo@foo.com")
+}
+
+func (s *OptionsSuite) TestCommitOptionsLoadGlobalCommitter(c *C) {
+ cfg := config.NewConfig()
+ cfg.User.Name = "foo"
+ cfg.User.Email = "foo@foo.com"
+ cfg.Committer.Name = "bar"
+ cfg.Committer.Email = "bar@bar.com"
+
+ s.writeGlobalConfig(c, cfg)
+ defer s.clearGlobalConfig(c)
+
+ o := CommitOptions{}
+ err := o.Validate(s.Repository)
+ c.Assert(err, IsNil)
+
+ c.Assert(o.Author.Name, Equals, "foo")
+ c.Assert(o.Author.Email, Equals, "foo@foo.com")
+ c.Assert(o.Committer.Name, Equals, "bar")
+ c.Assert(o.Committer.Email, Equals, "bar@bar.com")
+}
+
+func (s *OptionsSuite) TestCreateTagOptionsLoadGlobal(c *C) {
+ cfg := config.NewConfig()
+ cfg.User.Name = "foo"
+ cfg.User.Email = "foo@foo.com"
+
+ s.writeGlobalConfig(c, cfg)
+ defer s.clearGlobalConfig(c)
+
+ o := CreateTagOptions{
+ Message: "foo",
+ }
+
+ err := o.Validate(s.Repository, plumbing.ZeroHash)
+ c.Assert(err, IsNil)
+
+ c.Assert(o.Tagger.Name, Equals, "foo")
+ c.Assert(o.Tagger.Email, Equals, "foo@foo.com")
+}
+
+func (s *OptionsSuite) writeGlobalConfig(c *C, cfg *config.Config) {
+ tmp, err := ioutil.TempDir("", "test-options")
+ c.Assert(err, IsNil)
+
+ err = os.Mkdir(filepath.Join(tmp, "git"), 0777)
+ c.Assert(err, IsNil)
+
+ os.Setenv("XDG_CONFIG_HOME", tmp)
+
+ content, err := cfg.Marshal()
+ c.Assert(err, IsNil)
+
+ cfgFile := filepath.Join(tmp, "git/config")
+ err = ioutil.WriteFile(cfgFile, content, 0777)
+ c.Assert(err, IsNil)
+}
+
+func (s *OptionsSuite) clearGlobalConfig(c *C) {
+ os.Setenv("XDG_CONFIG_HOME", "")
+}