Skip to content

Commit 93e6e73

Browse files
committed
plumbing: fix pack commands for the file client on Windows
The default git install on Windows doesn't come with separate commands for receive-pack and upload-pack.
1 parent 63b30fb commit 93e6e73

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

plumbing/transport/file/client.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ func (r *runner) Command(cmd string, ep transport.Endpoint, auth transport.AuthM
4040
cmd = r.ReceivePackBin
4141
}
4242

43-
if _, err := exec.LookPath(cmd); err != nil {
44-
return nil, err
45-
}
46-
47-
return &command{cmd: exec.Command(cmd, ep.Path())}, nil
43+
return makeCommand(cmd, ep)
4844
}
4945

5046
type command struct {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// +build !windows
2+
3+
package file
4+
5+
import (
6+
"os/exec"
7+
8+
"gopkg.in/src-d/go-git.v4/plumbing/transport"
9+
"gopkg.in/src-d/go-git.v4/plumbing/transport/internal/common"
10+
)
11+
12+
func makeCommand(cmd string, ep transport.Endpoint) (common.Command, error) {
13+
if _, err := exec.LookPath(cmd); err != nil {
14+
return nil, err
15+
}
16+
17+
return &command{cmd: exec.Command(cmd, ep.Path())}, nil
18+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// +build windows
2+
3+
package file
4+
5+
import (
6+
"os/exec"
7+
"strings"
8+
9+
"gopkg.in/src-d/go-git.v4/plumbing/transport"
10+
"gopkg.in/src-d/go-git.v4/plumbing/transport/internal/common"
11+
)
12+
13+
// In the default Windows git install, there is no separate
14+
// git-upload-pack or git-receive-pack binaries; we must use "git
15+
// upload-pack" and "git receive-pack" instead.
16+
func makeCommand(cmd string, ep transport.Endpoint) (common.Command, error) {
17+
var subcommands []string
18+
if strings.HasPrefix(cmd, "git-") {
19+
subcommands = strings.SplitN(cmd, "-", 2)
20+
cmd = subcommands[0]
21+
}
22+
23+
if _, err := exec.LookPath(cmd); err != nil {
24+
return nil, err
25+
}
26+
27+
return &command{cmd: exec.Command(
28+
cmd, append(subcommands[1:], ep.Path())...)}, nil
29+
}

0 commit comments

Comments
 (0)