@@ -3,8 +3,11 @@ package file
3
3
4
4
import (
5
5
"io"
6
+ "io/ioutil"
6
7
"os"
7
8
"os/exec"
9
+ "path/filepath"
10
+ "strings"
8
11
9
12
"gopkg.in/src-d/go-git.v4/plumbing/transport"
10
13
"gopkg.in/src-d/go-git.v4/plumbing/transport/internal/common"
@@ -30,6 +33,30 @@ func NewClient(uploadPackBin, receivePackBin string) transport.Transport {
30
33
})
31
34
}
32
35
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
+
33
60
func (r * runner ) Command (cmd string , ep transport.Endpoint , auth transport.AuthMethod ,
34
61
) (common.Command , error ) {
35
62
@@ -40,7 +67,17 @@ func (r *runner) Command(cmd string, ep transport.Endpoint, auth transport.AuthM
40
67
cmd = r .ReceivePackBin
41
68
}
42
69
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
44
81
}
45
82
46
83
type command struct {
0 commit comments