locking: rename 'committer' to 'owner'
This commit is contained in:
parent
63dd3634a1
commit
f0d9be4684
@ -32,7 +32,7 @@ func locksCommand(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
for _, lock := range locks {
|
||||
Print("%s\t%s", lock.Path, lock.Committer)
|
||||
Print("%s\t%s", lock.Path, lock.Owner)
|
||||
lockCount++
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ func (c *uploadContext) Await() {
|
||||
|
||||
Print("Unable to push %d locked file(s):", ul)
|
||||
for _, unowned := range c.unownedLocks {
|
||||
Print("* %s - %s", unowned.Path, unowned.Committer)
|
||||
Print("* %s - %s", unowned.Path, unowned.Owner)
|
||||
}
|
||||
} else if len(c.ownedLocks) > 0 {
|
||||
Print("Consider unlocking your own locked file(s): (`git lfs unlock <path>`)")
|
||||
|
@ -53,9 +53,8 @@ as long as it's returned a string.
|
||||
* `path` - String path name of the locked file. This should be relative to the
|
||||
root of the repository working directory.
|
||||
* `locked_at` - The string ISO 8601 formatted timestamp the lock was created.
|
||||
* `committer` - The optional name/email of the user that created the Lock. This
|
||||
could be different from the `committer` values in the request if the lock
|
||||
service already knows the committer's identity based on the API credentials.
|
||||
* `owner` - The name of the user that created the Lock. This should be set from
|
||||
the user credentials posted when creating the lock.
|
||||
|
||||
```js
|
||||
// HTTP/1.1 201 Created
|
||||
@ -65,9 +64,8 @@ service already knows the committer's identity based on the API credentials.
|
||||
"id": "some-uuid",
|
||||
"path": "/path/to/file",
|
||||
"locked_at": "2016-05-17T15:49:06+00:00",
|
||||
"committer": {
|
||||
"owner": {
|
||||
"name": "Jane Doe",
|
||||
"email": "janedoe@email.com"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -177,7 +175,7 @@ Note: If the server has no locks, it must return an empty `locks` array.
|
||||
"id": "some-uuid",
|
||||
"path": "/path/to/file",
|
||||
"locked_at": "2016-05-17T15:49:06+00:00",
|
||||
"committer": {
|
||||
"owner": {
|
||||
"name": "Jane Doe"
|
||||
}
|
||||
}
|
||||
@ -285,7 +283,7 @@ Note: If the server has no locks, it must return an empty array in the `ours` or
|
||||
"id": "some-uuid",
|
||||
"path": "/path/to/file",
|
||||
"locked_at": "2016-05-17T15:49:06+00:00",
|
||||
"committer": {
|
||||
"owner": {
|
||||
"name": "Jane Doe"
|
||||
}
|
||||
}
|
||||
@ -390,7 +388,7 @@ response section to see what Lock properties are possible.
|
||||
"id": "some-uuid",
|
||||
"path": "/path/to/file",
|
||||
"locked_at": "2016-05-17T15:49:06+00:00",
|
||||
"committer": {
|
||||
"owner": {
|
||||
"name": "Jane Doe"
|
||||
}
|
||||
}
|
||||
|
@ -243,22 +243,18 @@ func (c *lockClient) SearchVerifiable(remote string, vreq *lockVerifiableRequest
|
||||
return locks, res, err
|
||||
}
|
||||
|
||||
// Committer represents a "First Last <email@domain.com>" pair.
|
||||
type Committer struct {
|
||||
// User represents the owner of a lock.
|
||||
type User struct {
|
||||
// Name is the name of the individual who would like to obtain the
|
||||
// lock, for instance: "Rick Olson".
|
||||
// lock, for instance: "Rick Sanchez".
|
||||
Name string `json:"name"`
|
||||
// Email is the email assopsicated with the individual who would
|
||||
// like to obtain the lock, for instance: "rick@github.com".
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
func NewCommitter(name, email string) *Committer {
|
||||
return &Committer{Name: name, Email: email}
|
||||
func NewUser(name string) *User {
|
||||
return &User{Name: name}
|
||||
}
|
||||
|
||||
// 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)
|
||||
// String implements the fmt.Stringer interface.
|
||||
func (u *User) String() string {
|
||||
return u.Name
|
||||
}
|
||||
|
@ -169,9 +169,8 @@ type Lock struct {
|
||||
// Path is an absolute path to the file that is locked as a part of this
|
||||
// lock.
|
||||
Path string `json:"path"`
|
||||
// Committer is the identity of the person who holds the ownership of
|
||||
// this lock.
|
||||
Committer *Committer `json:"committer"`
|
||||
// Owner is the identity of the user that created this lock.
|
||||
Owner *User `json:"owner"`
|
||||
// LockedAt is the time at which this lock was acquired.
|
||||
LockedAt time.Time `json:"locked_at"`
|
||||
}
|
||||
@ -325,11 +324,9 @@ func (c *Client) lockIdFromPath(path string) (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch locked files for the current committer and cache them locally
|
||||
// Fetch locked files for the current user and cache them locally
|
||||
// This can be used to sync up locked files when moving machines
|
||||
func (c *Client) refreshLockCache() error {
|
||||
// TODO: filters don't seem to currently define how to search for a
|
||||
// committer's email. Is it "committer.email"? For now, just iterate
|
||||
ourLocks, _, err := c.VerifiableLocks(0)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -345,9 +342,8 @@ func (c *Client) refreshLockCache() error {
|
||||
}
|
||||
|
||||
// IsFileLockedByCurrentCommitter returns whether a file is locked by the
|
||||
// current committer, as cached locally
|
||||
// current user, as cached locally
|
||||
func (c *Client) IsFileLockedByCurrentCommitter(path string) bool {
|
||||
|
||||
filter := map[string]string{"path": path}
|
||||
locks, err := c.searchCachedLocks(filter, 1)
|
||||
if err != nil {
|
||||
|
@ -26,17 +26,19 @@ func TestRefreshCache(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, "GET", r.Method)
|
||||
assert.Equal(t, "/api/locks", r.URL.Path)
|
||||
assert.Equal(t, "POST", r.Method)
|
||||
assert.Equal(t, "/api/locks/verify", r.URL.Path)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
err = json.NewEncoder(w).Encode(lockList{
|
||||
Locks: []Lock{
|
||||
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"}},
|
||||
err = json.NewEncoder(w).Encode(lockVerifiableList{
|
||||
Theirs: []Lock{
|
||||
Lock{Id: "99", Path: "folder/test3.dat", Owner: &User{Name: "Alice"}},
|
||||
Lock{Id: "199", Path: "other/test1.dat", Owner: &User{Name: "Charles"}},
|
||||
},
|
||||
Ours: []Lock{
|
||||
Lock{Id: "101", Path: "folder/test1.dat", Owner: &User{Name: "Fred"}},
|
||||
Lock{Id: "102", Path: "folder/test2.dat", Owner: &User{Name: "Fred"}},
|
||||
Lock{Id: "103", Path: "root.dat", Owner: &User{Name: "Fred"}},
|
||||
},
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
@ -74,9 +76,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", 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},
|
||||
Lock{Path: "folder/test1.dat", Id: "101", Owner: &User{Name: "Fred"}, LockedAt: zeroTime},
|
||||
Lock{Path: "folder/test2.dat", Id: "102", Owner: &User{Name: "Fred"}, LockedAt: zeroTime},
|
||||
Lock{Path: "root.dat", Id: "103", Owner: &User{Name: "Fred"}, LockedAt: zeroTime},
|
||||
}, locks)
|
||||
}
|
||||
|
||||
|
@ -757,21 +757,19 @@ func redirect307Handler(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(307)
|
||||
}
|
||||
|
||||
type Committer struct {
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
type User struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type Lock struct {
|
||||
Id string `json:"id"`
|
||||
Path string `json:"path"`
|
||||
Committer Committer `json:"committer"`
|
||||
LockedAt time.Time `json:"locked_at"`
|
||||
Id string `json:"id"`
|
||||
Path string `json:"path"`
|
||||
Owner User `json:"owner"`
|
||||
LockedAt time.Time `json:"locked_at"`
|
||||
}
|
||||
|
||||
type LockRequest struct {
|
||||
Path string `json:"path"`
|
||||
Committer Committer `json:"committer"`
|
||||
Path string `json:"path"`
|
||||
}
|
||||
|
||||
type LockResponse struct {
|
||||
@ -1029,10 +1027,10 @@ func locksHandler(w http.ResponseWriter, r *http.Request, repo string) {
|
||||
rand.Read(id[:])
|
||||
|
||||
lock := &Lock{
|
||||
Id: fmt.Sprintf("%x", id[:]),
|
||||
Path: lockRequest.Path,
|
||||
Committer: lockRequest.Committer,
|
||||
LockedAt: time.Now(),
|
||||
Id: fmt.Sprintf("%x", id[:]),
|
||||
Path: lockRequest.Path,
|
||||
Owner: User{Name: "Git LFS Tests"},
|
||||
LockedAt: time.Now(),
|
||||
}
|
||||
|
||||
addLocks(repo, *lock)
|
||||
|
@ -17,7 +17,7 @@ begin_test "list a single lock"
|
||||
GITLFSLOCKSENABLED=1 git lfs locks --path "f.dat" | tee locks.log
|
||||
grep "1 lock(s) matched query" locks.log
|
||||
grep "f.dat" locks.log
|
||||
grep "Git LFS Tests <git-lfs@example.com>" locks.log
|
||||
grep "Git LFS Tests" locks.log
|
||||
)
|
||||
end_test
|
||||
|
||||
@ -35,7 +35,7 @@ begin_test "list a single lock (--json)"
|
||||
|
||||
GITLFSLOCKSENABLED=1 git lfs locks --json --path "f_json.dat" | tee locks.log
|
||||
grep "\"path\":\"f_json.dat\"" locks.log
|
||||
grep "\"committer\":{\"name\":\"Git LFS Tests\",\"email\":\"git-lfs@example.com\"}" locks.log
|
||||
grep "\"owner\":{\"name\":\"Git LFS Tests\"}" locks.log
|
||||
)
|
||||
end_test
|
||||
|
||||
|
@ -529,10 +529,6 @@ begin_test "pre-push with their lock"
|
||||
setup_remote_repo "$reponame"
|
||||
clone_repo "$reponame" "$reponame"
|
||||
|
||||
# Use a different Git persona so the locks are owned by a different person
|
||||
git config --local user.name "Example Locker"
|
||||
git config --local user.email "locker@example.com"
|
||||
|
||||
git lfs track "*.dat"
|
||||
git add .gitattributes
|
||||
git commit -m "initial commit"
|
||||
@ -563,7 +559,7 @@ begin_test "pre-push with their lock"
|
||||
git push origin master 2>&1 | tee push.log
|
||||
|
||||
grep "Unable to push 1 locked file(s)" push.log
|
||||
grep "* locked_theirs.dat - Example Locker <locker@example.com>" push.log
|
||||
grep "* locked_theirs.dat - Git LFS Tests" push.log
|
||||
popd >/dev/null
|
||||
)
|
||||
end_test
|
||||
|
Loading…
Reference in New Issue
Block a user