2016-05-26 20:29:36 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2016-11-28 15:12:47 +00:00
|
|
|
"github.com/git-lfs/git-lfs/locking"
|
2016-05-26 20:29:36 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2016-05-27 22:26:15 +00:00
|
|
|
unlockCmdFlags unlockFlags
|
2016-05-26 20:29:36 +00:00
|
|
|
)
|
|
|
|
|
2016-05-27 22:26:15 +00:00
|
|
|
// unlockFlags holds the flags given to the `git lfs unlock` command
|
|
|
|
type unlockFlags struct {
|
|
|
|
// Id is the Id of the lock that is being unlocked.
|
|
|
|
Id string
|
|
|
|
// Force specifies whether or not the `lfs unlock` command was invoked
|
|
|
|
// with "--force", signifying the user's intent to break another
|
|
|
|
// individual's lock(s).
|
|
|
|
Force bool
|
|
|
|
}
|
|
|
|
|
2016-05-26 20:29:36 +00:00
|
|
|
func unlockCommand(cmd *cobra.Command, args []string) {
|
2016-12-05 11:25:02 +00:00
|
|
|
|
|
|
|
if len(lockRemote) > 0 {
|
|
|
|
cfg.CurrentRemote = lockRemote
|
|
|
|
}
|
|
|
|
|
2016-12-05 09:47:29 +00:00
|
|
|
lockClient, err := locking.NewClient(cfg)
|
|
|
|
if err != nil {
|
|
|
|
Exit("Unable to create lock system: %v", err.Error())
|
|
|
|
}
|
2016-12-05 15:01:25 +00:00
|
|
|
defer lockClient.Close()
|
2016-05-27 21:28:42 +00:00
|
|
|
if len(args) != 0 {
|
2016-05-27 22:19:16 +00:00
|
|
|
path, err := lockPath(args[0])
|
|
|
|
if err != nil {
|
2016-11-28 15:12:47 +00:00
|
|
|
Exit("Unable to determine path: %v", err.Error())
|
2016-05-27 22:19:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:25:02 +00:00
|
|
|
err = lockClient.UnlockFile(path, unlockCmdFlags.Force)
|
2016-11-28 15:12:47 +00:00
|
|
|
if err != nil {
|
|
|
|
Exit("Unable to unlock: %v", err.Error())
|
2016-05-27 21:28:42 +00:00
|
|
|
}
|
2016-05-27 22:26:15 +00:00
|
|
|
} else if unlockCmdFlags.Id != "" {
|
2016-12-05 11:25:02 +00:00
|
|
|
err := lockClient.UnlockFileById(unlockCmdFlags.Id, unlockCmdFlags.Force)
|
2016-11-28 15:12:47 +00:00
|
|
|
if err != nil {
|
|
|
|
Exit("Unable to unlock %v: %v", unlockCmdFlags.Id, err.Error())
|
|
|
|
}
|
2016-05-27 21:28:42 +00:00
|
|
|
} else {
|
|
|
|
Error("Usage: git lfs unlock (--id my-lock-id | <path>)")
|
2016-05-26 20:29:36 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 15:12:47 +00:00
|
|
|
Print("'%s' was unlocked", args[0])
|
2016-05-26 20:29:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2016-09-01 16:09:38 +00:00
|
|
|
if !isCommandEnabled(cfg, "locks") {
|
|
|
|
return
|
|
|
|
}
|
2016-05-27 21:28:42 +00:00
|
|
|
|
2016-09-01 16:09:38 +00:00
|
|
|
RegisterCommand("unlock", unlockCommand, func(cmd *cobra.Command) {
|
2016-08-10 15:33:25 +00:00
|
|
|
cmd.Flags().StringVarP(&lockRemote, "remote", "r", cfg.CurrentRemote, lockRemoteHelp)
|
|
|
|
cmd.Flags().StringVarP(&unlockCmdFlags.Id, "id", "i", "", "unlock a lock by its ID")
|
|
|
|
cmd.Flags().BoolVarP(&unlockCmdFlags.Force, "force", "f", false, "forcibly break another user's lock(s)")
|
|
|
|
})
|
2016-05-26 20:29:36 +00:00
|
|
|
}
|