git-lfs/commands/command_init.go

47 lines
1013 B
Go
Raw Normal View History

package commands
import (
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"
)
2014-06-26 20:15:21 +00:00
var (
initCmd = &cobra.Command{
Use: "init",
Short: "Initialize the default Git LFS configuration",
2014-06-26 20:15:21 +00:00
Run: initCommand,
}
2014-06-26 21:32:32 +00:00
initHooksCmd = &cobra.Command{
Use: "hooks",
Short: "Initialize hooks for the current repository",
Run: initHooksCommand,
}
2015-07-06 23:10:47 +00:00
forceInit = false
2014-06-26 21:32:32 +00:00
)
2014-06-26 21:32:32 +00:00
func initCommand(cmd *cobra.Command, args []string) {
2015-07-06 23:10:47 +00:00
if err := lfs.InstallFilters(forceInit); err != nil {
2014-06-26 21:32:32 +00:00
Error(err.Error())
2015-07-06 23:10:47 +00:00
Exit("Run `git lfs init --force` to reset git config.")
}
2015-03-19 19:30:55 +00:00
if lfs.InRepo() {
2014-06-26 21:32:32 +00:00
initHooksCommand(cmd, args)
}
Print("Git LFS initialized.")
}
2014-06-26 21:32:32 +00:00
func initHooksCommand(cmd *cobra.Command, args []string) {
updateForce = forceInit
updateCommand(cmd, args)
}
func init() {
2015-07-06 23:10:47 +00:00
initCmd.Flags().BoolVarP(&forceInit, "force", "f", false, "Set the Git LFS global config, overwriting previous values.")
2014-06-26 21:32:32 +00:00
initCmd.AddCommand(initHooksCmd)
2014-06-26 20:15:21 +00:00
RootCmd.AddCommand(initCmd)
}