2014-06-03 15:08:58 +00:00
|
|
|
package commands
|
2014-03-19 18:08:38 +00:00
|
|
|
|
|
|
|
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-03-19 18:08:38 +00:00
|
|
|
)
|
|
|
|
|
2014-06-26 20:15:21 +00:00
|
|
|
var (
|
|
|
|
initCmd = &cobra.Command{
|
2015-09-17 22:08:28 +00:00
|
|
|
Use: "init",
|
|
|
|
Run: initCommand,
|
2014-06-26 20:15:21 +00:00
|
|
|
}
|
2014-03-19 18:08:38 +00:00
|
|
|
|
2014-06-26 21:32:32 +00:00
|
|
|
initHooksCmd = &cobra.Command{
|
2015-09-17 22:08:28 +00:00
|
|
|
Use: "hooks",
|
|
|
|
Run: initHooksCommand,
|
2014-06-03 20:41:48 +00:00
|
|
|
}
|
2015-07-06 23:10:47 +00:00
|
|
|
|
|
|
|
forceInit = false
|
2015-09-23 17:58:16 +00:00
|
|
|
localInit = false
|
2015-09-23 18:20:30 +00:00
|
|
|
passInit = false
|
2014-06-26 21:32:32 +00:00
|
|
|
)
|
2014-06-03 20:41:48 +00:00
|
|
|
|
2014-06-26 21:32:32 +00:00
|
|
|
func initCommand(cmd *cobra.Command, args []string) {
|
2015-09-23 17:58:16 +00:00
|
|
|
if localInit {
|
|
|
|
requireInRepo()
|
|
|
|
}
|
|
|
|
|
|
|
|
opt := lfs.InstallOptions{Force: forceInit, Local: localInit}
|
2015-09-23 18:20:30 +00:00
|
|
|
if passInit {
|
|
|
|
// assume the user is changing their smudge mode, so enable force implicitly
|
|
|
|
opt.Force = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := lfs.InstallFilters(opt, passInit); 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.")
|
2014-06-03 20:41:48 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 22:35:04 +00:00
|
|
|
initHooksCommand(cmd, args)
|
2015-08-13 23:13:00 +00:00
|
|
|
Print("Git LFS initialized.")
|
2014-06-03 20:41:48 +00:00
|
|
|
}
|
2014-03-19 18:08:38 +00:00
|
|
|
|
2014-06-26 21:32:32 +00:00
|
|
|
func initHooksCommand(cmd *cobra.Command, args []string) {
|
2015-08-13 23:13:00 +00:00
|
|
|
updateForce = forceInit
|
|
|
|
updateCommand(cmd, args)
|
2014-06-03 20:41:48 +00:00
|
|
|
}
|
|
|
|
|
2014-03-19 18:08:38 +00:00
|
|
|
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.")
|
2015-09-23 17:58:16 +00:00
|
|
|
initCmd.Flags().BoolVarP(&localInit, "local", "l", false, "Set the Git LFS config for the local Git repository only.")
|
2015-09-23 18:20:30 +00:00
|
|
|
initCmd.Flags().BoolVarP(&passInit, "smudge-passthrough", "", false, "Skips automatic downloading of objects on clone or pull.")
|
2014-06-26 21:32:32 +00:00
|
|
|
initCmd.AddCommand(initHooksCmd)
|
2014-06-26 20:15:21 +00:00
|
|
|
RootCmd.AddCommand(initCmd)
|
2014-03-19 18:08:38 +00:00
|
|
|
}
|