config: add functions to look up current author
Since we have functions to look up the current committer, also add a set to look up the current author. This lets us honor the Git environment variable settings to handle different values for authors and committers.
This commit is contained in:
parent
4fd69115c0
commit
1c95b957a4
@ -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 {
|
||||
|
@ -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")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user