commands/unlock: fix panic when unlocking with --id

This commit is contained in:
risk danger olson 2017-02-27 14:21:59 -07:00
parent c2283cd285
commit 9c04fb2f59
2 changed files with 17 additions and 12 deletions

@ -38,7 +38,7 @@ func unlockCommand(cmd *cobra.Command, args []string) {
lockClient := newLockClient(lockRemote)
defer lockClient.Close()
if len(args) != 0 {
if hasPath {
path, err := lockPath(args[0])
if err != nil && !unlockCmdFlags.Force {
Exit("Unable to determine path: %v", err.Error())
@ -51,8 +51,12 @@ func unlockCommand(cmd *cobra.Command, args []string) {
if err != nil {
Exit("%s", errors.Cause(err))
}
} else if unlockCmdFlags.Id != "" {
if !locksCmdFlags.JSON {
Print("Unlocked %s", path)
return
}
} else if unlockCmdFlags.Id != "" {
// This call can early-out
unlockAbortIfFileModifiedById(unlockCmdFlags.Id, lockClient)
@ -60,20 +64,21 @@ func unlockCommand(cmd *cobra.Command, args []string) {
if err != nil {
Exit("Unable to unlock %v: %v", unlockCmdFlags.Id, errors.Cause(err))
}
if !locksCmdFlags.JSON {
Print("Unlocked Lock %s", unlockCmdFlags.Id)
return
}
} else {
Error(unlockUsage)
}
if locksCmdFlags.JSON {
if err := json.NewEncoder(os.Stdout).Encode(struct {
Unlocked bool `json:"unlocked"`
}{true}); err != nil {
Error(err.Error())
}
return
if err := json.NewEncoder(os.Stdout).Encode(struct {
Unlocked bool `json:"unlocked"`
}{true}); err != nil {
Error(err.Error())
}
Print("Unlocked %s", args[0])
return
}
func unlockAbortIfFileModified(path string) {

@ -76,7 +76,7 @@ begin_test "unlocking a lock by id"
id=$(assert_lock lock.log d.dat)
assert_server_lock "$reponame" "$id"
git lfs unlock --id="$id" 2>&1 | tee unlock.log
git lfs unlock --id="$id"
refute_server_lock "$reponame" "$id"
)
end_test