Move CurrentCommitter to Configuration instead of API

This removes another implicit dependency on global config from API pkg
This commit is contained in:
Steve Streeting 2016-12-05 11:45:24 +00:00
parent de63cd1d46
commit cf1b0e1ed8
3 changed files with 12 additions and 12 deletions

@ -4,8 +4,6 @@ import (
"fmt"
"strconv"
"time"
"github.com/git-lfs/git-lfs/config"
)
// LockService is an API service which encapsulates the Git LFS Locking API.
@ -144,15 +142,8 @@ type Committer struct {
Email string `json:"email"`
}
// CurrentCommitter returns a Committer instance populated with the same
// credentials as would be used to author a commit. In particular, the
// "user.name" and "user.email" configuration values are used from the
// config.Config singleton.
func CurrentCommitter() Committer {
name, _ := config.Config.Git.Get("user.name")
email, _ := config.Config.Git.Get("user.email")
return Committer{name, email}
func NewCommitter(name, email string) Committer {
return Committer{Name: name, Email: email}
}
// LockRequest encapsulates the payload sent across the API when a client would

@ -492,3 +492,12 @@ func (c *Configuration) loadGitConfig() bool {
return false
}
// CurrentCommitter returns the name/email that would be used to author a commit
// with this configuration. In particular, the "user.name" and "user.email"
// configuration values are used
func (c *Configuration) CurrentCommitter() (name, email string) {
name, _ = c.Git.Get("user.name")
email, _ = c.Git.Get("user.email")
return
}

@ -57,7 +57,7 @@ func (c *Client) LockFile(path string) (id string, e error) {
s, resp := c.apiClient.Locks.Lock(&api.LockRequest{
Path: path,
Committer: api.CurrentCommitter(),
Committer: api.NewCommitter(c.cfg.CurrentCommitter()),
LatestRemoteCommit: latest.Sha,
})