diff --git a/commands/command_lock.go b/commands/command_lock.go index d3e6ab84..7ff122ea 100644 --- a/commands/command_lock.go +++ b/commands/command_lock.go @@ -17,7 +17,6 @@ var ( ) func lockCommand(cmd *cobra.Command, args []string) { - if len(args) == 0 { Print("Usage: git lfs lock ") return @@ -32,7 +31,7 @@ func lockCommand(cmd *cobra.Command, args []string) { cfg.CurrentRemote = lockRemote } - lockClient, err := locking.NewClient(lockRemote, APIClient(), cfg) + lockClient, err := locking.NewClient(lockRemote, APIClient()) if err != nil { Exit("Unable to create lock system: %v", err.Error()) } diff --git a/commands/command_locks.go b/commands/command_locks.go index de3c49c4..391f2f9f 100644 --- a/commands/command_locks.go +++ b/commands/command_locks.go @@ -10,7 +10,6 @@ var ( ) func locksCommand(cmd *cobra.Command, args []string) { - filters, err := locksCmdFlags.Filters() if err != nil { Exit("Error building filters: %v", err) @@ -19,7 +18,7 @@ func locksCommand(cmd *cobra.Command, args []string) { if len(lockRemote) > 0 { cfg.CurrentRemote = lockRemote } - lockClient, err := locking.NewClient(lockRemote, APIClient(), cfg) + lockClient, err := locking.NewClient(lockRemote, APIClient()) if err != nil { Exit("Unable to create lock system: %v", err.Error()) } diff --git a/commands/command_unlock.go b/commands/command_unlock.go index 3ad5d4be..73807812 100644 --- a/commands/command_unlock.go +++ b/commands/command_unlock.go @@ -21,12 +21,11 @@ type unlockFlags struct { } func unlockCommand(cmd *cobra.Command, args []string) { - if len(lockRemote) > 0 { cfg.CurrentRemote = lockRemote } - lockClient, err := locking.NewClient(lockRemote, APIClient(), cfg) + lockClient, err := locking.NewClient(lockRemote, APIClient()) if err != nil { Exit("Unable to create lock system: %v", err.Error()) } diff --git a/lfsapi/client.go b/lfsapi/client.go index e42c38a6..e06af1b2 100644 --- a/lfsapi/client.go +++ b/lfsapi/client.go @@ -161,6 +161,12 @@ func (c *Client) httpClient(host string) *http.Client { return httpClient } +func (c *Client) CurrentUser() (string, string) { + userName, _ := c.gitEnv.Get("user.name") + userEmail, _ := c.gitEnv.Get("user.email") + return userName, userEmail +} + func newRequestForRetry(req *http.Request, location string) (*http.Request, error) { newReq, err := http.NewRequest(req.Method, location, nil) if err != nil { diff --git a/locking/locks.go b/locking/locks.go index 595b56c1..e24cd647 100644 --- a/locking/locks.go +++ b/locking/locks.go @@ -27,14 +27,13 @@ var ( type Client struct { Remote string client *lockClient - cfg *config.Configuration cache *LockCache } // NewClient creates a new locking client with the given configuration // You must call the returned object's `Close` method when you are finished with // it -func NewClient(remote string, lfsClient *lfsapi.Client, cfg *config.Configuration) (*Client, error) { +func NewClient(remote string, lfsClient *lfsapi.Client) (*Client, error) { lockDir := filepath.Join(config.LocalGitStorageDir, "lfs") err := os.MkdirAll(lockDir, 0755) if err != nil { @@ -49,7 +48,6 @@ func NewClient(remote string, lfsClient *lfsapi.Client, cfg *config.Configuratio return &Client{ Remote: remote, client: &lockClient{Client: lfsClient}, - cfg: cfg, cache: cache, }, nil } @@ -72,7 +70,7 @@ func (c *Client) LockFile(path string) (Lock, error) { lockReq := &lockRequest{ Path: path, LatestRemoteCommit: latest.Sha, - Committer: newCommitter(c.cfg.CurrentCommitter()), + Committer: newCommitter(c.client.CurrentUser()), } lockRes, _, err := c.client.Lock(c.Remote, lockReq) @@ -96,7 +94,6 @@ func (c *Client) LockFile(path string) (Lock, error) { // path must be relative to the root of the repository // Force causes the file to be unlocked from other users as well func (c *Client) UnlockFile(path string, force bool) error { - id, err := c.lockIdFromPath(path) if err != nil { return fmt.Errorf("Unable to get lock id: %v", err) @@ -262,7 +259,7 @@ func (c *Client) refreshLockCache() error { // We're going to overwrite the entire local cache c.cache.Clear() - _, email := c.cfg.CurrentCommitter() + _, email := c.client.CurrentUser() for _, l := range locks { if l.Email == email { c.cache.Add(l) diff --git a/locking/locks_test.go b/locking/locks_test.go index 9c591241..f5bdab89 100644 --- a/locking/locks_test.go +++ b/locking/locks_test.go @@ -51,8 +51,6 @@ func TestRefreshCache(t *testing.T) { config.LocalGitStorageDir = oldStore }() - cfg := config.NewFrom(config.Values{ - Git: map[string]string{"user.name": "Fred", "user.email": "fred@bloggs.com"}}) lfsclient, err := lfsapi.NewClient(nil, lfsapi.Env(map[string]string{ "lfs.url": srv.URL + "/api", "user.name": "Fred", @@ -60,7 +58,7 @@ func TestRefreshCache(t *testing.T) { })) require.Nil(t, err) - client, err := NewClient("", lfsclient, cfg) + client, err := NewClient("", lfsclient) assert.Nil(t, err) // Should start with no cached items