Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions server/events/working_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (

const workingDirPrefix = "repos"

const prSourceRemote = "source"

var cloneLocks sync.Map
var recheckRequiredMap sync.Map

Expand Down Expand Up @@ -79,7 +81,7 @@ type FileWorkspace struct {
TestingOverrideBaseCloneURL string
// GithubAppEnabled is true and a PR number is supplied, we should fetch
// the ref "pull/PR_NUMBER/head" from the "origin" remote. If this is false,
// we fetch "+refs/heads/$HEAD_BRANCH" from the "head" remote.
// we fetch "+refs/heads/$HEAD_BRANCH" from the "<prSourceRemote>" remote.
GithubAppEnabled bool
// use the global setting without overriding
GpgNoSigningEnabled bool
Expand Down Expand Up @@ -195,7 +197,7 @@ func (w *FileWorkspace) recheckDiverged(logger logging.SimpleLogging, p models.P
"git", "remote", "set-url", "origin", p.BaseRepo.CloneURL,
},
{
"git", "remote", "set-url", "head", headRepo.CloneURL,
"git", "remote", "set-url", prSourceRemote, headRepo.CloneURL,
},
{
"git", "remote", "update",
Expand Down Expand Up @@ -257,7 +259,7 @@ func (w *FileWorkspace) remoteHasBranch(logger logging.SimpleLogging, c wrappedG

func (w *FileWorkspace) updateToRef(logger logging.SimpleLogging, c wrappedGitContext, targetRef string) error {

// We use both `head` and `origin` remotes, update them both
// We use both `<prSourceRemote>` and `origin` remotes, update them both
if err := w.wrappedGit(logger, c, "fetch", "--all"); err != nil {
return err
}
Expand Down Expand Up @@ -359,7 +361,7 @@ func (w *FileWorkspace) forceClone(logger logging.SimpleLogging, c wrappedGitCon
}
}

if err := w.wrappedGit(logger, c, "remote", "add", "head", headCloneURL); err != nil {
if err := w.wrappedGit(logger, c, "remote", "add", prSourceRemote, headCloneURL); err != nil {
return err
}
if w.GpgNoSigningEnabled {
Expand Down Expand Up @@ -415,7 +417,7 @@ func (w *FileWorkspace) wrappedGit(logger logging.SimpleLogging, c wrappedGitCon
// Merge the PR into the base branch.
func (w *FileWorkspace) mergeToBaseBranch(logger logging.SimpleLogging, c wrappedGitContext) error {
fetchRef := fmt.Sprintf("+refs/heads/%s:", c.pr.HeadBranch)
fetchRemote := "head"
fetchRemote := prSourceRemote
if w.GithubAppEnabled && c.pr.Num > 0 {
fetchRef = fmt.Sprintf("pull/%d/head:", c.pr.Num)
fetchRemote = "origin"
Expand Down
18 changes: 9 additions & 9 deletions server/events/working_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ func TestClone_ResetOnWrongCommitWithMergeStrategy(t *testing.T) {
runCmd(t, checkoutDir, "git", "config", "--local", "commit.gpgsign", "false")

runCmd(t, checkoutDir, "git", "checkout", "main")
runCmd(t, checkoutDir, "git", "remote", "add", "head", repoDir)
runCmd(t, checkoutDir, "git", "remote", "add", "source", repoDir)

// Simulate the merge strategy
runCmd(t, checkoutDir, "git", "checkout", "branch")
Expand Down Expand Up @@ -614,8 +614,8 @@ func TestClone_MasterHasDiverged(t *testing.T) {
firstPRDir := repoDir + "/first-pr"
runCmd(t, repoDir, "mkdir", "-p", "first-pr")
runCmd(t, firstPRDir, "git", "clone", "--branch", "main", "--single-branch", repoDir, ".")
runCmd(t, firstPRDir, "git", "remote", "add", "head", repoDir)
runCmd(t, firstPRDir, "git", "fetch", "head", "+refs/heads/first-pr")
runCmd(t, firstPRDir, "git", "remote", "add", "source", repoDir)
runCmd(t, firstPRDir, "git", "fetch", "source", "+refs/heads/first-pr")
runCmd(t, firstPRDir, "git", "config", "--local", "user.email", "atlantisbot@runatlantis.io")
runCmd(t, firstPRDir, "git", "config", "--local", "user.name", "atlantisbot")
runCmd(t, firstPRDir, "git", "config", "--local", "commit.gpgsign", "false")
Expand All @@ -632,8 +632,8 @@ func TestClone_MasterHasDiverged(t *testing.T) {
secondPRDir := repoDir + "/second-pr"
runCmd(t, repoDir, "mkdir", "-p", "second-pr")
runCmd(t, secondPRDir, "git", "clone", "--branch", "main", "--single-branch", repoDir, ".")
runCmd(t, secondPRDir, "git", "remote", "add", "head", repoDir)
runCmd(t, secondPRDir, "git", "fetch", "head", "+refs/heads/second-pr")
runCmd(t, secondPRDir, "git", "remote", "add", "source", repoDir)
runCmd(t, secondPRDir, "git", "fetch", "source", "+refs/heads/second-pr")
runCmd(t, secondPRDir, "git", "config", "--local", "user.email", "atlantisbot@runatlantis.io")
runCmd(t, secondPRDir, "git", "config", "--local", "user.name", "atlantisbot")
runCmd(t, secondPRDir, "git", "config", "--local", "commit.gpgsign", "false")
Expand Down Expand Up @@ -718,8 +718,8 @@ func TestHasDiverged_MasterHasDiverged(t *testing.T) {
firstPRDir := repoDir + "/first-pr"
runCmd(t, repoDir, "mkdir", "-p", "first-pr")
runCmd(t, firstPRDir, "git", "clone", "--branch", "main", "--single-branch", repoDir, ".")
runCmd(t, firstPRDir, "git", "remote", "add", "head", repoDir)
runCmd(t, firstPRDir, "git", "fetch", "head", "+refs/heads/first-pr")
runCmd(t, firstPRDir, "git", "remote", "add", "source", repoDir)
runCmd(t, firstPRDir, "git", "fetch", "source", "+refs/heads/first-pr")
runCmd(t, firstPRDir, "git", "config", "--local", "user.email", "atlantisbot@runatlantis.io")
runCmd(t, firstPRDir, "git", "config", "--local", "user.name", "atlantisbot")
runCmd(t, firstPRDir, "git", "config", "--local", "commit.gpgsign", "false")
Expand All @@ -736,8 +736,8 @@ func TestHasDiverged_MasterHasDiverged(t *testing.T) {
secondPRDir := repoDir + "/second-pr"
runCmd(t, repoDir, "mkdir", "-p", "second-pr")
runCmd(t, secondPRDir, "git", "clone", "--branch", "main", "--single-branch", repoDir, ".")
runCmd(t, secondPRDir, "git", "remote", "add", "head", repoDir)
runCmd(t, secondPRDir, "git", "fetch", "head", "+refs/heads/second-pr")
runCmd(t, secondPRDir, "git", "remote", "add", "source", repoDir)
runCmd(t, secondPRDir, "git", "fetch", "source", "+refs/heads/second-pr")
runCmd(t, secondPRDir, "git", "config", "--local", "user.email", "atlantisbot@runatlantis.io")
runCmd(t, secondPRDir, "git", "config", "--local", "user.name", "atlantisbot")
runCmd(t, secondPRDir, "git", "config", "--local", "commit.gpgsign", "false")
Expand Down
Loading