Skip to content

Conversation

@lukemassa
Copy link
Contributor

what

Make it so that, if we attempt to reuse the clone directory but run into some error, fall back to forcing the clone.

why

There are some subtle bugs when it comes to reusing the clone directory (example #6009, #6000). When I wrote the code (#5895) I was hoping it would be "good enough", but now I'm thinking that if something does go wrong, it's probably best to fallback to the known good path, and log an error.

tests

I added a unit test, and also ran this code on a branch before #6010 and watched it bypass the problem:

{"level":"info","ts":"2025-12-06T14:04:58.026-0500","caller":"events/working_dir.go:141","msg":"repo was already cloned but branch is not at correct commit, updating to \"a81b4d45a8d7a9b5920bf7456de0bbfd7d04c1db\"","json":{"repo":"lukemassa/atlantis-test","pull":"38"}}
{"level":"error","ts":"2025-12-06T14:04:59.278-0500","caller":"events/working_dir.go:111","msg":"An error occurred attempting to reuse the clone dir, falling back to forced clone. This is likely a bug please report: post-merge verification failed: HEAD^2 != a81b4d45a8d7a9b5920bf7456de0bbfd7d04c1db"
...
{"level":"info","ts":"2025-12-06T14:04:59.287-0500","caller":"events/working_dir.go:346","msg":"creating dir '/Users/lmassa/.atlantis/repos/lukemassa/atlantis-test/38/default'","json":{"repo":"lukemassa/atlantis-test","pull":"38"}}

references

Addresses an issue in: #5895
Would have prevented: #6000, #6009

@dosubot dosubot bot added bug Something isn't working go Pull requests that update Go code labels Dec 6, 2025
// - (false, err) → an unexpected error occurred; caller should log the error and force clone
func (w *FileWorkspace) attemptReuseCloneDir(logger logging.SimpleLogging, c wrappedGitContext, cloneDir string) (bool, error) {
// If the directory doesn't exist yet, surely we can't reuse it
if _, err := os.Stat(cloneDir); err != nil {

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.
This path depends on a
user-provided value
.
This path depends on a
user-provided value
.
This path depends on a
user-provided value
.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't introduce this variable I just moved it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant