diff --git a/config/config.go b/config/config.go index c27ff0e3..756f2061 100644 --- a/config/config.go +++ b/config/config.go @@ -533,6 +533,19 @@ func (c *Configuration) CurrentCommitterTimestamp() time.Time { return c.timestamp } +// CurrentAuthor returns the name/email that would be used to author a change +// with this configuration. In particular, the "user.name" and "user.email" +// configuration values are used +func (c *Configuration) CurrentAuthor() (name, email string) { + return c.findUserData("author") +} + +// CurrentCommitterTimestamp returns the timestamp that would be used to commit +// a change with this configuration. +func (c *Configuration) CurrentAuthorTimestamp() time.Time { + return c.timestamp +} + // RepositoryPermissions returns the permissions that should be used to write // files in the repository. func (c *Configuration) RepositoryPermissions() os.FileMode { diff --git a/config/config_test.go b/config/config_test.go index a66ace6b..ecff2f00 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -234,4 +234,24 @@ func TestCurrentUser(t *testing.T) { name, email = cfg.CurrentCommitter() assert.Equal(t, name, "Sam Roe") assert.Equal(t, email, "sroe@example.net") + + cfg = NewFrom(Values{ + Git: map[string][]string{ + "user.name": []string{"Pat Doe"}, + "user.email": []string{"pdoe@example.org"}, + }, + Os: map[string][]string{ + "GIT_AUTHOR_NAME": []string{"Sam Roe"}, + "GIT_AUTHOR_EMAIL": []string{"sroe@example.net"}, + "EMAIL": []string{"pdoe@example.com"}, + }, + }) + + name, email = cfg.CurrentCommitter() + assert.Equal(t, name, "Pat Doe") + assert.Equal(t, email, "pdoe@example.org") + + name, email = cfg.CurrentAuthor() + assert.Equal(t, name, "Sam Roe") + assert.Equal(t, email, "sroe@example.net") }