04abbd8436
Following on from the changes in PR #4781, we can make additional message strings translatable using the tr.Tr.Get() method. Because this method performs printf(3)-style format string parsing and interpolation, we can simplify some of the surrounding calls, e.g., from fmt.Errorf() to errors.New(), and from fmt.Fprintf() to fmt.Fprintln(). This ensures that if either the translated text or any interpolated arguments happen to contain character sequences that would be interpreted as Go format specifiers (e.g., "%s" or "%d"), these will not result in warnings such as "%!s(MISSING)" in the output text. Note also that we try to remove newlines from the message strings were possible and change the surrounding calls to append them instead, e.g., with fmt.Fprintln().
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package commands
|
|
|
|
import (
|
|
"regexp"
|
|
|
|
"github.com/git-lfs/git-lfs/v3/tr"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
updateForce = false
|
|
updateManual = false
|
|
)
|
|
|
|
// updateCommand is used for updating parts of Git LFS that reside under
|
|
// .git/lfs.
|
|
func updateCommand(cmd *cobra.Command, args []string) {
|
|
requireGitVersion()
|
|
setupRepository()
|
|
|
|
lfsAccessRE := regexp.MustCompile(`\Alfs\.(.*)\.access\z`)
|
|
for key, _ := range cfg.Git.All() {
|
|
matches := lfsAccessRE.FindStringSubmatch(key)
|
|
if len(matches) < 2 {
|
|
continue
|
|
}
|
|
|
|
value, _ := cfg.Git.Get(key)
|
|
|
|
switch value {
|
|
case "basic":
|
|
case "private":
|
|
cfg.SetGitLocalKey(key, "basic")
|
|
Print(tr.Tr.Get("Updated %s access from %s to %s.", matches[1], value, "basic"))
|
|
default:
|
|
cfg.UnsetGitLocalKey(key)
|
|
Print(tr.Tr.Get("Removed invalid %s access of %s.", matches[1], value))
|
|
}
|
|
}
|
|
|
|
if updateForce && updateManual {
|
|
Exit(tr.Tr.Get("You cannot use --force and --manual options together"))
|
|
}
|
|
|
|
if updateManual {
|
|
Print(getHookInstallSteps())
|
|
} else {
|
|
if err := installHooks(updateForce); err != nil {
|
|
Error(err.Error())
|
|
Exit("%s\n 1: %s\n 2: %s",
|
|
tr.Tr.Get("To resolve this, either:"),
|
|
tr.Tr.Get("run `git lfs update --manual` for instructions on how to merge hooks."),
|
|
tr.Tr.Get("run `git lfs update --force` to overwrite your hook."))
|
|
} else {
|
|
Print(tr.Tr.Get("Updated Git hooks."))
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
func init() {
|
|
RegisterCommand("update", updateCommand, func(cmd *cobra.Command) {
|
|
cmd.Flags().BoolVarP(&updateForce, "force", "f", false, "Overwrite existing hooks.")
|
|
cmd.Flags().BoolVarP(&updateManual, "manual", "m", false, "Print instructions for manual install.")
|
|
})
|
|
}
|