git-lfs/commands/command_init.go
Rick Olson 5b7990ce92 teach the init command how to update pre-push hooks with force
This reuses the update command completely.
2015-08-13 17:13:00 -06:00

47 lines
1013 B
Go

package commands
import (
"github.com/github/git-lfs/lfs"
"github.com/github/git-lfs/vendor/_nuts/github.com/spf13/cobra"
)
var (
initCmd = &cobra.Command{
Use: "init",
Short: "Initialize the default Git LFS configuration",
Run: initCommand,
}
initHooksCmd = &cobra.Command{
Use: "hooks",
Short: "Initialize hooks for the current repository",
Run: initHooksCommand,
}
forceInit = false
)
func initCommand(cmd *cobra.Command, args []string) {
if err := lfs.InstallFilters(forceInit); err != nil {
Error(err.Error())
Exit("Run `git lfs init --force` to reset git config.")
}
if lfs.InRepo() {
initHooksCommand(cmd, args)
}
Print("Git LFS initialized.")
}
func initHooksCommand(cmd *cobra.Command, args []string) {
updateForce = forceInit
updateCommand(cmd, args)
}
func init() {
initCmd.Flags().BoolVarP(&forceInit, "force", "f", false, "Set the Git LFS global config, overwriting previous values.")
initCmd.AddCommand(initHooksCmd)
RootCmd.AddCommand(initCmd)
}