commands/checkout: make strings translatable

This commit is contained in:
brian m. carlson 2021-11-19 15:53:17 +00:00
parent 4db7278965
commit f32961cc68
No known key found for this signature in database
GPG Key ID: 2D0C9BC12F82B3A1

@ -4,11 +4,13 @@ import (
"fmt"
"os"
"github.com/git-lfs/git-lfs/v3/errors"
"github.com/git-lfs/git-lfs/v3/filepathfilter"
"github.com/git-lfs/git-lfs/v3/git"
"github.com/git-lfs/git-lfs/v3/lfs"
"github.com/git-lfs/git-lfs/v3/tasklog"
"github.com/git-lfs/git-lfs/v3/tq"
"github.com/git-lfs/git-lfs/v3/tr"
"github.com/spf13/cobra"
)
@ -24,7 +26,7 @@ func checkoutCommand(cmd *cobra.Command, args []string) {
stage, err := whichCheckout()
if err != nil {
Exit("Error parsing args: %v", err)
Exit(tr.Tr.Get("Error parsing args: %v", err))
}
if checkoutTo != "" && stage != git.IndexStageDefault {
@ -34,17 +36,17 @@ func checkoutCommand(cmd *cobra.Command, args []string) {
checkoutConflict(rootedPaths(args)[0], stage)
return
} else if checkoutTo != "" || stage != git.IndexStageDefault {
Exit("--to and exactly one of --theirs, --ours, and --base must be used together")
Exit(tr.Tr.Get("--to and exactly one of --theirs, --ours, and --base must be used together"))
}
ref, err := git.CurrentRef()
if err != nil {
Panic(err, "Could not checkout")
Panic(err, tr.Tr.Get("Could not checkout"))
}
singleCheckout := newSingleCheckout(cfg.Git, "")
if singleCheckout.Skip() {
fmt.Println("Cannot checkout LFS objects, Git LFS is not installed.")
fmt.Println(tr.Tr.Get("Cannot checkout LFS objects, Git LFS is not installed."))
return
}
@ -59,7 +61,7 @@ func checkoutCommand(cmd *cobra.Command, args []string) {
logger.Enqueue(meter)
chgitscanner := lfs.NewGitScanner(cfg, func(p *lfs.WrappedPointer, err error) {
if err != nil {
LoggedError(err, "Scanner error: %s", err)
LoggedError(err, tr.Tr.Get("Scanner error: %s", err))
return
}
@ -93,33 +95,33 @@ func checkoutCommand(cmd *cobra.Command, args []string) {
func checkoutConflict(file string, stage git.IndexStage) {
singleCheckout := newSingleCheckout(cfg.Git, "")
if singleCheckout.Skip() {
fmt.Println("Cannot checkout LFS objects, Git LFS is not installed.")
fmt.Println(tr.Tr.Get("Cannot checkout LFS objects, Git LFS is not installed."))
return
}
ref, err := git.ResolveRef(fmt.Sprintf(":%d:%s", stage, file))
if err != nil {
Exit("Could not checkout (are you not in the middle of a merge?): %v", err)
Exit(tr.Tr.Get("Could not checkout (are you not in the middle of a merge?): %v", err))
}
scanner, err := git.NewObjectScanner(cfg.GitEnv(), cfg.OSEnv())
if err != nil {
Exit("Could not create object scanner: %v", err)
Exit(tr.Tr.Get("Could not create object scanner: %v", err))
}
if !scanner.Scan(ref.Sha) {
Exit("Could not find object %q", ref.Sha)
Exit(tr.Tr.Get("Could not find object %q", ref.Sha))
}
ptr, err := lfs.DecodePointer(scanner.Contents())
if err != nil {
Exit("Could not find decoder pointer for object %q: %v", ref.Sha, err)
Exit(tr.Tr.Get("Could not find decoder pointer for object %q: %v", ref.Sha, err))
}
p := &lfs.WrappedPointer{Name: file, Pointer: ptr}
if err := singleCheckout.RunToPath(p, checkoutTo); err != nil {
Exit("Error checking out %v to %q: %v", ref.Sha, checkoutTo, err)
Exit(tr.Tr.Get("Error checking out %v to %q: %v", ref.Sha, checkoutTo, err))
}
singleCheckout.Close()
}
@ -142,7 +144,7 @@ func whichCheckout() (stage git.IndexStage, err error) {
}
if seen > 1 {
return 0, fmt.Errorf("at most one of --base, --theirs, and --ours is allowed")
return 0, errors.New(tr.Tr.Get("at most one of --base, --theirs, and --ours is allowed"))
}
return stage, nil
}