2014-06-03 15:08:58 +00:00
|
|
|
package commands
|
2014-03-19 18:08:38 +00:00
|
|
|
|
|
|
|
import (
|
2014-06-03 20:41:48 +00:00
|
|
|
"github.com/github/git-media/gitmedia"
|
2014-03-19 18:08:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type InitCommand struct {
|
|
|
|
*Command
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *InitCommand) Run() {
|
2014-06-03 20:41:48 +00:00
|
|
|
var sub string
|
|
|
|
if len(c.SubCommands) > 0 {
|
|
|
|
sub = c.SubCommands[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
switch sub {
|
|
|
|
case "hooks":
|
2014-06-05 18:48:23 +00:00
|
|
|
c.hookInit()
|
2014-06-03 20:41:48 +00:00
|
|
|
default:
|
|
|
|
c.runInit()
|
|
|
|
}
|
|
|
|
|
2014-06-05 18:19:30 +00:00
|
|
|
Print("git media initialized")
|
2014-06-03 20:41:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *InitCommand) runInit() {
|
|
|
|
c.globalInit()
|
2014-06-03 21:05:58 +00:00
|
|
|
if gitmedia.InRepo() {
|
2014-06-03 21:04:25 +00:00
|
|
|
c.hookInit()
|
2014-06-03 20:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *InitCommand) globalInit() {
|
2014-06-05 18:48:23 +00:00
|
|
|
if err := gitmedia.InstallFilters(); err != nil {
|
|
|
|
Error(err.Error())
|
|
|
|
}
|
2014-06-03 20:41:48 +00:00
|
|
|
}
|
2014-03-19 18:08:38 +00:00
|
|
|
|
2014-06-05 18:48:23 +00:00
|
|
|
func (c *InitCommand) hookInit() {
|
|
|
|
if err := gitmedia.InstallHooks(); err != nil {
|
|
|
|
Error(err.Error())
|
|
|
|
}
|
2014-06-03 20:41:48 +00:00
|
|
|
}
|
|
|
|
|
2014-03-19 18:08:38 +00:00
|
|
|
func init() {
|
|
|
|
registerCommand("init", func(c *Command) RunnableCommand {
|
|
|
|
return &InitCommand{Command: c}
|
|
|
|
})
|
|
|
|
}
|