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 {
|
switch sub {
|
||||||
case "hooks":
|
case "hooks":
|
||||||
if !inRepo() {
|
if err := c.hookInit(); err != nil {
|
||||||
fmt.Println("Not in a repository")
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.hookInit()
|
|
||||||
default:
|
default:
|
||||||
c.runInit()
|
c.runInit()
|
||||||
}
|
}
|
||||||
@ -36,7 +35,7 @@ func (c *InitCommand) Run() {
|
|||||||
func (c *InitCommand) runInit() {
|
func (c *InitCommand) runInit() {
|
||||||
c.globalInit()
|
c.globalInit()
|
||||||
if inRepo() {
|
if inRepo() {
|
||||||
c.repoInit()
|
c.hookInit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,11 +45,8 @@ func (c *InitCommand) globalInit() {
|
|||||||
requireFilters()
|
requireFilters()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *InitCommand) repoInit() {
|
func (c *InitCommand) hookInit() error {
|
||||||
c.hookInit()
|
return gitmedia.InstallHooks()
|
||||||
}
|
|
||||||
|
|
||||||
func (c *InitCommand) hookInit() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func inRepo() bool {
|
func inRepo() bool {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package gitmedia
|
package gitmedia
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@ -62,6 +63,14 @@ func Environ() []string {
|
|||||||
return env
|
return env
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InstallHooks() error {
|
||||||
|
if LocalWorkingDir == "" {
|
||||||
|
return errors.New("Not in a repository")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var err error
|
var err error
|
||||||
LocalWorkingDir, LocalGitDir, err = resolveGitDir()
|
LocalWorkingDir, LocalGitDir, err = resolveGitDir()
|
||||||
|
Loading…
Reference in New Issue
Block a user