git-lfs/commands/command_update.go
Taylor Blau 4593d0a641 vendor: vendor dependencies in vendor/ using Glide
- script/vendor received an update in order to work with Glide
- import paths have been rewritten to work with GO15VENDOREXPERIMENT
2016-05-23 12:10:35 -06:00

67 lines
1.6 KiB
Go

package commands
import (
"regexp"
"github.com/github/git-lfs/config"
"github.com/github/git-lfs/git"
"github.com/github/git-lfs/lfs"
"github.com/spf13/cobra"
)
var (
updateCmd = &cobra.Command{
Use: "update",
Run: updateCommand,
}
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) {
requireInRepo()
lfsAccessRE := regexp.MustCompile(`\Alfs\.(.*)\.access\z`)
for key, value := range config.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)
}
}
if updateForce && updateManual {
Exit("You cannot use --force and --manual options together")
}
if updateManual {
Print(lfs.GetHookInstallSteps())
} else {
if err := lfs.InstallHooks(updateForce); err != nil {
Error(err.Error())
Exit("To resolve this, either:\n 1: run `git lfs update --manual` for instructions on how to merge hooks.\n 2: run `git lfs update --force` to overwrite your hook.")
} else {
Print("Updated pre-push hook.")
}
}
}
func init() {
updateCmd.Flags().BoolVarP(&updateForce, "force", "f", false, "Overwrite existing hooks.")
updateCmd.Flags().BoolVarP(&updateManual, "manual", "m", false, "Print instructions for manual install.")
RootCmd.AddCommand(updateCmd)
}