diff --git a/commands/command_init.go b/commands/command_init.go index 0716c61a..a09aa751 100644 --- a/commands/command_init.go +++ b/commands/command_init.go @@ -21,11 +21,10 @@ func (c *InitCommand) Run() { switch sub { case "hooks": - if !inRepo() { - fmt.Println("Not in a repository") + if err := c.hookInit(); err != nil { + fmt.Println(err) return } - c.hookInit() default: c.runInit() } @@ -36,7 +35,7 @@ func (c *InitCommand) Run() { func (c *InitCommand) runInit() { c.globalInit() if inRepo() { - c.repoInit() + c.hookInit() } } @@ -46,11 +45,8 @@ func (c *InitCommand) globalInit() { requireFilters() } -func (c *InitCommand) repoInit() { - c.hookInit() -} - -func (c *InitCommand) hookInit() { +func (c *InitCommand) hookInit() error { + return gitmedia.InstallHooks() } func inRepo() bool { diff --git a/gitmedia/gitmedia.go b/gitmedia/gitmedia.go index a325cab8..f5a78c8c 100644 --- a/gitmedia/gitmedia.go +++ b/gitmedia/gitmedia.go @@ -1,6 +1,7 @@ package gitmedia import ( + "errors" "fmt" "io/ioutil" "os" @@ -62,6 +63,14 @@ func Environ() []string { return env } +func InstallHooks() error { + if LocalWorkingDir == "" { + return errors.New("Not in a repository") + } + + return nil +} + func init() { var err error LocalWorkingDir, LocalGitDir, err = resolveGitDir()