Skip to content

Commit

Permalink
fixed git subcommand to allow arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ethernetdan committed Jul 1, 2016
1 parent b9c7abc commit 86b531b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
39 changes: 19 additions & 20 deletions cli/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"os/exec"
"path/filepath"
"syscall"

"github.com/codegangsta/cli"
)
Expand All @@ -11,28 +12,26 @@ func (s SpreadCli) Git() *cli.Command {
return &cli.Command{
Name: "git",
Usage: "Allows access to git commands while Spread is build out",
Flags: []cli.Flag{
cli.StringFlag{
Name: "context",
Value: "",
Usage: "kubectl context to use for requests",
},
},
Action: func(c *cli.Context) {
proj := s.projectOrDie()
gitDir := filepath.Join(proj.Path, "git")
cli.ShowSubcommandHelp(c)
},
}
}

gitArgs := []string{"--git-dir=" + gitDir}
gitArgs = append(gitArgs, c.Args()...)
func (s SpreadCli) ExecGitCmd(args ...string) {
git, err := exec.LookPath("git")
if err != nil {
s.fatalf("Could not locate git: %v", err)
}

cmd := exec.Command("git", gitArgs...)
cmd.Stdin = s.in
cmd.Stdout = s.out
cmd.Stderr = s.err
err := cmd.Run()
if err != nil {
s.fatalf("could not run git: %v", err)
}
},
proj := s.projectOrDie()
gitDir := filepath.Join(proj.Path, "git")

gitArgs := []string{git, "--git-dir=" + gitDir}
gitArgs = append(gitArgs, args...)

err = syscall.Exec(git, gitArgs, []string{})
if err != nil {
s.fatalf("could not run git: %v", err)
}
}
5 changes: 5 additions & 0 deletions cmd/spread/spread.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ func main() {
wd, _ := os.Getwd()
spread := cli.NewSpreadCli(os.Stdin, os.Stdout, os.Stderr, Version, wd)

// git override
if len(os.Args) > 2 && os.Args[1] == "git" {
spread.ExecGitCmd(os.Args[2:]...)
}

app := app()
app.Commands = commands(spread)
app.Run(os.Args)
Expand Down

0 comments on commit 86b531b

Please sign in to comment.