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

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: #527
  • Loading branch information
strib committed Aug 2, 2017
1 parent 93e6e73 commit eb6d4ed
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 48 deletions.
39 changes: 38 additions & 1 deletion plumbing/transport/file/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package file

import (
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"

"gopkg.in/src-d/go-git.v4/plumbing/transport"
"gopkg.in/src-d/go-git.v4/plumbing/transport/internal/common"
Expand All @@ -30,6 +33,30 @@ 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
}
execPathBytes, err := ioutil.ReadAll(stdout)
if err != nil {
return "", err
}
execPath := string(execPathBytes)
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 +67,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 eb6d4ed

Please sign in to comment.