mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 07:19:20 +01:00
refactor(git): move GIT env args for the method
This commit is contained in:
parent
f882d20b0a
commit
4836b189a0
@ -78,7 +78,23 @@ type AccessKeyInstallation struct {
|
||||
Script string
|
||||
}
|
||||
|
||||
func (key AccessKeyInstallation) Destroy() error {
|
||||
func (key *AccessKeyInstallation) GetGitEnv() (env []string) {
|
||||
env = make([]string, 0)
|
||||
|
||||
env = append(env, fmt.Sprintln("GIT_TERMINAL_PROMPT=0"))
|
||||
if key.SSHAgent != nil {
|
||||
env = append(env, fmt.Sprintf("SSH_AUTH_SOCK=%s", key.SSHAgent.SocketFile))
|
||||
sshCmd := "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
|
||||
if util.Config.SshConfigPath != "" {
|
||||
sshCmd += " -F " + util.Config.SshConfigPath
|
||||
}
|
||||
env = append(env, fmt.Sprintf("GIT_SSH_COMMAND=%s", sshCmd))
|
||||
}
|
||||
|
||||
return env
|
||||
}
|
||||
|
||||
func (key *AccessKeyInstallation) Destroy() error {
|
||||
if key.SSHAgent != nil {
|
||||
return key.SSHAgent.Close()
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package db_lib
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
@ -17,16 +16,7 @@ type CmdGitClient struct {
|
||||
func (c CmdGitClient) makeCmd(r GitRepository, targetDir GitRepositoryDirType, args ...string) *exec.Cmd {
|
||||
cmd := exec.Command("git") //nolint: gas
|
||||
|
||||
cmd.Env = os.Environ()
|
||||
cmd.Env = append(cmd.Env, fmt.Sprintln("GIT_TERMINAL_PROMPT=0"))
|
||||
if r.Repository.SSHKey.Type == db.AccessKeySSH {
|
||||
cmd.Env = append(cmd.Env, fmt.Sprintf("SSH_AUTH_SOCK=%s", c.keyInstallation.SSHAgent.SocketFile))
|
||||
sshCmd := "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
|
||||
if util.Config.SshConfigPath != "" {
|
||||
sshCmd += " -F " + util.Config.SshConfigPath
|
||||
}
|
||||
cmd.Env = append(cmd.Env, fmt.Sprintf("GIT_SSH_COMMAND=%s", sshCmd))
|
||||
}
|
||||
cmd.Env = append(getEnvironmentVars(), c.keyInstallation.GetGitEnv()...)
|
||||
|
||||
switch targetDir {
|
||||
case GitRepositoryTmpPath:
|
||||
|
@ -3,9 +3,6 @@ package db_lib
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/semaphoreui/semaphore/db"
|
||||
"github.com/semaphoreui/semaphore/pkg/task_logger"
|
||||
"github.com/semaphoreui/semaphore/util"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/config"
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
@ -13,6 +10,9 @@ import (
|
||||
"github.com/go-git/go-git/v5/plumbing/transport/http"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
|
||||
"github.com/go-git/go-git/v5/storage/memory"
|
||||
"github.com/semaphoreui/semaphore/db"
|
||||
"github.com/semaphoreui/semaphore/pkg/task_logger"
|
||||
"github.com/semaphoreui/semaphore/util"
|
||||
|
||||
ssh2 "golang.org/x/crypto/ssh"
|
||||
)
|
||||
@ -119,9 +119,9 @@ func (c GoGitClient) Pull(r GitRepository) error {
|
||||
}
|
||||
|
||||
// Pull the latest changes from the origin remote and merge into the current branch
|
||||
err = wt.Pull(&git.PullOptions{RemoteName: "origin",
|
||||
Auth: authMethod,
|
||||
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth})
|
||||
err = wt.Pull(&git.PullOptions{RemoteName: "origin",
|
||||
Auth: authMethod,
|
||||
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth})
|
||||
if err != nil && err != git.NoErrAlreadyUpToDate {
|
||||
r.Logger.Log("Unable to pull latest changes")
|
||||
return err
|
||||
@ -167,7 +167,7 @@ func (c GoGitClient) CanBePulled(r GitRepository) bool {
|
||||
Auth: authMethod,
|
||||
})
|
||||
|
||||
if err != nil && err != git.NoErrAlreadyUpToDate {
|
||||
if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -865,16 +865,6 @@ func LookupDefaultApps() {
|
||||
}
|
||||
}
|
||||
|
||||
func PrintDebug() {
|
||||
envs := os.Environ()
|
||||
for _, e := range envs {
|
||||
fmt.Println(e)
|
||||
}
|
||||
|
||||
b, _ := Config.ToJSON()
|
||||
fmt.Println(string(b))
|
||||
}
|
||||
|
||||
func GetPublicAliasURL(scope string, alias string) string {
|
||||
aliasURL := Config.WebHost
|
||||
port := Config.Port
|
||||
|
Loading…
Reference in New Issue
Block a user