commands/unlock: make strings translatable

Move the string for lockRemoteHelp variable into the actual help output.
We cannot translate a global variable because at initialization time the
locale string won't have been loaded and we won't be able to load the
proper string.  Since the variable is now unused, remove it.
This commit is contained in:
brian m. carlson 2021-12-13 18:49:04 +00:00
parent d458827544
commit da2a92c6dd
No known key found for this signature in database
GPG Key ID: 2D0C9BC12F82B3A1
3 changed files with 14 additions and 17 deletions

@ -15,8 +15,7 @@ import (
)
var (
lockRemote string
lockRemoteHelp = "specify which remote to use when interacting with locks"
lockRemote string
)
func lockCommand(cmd *cobra.Command, args []string) {

@ -2,12 +2,12 @@ package commands
import (
"encoding/json"
"fmt"
"os"
"github.com/git-lfs/git-lfs/v3/errors"
"github.com/git-lfs/git-lfs/v3/git"
"github.com/git-lfs/git-lfs/v3/locking"
"github.com/git-lfs/git-lfs/v3/tr"
"github.com/spf13/cobra"
)
@ -25,8 +25,6 @@ type unlockFlags struct {
Force bool
}
var unlockUsage = "Usage: git lfs unlock (--id my-lock-id | <path>)"
type unlockResponse struct {
Id string `json:"id,omitempty"`
Path string `json:"path,omitempty"`
@ -53,7 +51,7 @@ func unlockCommand(cmd *cobra.Command, args []string) {
if hasPath == hasId {
// If there is both an `--id` AND a `<path>`, or there is
// neither, print the usage and quit.
Exit(unlockUsage)
Exit(tr.Tr.Get("Exactly one of --id or a set of paths must be provided"))
}
if len(lockRemote) > 0 {
@ -72,7 +70,7 @@ func unlockCommand(cmd *cobra.Command, args []string) {
path, err := lockPath(pathspec)
if err != nil {
if !unlockCmdFlags.Force {
locks = handleUnlockError(locks, "", path, fmt.Errorf("Unable to determine path: %v", err.Error()))
locks = handleUnlockError(locks, "", path, errors.New(tr.Tr.Get("Unable to determine path: %v", err.Error())))
success = false
continue
}
@ -107,13 +105,13 @@ func unlockCommand(cmd *cobra.Command, args []string) {
err := lockClient.UnlockFileById(unlockCmdFlags.Id, unlockCmdFlags.Force)
if err != nil {
locks = handleUnlockError(locks, unlockCmdFlags.Id, "", fmt.Errorf("Unable to unlock %v: %v", unlockCmdFlags.Id, errors.Cause(err)))
locks = handleUnlockError(locks, unlockCmdFlags.Id, "", errors.New(tr.Tr.Get("Unable to unlock %v: %v", unlockCmdFlags.Id, errors.Cause(err))))
success = false
} else if !locksCmdFlags.JSON {
Print("Unlocked Lock %s", unlockCmdFlags.Id)
Print(tr.Tr.Get("Unlocked Lock %s", unlockCmdFlags.Id))
}
} else {
Error(unlockUsage)
Exit(tr.Tr.Get("Exactly one of --id or a set of paths must be provided"))
}
if locksCmdFlags.JSON {
@ -145,9 +143,9 @@ func unlockAbortIfFileModified(path string) error {
if modified {
if unlockCmdFlags.Force {
// Only a warning
Error("Warning: unlocking with uncommitted changes because --force")
Error(tr.Tr.Get("warning: unlocking with uncommitted changes because --force"))
} else {
return fmt.Errorf("Cannot unlock file with uncommitted changes")
return errors.New(tr.Tr.Get("Cannot unlock file with uncommitted changes"))
}
}
@ -174,7 +172,7 @@ func unlockAbortIfFileModifiedById(id string, lockClient *locking.Client) error
func init() {
RegisterCommand("unlock", unlockCommand, func(cmd *cobra.Command) {
cmd.Flags().StringVarP(&lockRemote, "remote", "r", "", lockRemoteHelp)
cmd.Flags().StringVarP(&lockRemote, "remote", "r", "", "specify which remote to use when interacting with locks")
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)")
cmd.Flags().BoolVarP(&locksCmdFlags.JSON, "json", "", false, "print output in json")

@ -137,7 +137,7 @@ begin_test "unlock multiple files"
git lfs lock a.dat
git lfs lock b.dat
git lfs unlock *.dat >log 2>&1
grep "Usage:" log && exit 1
grep "Exactly one of --id or a set of paths must be provided" log && exit 1
true
)
end_test
@ -321,7 +321,7 @@ begin_test "unlocking a lock without sufficient info"
assert_server_lock "$reponame" "$id"
git lfs unlock 2>&1 | tee unlock.log
grep "Usage: git lfs unlock" unlock.log
grep "Exactly one of --id or a set of paths must be provided" unlock.log
assert_server_lock "$reponame" "$id"
)
end_test
@ -372,7 +372,7 @@ begin_test "unlocking a lock with ambiguous arguments"
exit 1
fi
grep "Usage:" unlock.log
grep "Exactly one of --id or a set of paths must be provided" unlock.log
assert_server_lock "$reponame" "$id"
)
end_test
@ -393,7 +393,7 @@ begin_test "unlocking a lock while uncommitted with --force"
# should allow with --force
git lfs unlock --force "modforce.dat" 2>&1 | tee unlock.log
grep "Warning: unlocking with uncommitted changes" unlock.log
grep "warning: unlocking with uncommitted changes" unlock.log
refute_server_lock "$reponame" "$id"
)
end_test