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

Commit 3af2b9d

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

File tree

3 files changed

+34
-48
lines changed

3 files changed

+34
-48
lines changed

plumbing/transport/file/client.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@ func NewClient(uploadPackBin, receivePackBin string) transport.Transport {
3030
})
3131
}
3232

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

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

43-
return makeCommand(cmd, ep)
66+
_, err := exec.LookPath(cmd)
67+
if err != nil {
68+
if e, ok := err.(*exec.Error); ok && e.Err == exec.ErrNotFound {
69+
cmd, err = prefixExecPath(cmd)
70+
if err != nil {
71+
return nil, err
72+
}
73+
}
74+
}
75+
76+
return &command{cmd: exec.Command(cmd, ep.Path())}, nil
4477
}
4578

4679
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)