-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgit_standalone_client.go
46 lines (39 loc) · 1.19 KB
/
git_standalone_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package utils
import (
"fmt"
"github.com/neel1996/gitconvex-server/global"
"os/exec"
"runtime"
"strings"
)
// Not used anymore from v2.1.0
func GetGitClient(targetPath string, args []string) exec.Cmd {
// Checking if git is installed and accessible from command line
var git string
var err error
logger := global.Logger{}
git, pathErr := exec.LookPath("git")
if pathErr != nil {
platform := runtime.GOOS
logger.Log(fmt.Sprintf("Git is not accessible --> %v", pathErr.Error()), global.StatusWarning)
if strings.Contains(platform, "windows") {
git, err = exec.LookPath("./gitclient.exe")
} else {
git, err = exec.LookPath("./gitclient")
}
if err != nil {
logger.Log(fmt.Sprintf("Standalone Git client is not available --> %v", err.Error()), global.StatusError)
} else {
logger.Log(fmt.Sprintf("Using the standlone git client from %s", git), global.StatusInfo)
}
} else {
logger.Log(fmt.Sprintf("Git is accessible from the commandline --> %v", git), global.StatusInfo)
}
cmdArgs := append([]string{git, "-C", targetPath}, args...)
cmd := exec.Cmd{
Path: git,
Args: cmdArgs,
}
logger.Log(fmt.Sprintf("Command --> %s", cmd.String()), global.StatusInfo)
return cmd
}