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-06-26 20:15:21 +00:00
|
|
|
"github.com/spf13/cobra"
|
2014-03-19 18:08:38 +00:00
|
|
|
)
|
|
|
|
|
2014-06-26 20:15:21 +00:00
|
|
|
var (
|
|
|
|
initCmd = &cobra.Command{
|
|
|
|
Use: "init",
|
2014-06-26 21:22:24 +00:00
|
|
|
Short: "Initialize the default Git Media configuration",
|
2014-06-26 20:15:21 +00:00
|
|
|
Run: initCommand,
|
|
|
|
}
|
2014-03-19 18:08:38 +00:00
|
|
|
|
2014-06-26 21:32:32 +00:00
|
|
|
initHooksCmd = &cobra.Command{
|
|
|
|
Use: "hooks",
|
|
|
|
Short: "Initialize hooks for the current repository",
|
|
|
|
Run: initHooksCommand,
|
2014-06-03 20:41:48 +00:00
|
|
|
}
|
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) {
|
|
|
|
if err := gitmedia.InstallFilters(); err != nil {
|
|
|
|
Error(err.Error())
|
2014-06-03 20:41:48 +00:00
|
|
|
}
|
|
|
|
|
2014-06-03 21:05:58 +00:00
|
|
|
if gitmedia.InRepo() {
|
2014-06-26 21:32:32 +00:00
|
|
|
initHooksCommand(cmd, args)
|
2014-06-03 20:41:48 +00:00
|
|
|
}
|
|
|
|
|
2015-01-30 15:41:03 +00:00
|
|
|
Print("git hawser 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) {
|
2014-09-23 21:42:47 +00:00
|
|
|
if err := gitmedia.InstallHooks(false); err != nil {
|
2014-06-05 18:48:23 +00:00
|
|
|
Error(err.Error())
|
|
|
|
}
|
2014-06-03 20:41:48 +00:00
|
|
|
}
|
|
|
|
|
2014-03-19 18:08:38 +00:00
|
|
|
func init() {
|
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
|
|
|
}
|