Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit eb6d4ed

Browse files
committed
plumbing: use --exec-path to find pack executables
Suggested by smola. Issue: #527
1 parent 93e6e73 commit eb6d4ed

File tree

3 files changed

+38
-48
lines changed

3 files changed

+38
-48
lines changed

plumbing/transport/file/client.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ package file
33

44
import (
55
"io"
6+
"io/ioutil"
67
"os"
78
"os/exec"
9+
"path/filepath"
10+
"strings"
811

912
"gopkg.in/src-d/go-git.v4/plumbing/transport"
1013
"gopkg.in/src-d/go-git.v4/plumbing/transport/internal/common"
@@ -30,6 +33,30 @@ func NewClient(uploadPackBin, receivePackBin string) transport.Transport {
3033
})
3134
}
3235

36+
func prefixExecPath(cmd string) (string, error) {
37+
// Use `git --exec-path` to find the exec path.
38+
execCmd := &command{cmd: exec.Command("git", "--exec-path")}
39+
err := execCmd.Start()
40+
if err != nil {
41+
return "", err
42+
}
43+
err = execCmd.Close()
44+
if err != nil {
45+
return "", err
46+
}
47+
stdout, err := execCmd.StdoutPipe()
48+
if err != nil {
49+
return "", err
50+
}
51+
execPathBytes, err := ioutil.ReadAll(stdout)
52+
if err != nil {
53+
return "", err
54+
}
55+
execPath := string(execPathBytes)
56+
execPath = strings.TrimSpace(execPath)
57+
return filepath.Join(execPath, cmd), nil
58+
}
59+
3360
func (r *runner) Command(cmd string, ep transport.Endpoint, auth transport.AuthMethod,
3461
) (common.Command, error) {
3562

@@ -40,7 +67,17 @@ func (r *runner) Command(cmd string, ep transport.Endpoint, auth transport.AuthM
4067
cmd = r.ReceivePackBin
4168
}
4269

43-
return makeCommand(cmd, ep)
70+
_, err := exec.LookPath(cmd)
71+
if err != nil {
72+
if e, ok := err.(*exec.Error); ok && e.Err == exec.ErrNotFound {
73+
cmd, err = prefixExecPath(cmd)
74+
if err != nil {
75+
return nil, err
76+
}
77+
}
78+
}
79+
80+
return &command{cmd: exec.Command(cmd, ep.Path())}, nil
4481
}
4582

4683
type command struct {

plumbing/transport/file/client_cmd_unix.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

plumbing/transport/file/client_cmd_windows.go

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)