Skip to content

Commit f064a5d

Browse files
committed
Revert "Remove sysexec since Windows doesn't support it…:-("
This reverts commit d527efb.
1 parent 8f0a220 commit f064a5d

File tree

5 files changed

+40
-8
lines changed

5 files changed

+40
-8
lines changed

cmd/cmd.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"os/exec"
77
"strings"
8+
"syscall"
89
)
910

1011
type Cmd struct {
@@ -52,6 +53,20 @@ func (cmd *Cmd) Exec() error {
5253
return c.Run()
5354
}
5455

56+
func (cmd *Cmd) SysExec() error {
57+
binary, lookErr := exec.LookPath(cmd.Name)
58+
if lookErr != nil {
59+
return fmt.Errorf("command not found: %s", cmd.Name)
60+
}
61+
62+
args := []string{cmd.Name}
63+
args = append(args, cmd.Args...)
64+
65+
env := os.Environ()
66+
67+
return syscall.Exec(binary, args, env)
68+
}
69+
5570
func New(name string) *Cmd {
5671
return &Cmd{Name: name, Args: make([]string, 0)}
5772
}

commands/browse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ func browse(command *Command, args *Args) {
6464
utils.Check(err)
6565
}
6666

67-
args.Replace(launcher[0], "", launcher[1:]...)
67+
args.Replace(launcher[0], "", launcher[1:]...)
6868
args.AppendParams(url)
6969
}

commands/runner.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (r *Runner) Execute() error {
5454
}
5555
}
5656

57-
return git.Spawn(args.Command, args.Params...)
57+
return git.SysExec(args.Command, args.Params...)
5858
}
5959

6060
func slurpGlobalFlags(args *Args) {
@@ -73,8 +73,15 @@ func printCommands(cmds []*cmd.Cmd) {
7373
}
7474

7575
func executeCommands(cmds []*cmd.Cmd) error {
76-
for _, c := range cmds {
77-
err := c.Exec()
76+
length := len(cmds)
77+
for i, c := range cmds {
78+
var err error
79+
if i == (length - 1) {
80+
err = c.SysExec()
81+
} else {
82+
err = c.Exec()
83+
}
84+
7885
if err != nil {
7986
return err
8087
}

git/git.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ func Config(name string) (string, error) {
116116
return output[0], nil
117117
}
118118

119+
func SysExec(command string, args ...string) error {
120+
cmd := cmd.New("git")
121+
cmd.WithArg(command)
122+
for _, a := range args {
123+
cmd.WithArg(a)
124+
}
125+
126+
return cmd.SysExec()
127+
}
128+
119129
func Spawn(command string, args ...string) error {
120130
cmd := cmd.New("git")
121131
cmd.WithArg(command)

github/github.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (gh *GitHub) CreateRepository(project Project, description, homepage string
5959

6060
func (gh *GitHub) CreatePullRequestForIssue(base, head, issue string) (string, error) {
6161
client := gh.client()
62-
params := octokat.PullRequestForIssueParams{Base: base, Head: head, Issue: issue}
62+
params := octokat.PullRequestForIssueParams{Base: base, Head: head, Issue: issue}
6363
pullRequest, err := client.CreatePullRequestForIssue(gh.repo(), params)
6464
if err != nil {
6565
return "", err
@@ -85,14 +85,14 @@ func (gh *GitHub) CiStatus(sha string) (*octokat.Status, error) {
8585
func (gh *GitHub) ForkRepository(name, owner string, noRemote bool) (repo *octokat.Repository, err error) {
8686
client := gh.client()
8787
config := gh.Config
88-
repo, err = client.Repository(octokat.Repo{Name: name, UserName: config.User})
88+
repo, err = client.Repository(octokat.Repo{Name: name, UserName: config.User})
8989
if repo != nil && err == nil {
9090
msg := fmt.Sprintf("Error creating fork: %s exists on %s", repo.FullName, GitHubHost)
9191
err = errors.New(msg)
9292
return
9393
}
9494

95-
repo, err = client.Fork(octokat.Repo{Name: name, UserName: owner}, nil)
95+
repo, err = client.Fork(octokat.Repo{Name: name, UserName: owner}, nil)
9696

9797
return
9898
}
@@ -109,7 +109,7 @@ func (gh *GitHub) ExpandRemoteUrl(owner, name string, isSSH bool) (url string) {
109109

110110
func (gh *GitHub) repo() octokat.Repo {
111111
project := gh.Project
112-
return octokat.Repo{Name: project.Name, UserName: project.Owner}
112+
return octokat.Repo{Name: project.Name, UserName: project.Owner}
113113
}
114114

115115
func findOrCreateToken(user, password string) (string, error) {

0 commit comments

Comments
 (0)