Skip to content

Commit

Permalink
plumbing: use --exec-path to find pack executables
Browse files Browse the repository at this point in the history
Suggested by smola.

Issue: src-d#527
  • Loading branch information
strib committed Aug 2, 2017
1 parent 93e6e73 commit 3af2b9d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 48 deletions.
35 changes: 34 additions & 1 deletion plumbing/transport/file/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,29 @@ func NewClient(uploadPackBin, receivePackBin string) transport.Transport {
})
}

func prefixExecPath(cmd string) (string, error) {
// Use `git --exec-path` to find the exec path.
execCmd := &command{cmd: exec.Command("git", "--exec-path")}
err = execCmd.Start()
if err != nil {
return "", err
}
err = execCmd.Close()
if err != nil {
return "", err
}
stdout, err := execCmd.StdoutPipe()
if err != nil {
return "", err
}
execPath, err := ioutil.ReadAll(stdout)
if err != nil {
return "", err
}
execPath = strings.TrimSpace(execPath)
return filepath.Join(execPath, cmd), nil
}

func (r *runner) Command(cmd string, ep transport.Endpoint, auth transport.AuthMethod,
) (common.Command, error) {

Expand All @@ -40,7 +63,17 @@ func (r *runner) Command(cmd string, ep transport.Endpoint, auth transport.AuthM
cmd = r.ReceivePackBin
}

return makeCommand(cmd, ep)
_, err := exec.LookPath(cmd)
if err != nil {
if e, ok := err.(*exec.Error); ok && e.Err == exec.ErrNotFound {
cmd, err = prefixExecPath(cmd)
if err != nil {
return nil, err
}
}
}

return &command{cmd: exec.Command(cmd, ep.Path())}, nil
}

type command struct {
Expand Down
18 changes: 0 additions & 18 deletions plumbing/transport/file/client_cmd_unix.go

This file was deleted.

29 changes: 0 additions & 29 deletions plumbing/transport/file/client_cmd_windows.go

This file was deleted.

0 comments on commit 3af2b9d

Please sign in to comment.