Merge branch 'master' into locking-pre-push
This commit is contained in:
commit
b2cfaf67c6
@ -32,7 +32,7 @@ func locksCommand(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
for _, lock := range locks {
|
||||
Print("%s\t%s <%s>", lock.Path, lock.Name, lock.Email)
|
||||
Print("%s\t%s", lock.Path, lock.Committer)
|
||||
lockCount++
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ type lockRequest struct {
|
||||
// `.git/refs/origin/<name>`.
|
||||
LatestRemoteCommit string `json:"latest_remote_commit"`
|
||||
// Committer is the individual that wishes to obtain the lock.
|
||||
Committer committer `json:"committer"`
|
||||
Committer Committer `json:"committer"`
|
||||
}
|
||||
|
||||
// LockResponse encapsulates the information sent over the API in response to
|
||||
@ -191,7 +191,7 @@ func (c *lockClient) Search(remote string, searchReq *lockSearchRequest) (*lockL
|
||||
}
|
||||
|
||||
// Committer represents a "First Last <email@domain.com>" pair.
|
||||
type committer struct {
|
||||
type Committer struct {
|
||||
// Name is the name of the individual who would like to obtain the
|
||||
// lock, for instance: "Rick Olson".
|
||||
Name string `json:"name"`
|
||||
@ -200,6 +200,12 @@ type committer struct {
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
func newCommitter(name, email string) committer {
|
||||
return committer{Name: name, Email: email}
|
||||
func NewCommitter(name, email string) Committer {
|
||||
return Committer{Name: name, Email: email}
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer interface by returning a string
|
||||
// representation of the Committer in the format "First Last <email>".
|
||||
func (c *Committer) String() string {
|
||||
return fmt.Sprintf("%s <%s>", c.Name, c.Email)
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ func (c *Client) LockFile(path string) (Lock, error) {
|
||||
lockReq := &lockRequest{
|
||||
Path: path,
|
||||
LatestRemoteCommit: latest.Sha,
|
||||
Committer: newCommitter(c.client.CurrentUser()),
|
||||
Committer: NewCommitter(c.client.CurrentUser()),
|
||||
}
|
||||
|
||||
lockRes, _, err := c.client.Lock(c.Remote, lockReq)
|
||||
@ -146,10 +146,9 @@ type Lock struct {
|
||||
// Path is an absolute path to the file that is locked as a part of this
|
||||
// lock.
|
||||
Path string `json:"path"`
|
||||
// Name is the name of the person holding this lock
|
||||
Name string `json:"name"`
|
||||
// Email address of the person holding this lock
|
||||
Email string `json:"email"`
|
||||
// Committer is the identity of the person who holds the ownership of
|
||||
// this lock.
|
||||
Committer Committer `json:"committer"`
|
||||
// LockedAt is the time at which this lock was acquired.
|
||||
LockedAt time.Time `json:"locked_at"`
|
||||
}
|
||||
@ -267,7 +266,7 @@ func (c *Client) refreshLockCache() error {
|
||||
|
||||
_, email := c.client.CurrentUser()
|
||||
for _, l := range locks {
|
||||
if l.Email == email {
|
||||
if l.Committer.Email == email {
|
||||
c.cache.Add(l)
|
||||
}
|
||||
}
|
||||
|
@ -32,11 +32,11 @@ func TestRefreshCache(t *testing.T) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
err = json.NewEncoder(w).Encode(lockList{
|
||||
Locks: []Lock{
|
||||
Lock{Id: "99", Path: "folder/test3.dat", Name: "Alice", Email: "alice@wonderland.com"},
|
||||
Lock{Id: "101", Path: "folder/test1.dat", Name: "Fred", Email: "fred@bloggs.com"},
|
||||
Lock{Id: "102", Path: "folder/test2.dat", Name: "Fred", Email: "fred@bloggs.com"},
|
||||
Lock{Id: "103", Path: "root.dat", Name: "Fred", Email: "fred@bloggs.com"},
|
||||
Lock{Id: "199", Path: "other/test1.dat", Name: "Charles", Email: "charles@incharge.com"},
|
||||
Lock{Id: "99", Path: "folder/test3.dat", Committer: Committer{Name: "Alice", Email: "alice@wonderland.com"}},
|
||||
Lock{Id: "101", Path: "folder/test1.dat", Committer: Committer{Name: "Fred", Email: "fred@bloggs.com"}},
|
||||
Lock{Id: "102", Path: "folder/test2.dat", Committer: Committer{Name: "Fred", Email: "fred@bloggs.com"}},
|
||||
Lock{Id: "103", Path: "root.dat", Committer: Committer{Name: "Fred", Email: "fred@bloggs.com"}},
|
||||
Lock{Id: "199", Path: "other/test1.dat", Committer: Committer{Name: "Charles", Email: "charles@incharge.com"}},
|
||||
},
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
@ -74,9 +74,9 @@ func TestRefreshCache(t *testing.T) {
|
||||
// Sort locks for stable comparison
|
||||
sort.Sort(LocksById(locks))
|
||||
assert.Equal(t, []Lock{
|
||||
Lock{Path: "folder/test1.dat", Id: "101", Name: "Fred", Email: "fred@bloggs.com", LockedAt: zeroTime},
|
||||
Lock{Path: "folder/test2.dat", Id: "102", Name: "Fred", Email: "fred@bloggs.com", LockedAt: zeroTime},
|
||||
Lock{Path: "root.dat", Id: "103", Name: "Fred", Email: "fred@bloggs.com", LockedAt: zeroTime},
|
||||
Lock{Path: "folder/test1.dat", Id: "101", Committer: Committer{Name: "Fred", Email: "fred@bloggs.com"}, LockedAt: zeroTime},
|
||||
Lock{Path: "folder/test2.dat", Id: "102", Committer: Committer{Name: "Fred", Email: "fred@bloggs.com"}, LockedAt: zeroTime},
|
||||
Lock{Path: "root.dat", Id: "103", Committer: Committer{Name: "Fred", Email: "fred@bloggs.com"}, LockedAt: zeroTime},
|
||||
}, locks)
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user