git-lfs/commands/command_update.go

60 lines
1.3 KiB
Go
Raw Normal View History

package commands
import (
2015-09-08 16:20:52 +00:00
"os"
"regexp"
"github.com/github/git-lfs/git"
2015-03-19 19:30:55 +00:00
"github.com/github/git-lfs/lfs"
2015-05-25 18:20:50 +00:00
"github.com/github/git-lfs/vendor/_nuts/github.com/spf13/cobra"
)
var (
updateCmd = &cobra.Command{
Use: "update",
2015-03-19 19:30:55 +00:00
Short: "Update local Git LFS configuration",
Run: updateCommand,
}
updateForce = false
)
2015-03-19 19:30:55 +00:00
// updateCommand is used for updating parts of Git LFS that reside under
// .git/lfs.
func updateCommand(cmd *cobra.Command, args []string) {
if err := lfs.InstallHooks(updateForce); err != nil {
2015-09-08 16:20:52 +00:00
if lfs.IsInvalidRepoError(err) {
Print(err.Error())
os.Exit(128)
} else {
Error(err.Error())
Print("Run `git lfs update --force` to overwrite this hook.")
}
} else {
Print("Updated pre-push hook.")
}
lfsAccessRE := regexp.MustCompile(`\Alfs\.(.*)\.access\z`)
for key, value := range lfs.Config.AllGitConfig() {
matches := lfsAccessRE.FindStringSubmatch(key)
if len(matches) < 2 {
continue
}
switch value {
case "basic":
case "private":
git.Config.SetLocal("", key, "basic")
Print("Updated %s access from %s to %s.", matches[1], value, "basic")
default:
git.Config.UnsetLocalKey("", key)
Print("Removed invalid %s access of %s.", matches[1], value)
}
}
}
func init() {
updateCmd.Flags().BoolVarP(&updateForce, "force", "f", false, "Overwrite hooks.")
RootCmd.AddCommand(updateCmd)
}