diff --git a/db/AccessKey.go b/db/AccessKey.go index c24f2c01..9183b712 100644 --- a/db/AccessKey.go +++ b/db/AccessKey.go @@ -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() } diff --git a/db_lib/CmdGitClient.go b/db_lib/CmdGitClient.go index 8789c5d9..5ffa2fcd 100644 --- a/db_lib/CmdGitClient.go +++ b/db_lib/CmdGitClient.go @@ -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: diff --git a/db_lib/GoGitClient.go b/db_lib/GoGitClient.go index 8ef22f31..9a75a861 100644 --- a/db_lib/GoGitClient.go +++ b/db_lib/GoGitClient.go @@ -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 } diff --git a/util/config.go b/util/config.go index d2824c51..b190611e 100644 --- a/util/config.go +++ b/util/config.go @@ -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