Simplify in-repo init, move hook instalation under gitmedia package
This commit is contained in:
parent
e3be932255
commit
5d44b534ca
@ -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 {
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user