Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Workspace Error when include-git-untracked-files is true #5288

Merged

Conversation

X-Guardian
Copy link
Contributor

what

In the project_command_builder buildAllCommandsByCfg function, move the p.IncludeGitUntrackedFiles condition to after p.WorkingDir.Clone and only call p.shouldSkipClone if p.IncludeGitUntrackedFiles is false.

why

Fixes an issue when include-git-untracked-files is true and the branch for a PR has not yet been cloned, the following error will occur during a plan:

checking if workspace exists: stat <directory>: no such file or directory

tests

Logs

Before
{"level":"debug","ts":"2025-02-01T13:22:54.939Z","caller":"vcs/gitlab_client.go:123","msg":"Getting modified files for GitLab merge request 31","json":{"repo":"sheather/test","pull":"31"}}
{"level":"debug","ts":"2025-02-01T13:22:55.796Z","caller":"vcs/gitlab_client.go:144","msg":"GET projects/sheather%2Ftest/merge_requests/31/changes returned: 200","json":{"repo":"sheather/test","pull":"31"}}
{"level":"debug","ts":"2025-02-01T13:22:55.796Z","caller":"events/project_command_builder.go:459","msg":"'include-git-untracked-files' option is set, getting untracked files","json":{"repo":"sheather/test","pull":"31"}}
{"level":"error","ts":"2025-02-01T13:22:55.796Z","caller":"events/instrumented_project_command_builder.go:75","msg":"Error building plan commands: checking if workspace exists: stat /root/.atlantis/repos/sheather/test/31/default: no such file or directory","json":{},"stacktrace":"github.com/runatlantis/atlantis/server/events.(*InstrumentedProjectCommandBuilder).buildAndEmitStats\n\t/mnt/c/Users/Simon/Documents/GitHub/X-Guardian/atlantis/server/events/instrumented_project_command_builder.go:75\ngithub.yoyoweb123.workers.dev/runatlantis/atlantis/server/events.(*InstrumentedProjectCommandBuilder).BuildPlanCommands\n\t/mnt/c/Users/Simon/Documents/GitHub/X-Guardian/atlantis/server/events/instrumented_project_command_builder.go:35\ngithub.yoyoweb123.workers.dev/runatlantis/atlantis/server/events.(*PlanCommandRunner).run\n\t/mnt/c/Users/Simon/Documents/GitHub/X-Guardian/atlantis/server/events/plan_command_runner.go:195\ngithub.yoyoweb123.workers.dev/runatlantis/atlantis/server/events.(*PlanCommandRunner).Run\n\t/mnt/c/Users/Simon/Documents/GitHub/X-Guardian/atlantis/server/events/plan_command_runner.go:307\ngithub.yoyoweb123.workers.dev/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunCommentCommand\n\t/mnt/c/Users/Simon/Documents/GitHub/X-Guardian/atlantis/server/events/command_runner.go:383"}
{"level":"info","ts":"2025-02-01T13:22:55.796Z","caller":"vcs/gitlab_client.go:411","msg":"Updating GitLab commit status for 'atlantis/plan' to 'failed'","json":{"repo":"sheather/test","pull":"31"}}
After
{"level":"debug","ts":"2025-02-01T13:27:40.488Z","caller":"vcs/gitlab_client.go:123","msg":"Getting modified files for GitLab merge request 31","json":{"repo":"sheather/test","pull":"31"}}
{"level":"debug","ts":"2025-02-01T13:27:41.686Z","caller":"vcs/gitlab_client.go:144","msg":"GET projects/sheather%2Ftest/merge_requests/31/changes returned: 200","json":{"repo":"sheather/test","pull":"31"}}
{"level":"debug","ts":"2025-02-01T13:27:41.686Z","caller":"events/project_command_builder.go:458","msg":"1 files were modified in this pull request. Modified files: [live/aws/123456789012/develop/eu-west-2/stack11/main.tf]","json":{"repo":"sheather/test","pull":"31"}}
{"level":"debug","ts":"2025-02-01T13:27:41.686Z","caller":"events/project_command_builder.go:479","msg":"got workspace lock","json":{"repo":"sheather/test","pull":"31"}}
{"level":"info","ts":"2025-02-01T13:27:41.686Z","caller":"events/working_dir.go:235","msg":"creating dir '/root/.atlantis/repos/sheather/test/31/default'","json":{"repo":"sheather/test","pull":"31"}}
{"level":"debug","ts":"2025-02-01T13:27:43.651Z","caller":"events/working_dir.go:326","msg":"ran: git clone --branch main --single-branch https://atlantis:<redacted>@gitlab.lan/sheather/test.git /root/.atlantis/repos/sheather/test/31/default. Output: Cloning into '/root/.atlantis/repos/sheather/test/31/default'...","json":{"repo":"sheather/test","pull":"31"}}
{"level":"debug","ts":"2025-02-01T13:27:43.662Z","caller":"events/working_dir.go:326","msg":"ran: git remote add head https://atlantis:<redacted>@gitlab.lan/sheather/test.git. Output: ","json":{"repo":"sheather/test","pull":"31"}}
{"level":"debug","ts":"2025-02-01T13:27:44.327Z","caller":"events/working_dir.go:326","msg":"ran: git fetch head +refs/heads/stack11:. Output: From https://gitlab.lan/sheather/test\n * branch            stack11    -> FETCH_HEAD\n * [new branch]      stack11    -> head/stack11","json":{"repo":"sheather/test","pull":"31"}}
{"level":"debug","ts":"2025-02-01T13:27:44.339Z","caller":"events/working_dir.go:326","msg":"ran: git merge-base main FETCH_HEAD. Output: 87ab0cdc7158639143581c4f4194703bad55286a","json":{"repo":"sheather/test","pull":"31"}}
{"level":"debug","ts":"2025-02-01T13:27:44.387Z","caller":"events/working_dir.go:326","msg":"ran: git merge -q --no-ff -m atlantis-merge FETCH_HEAD. Output: ","json":{"repo":"sheather/test","pull":"31"}}
{"level":"debug","ts":"2025-02-01T13:27:44.388Z","caller":"events/project_command_builder.go:488","msg":"'include-git-untracked-files' option is set, getting untracked files","json":{"repo":"sheather/test","pull":"31"}}
{"level":"debug","ts":"2025-02-01T13:27:44.388Z","caller":"events/working_dir.go:439","msg":"Checking for Git untracked files in directory: '/root/.atlantis/repos/sheather/test/31/default'","json":{"repo":"sheather/test","pull":"31"}}
{"level":"debug","ts":"2025-02-01T13:27:44.401Z","caller":"events/working_dir.go:449","msg":"Untracked files: ''","json":{"repo":"sheather/test","pull":"31"}}

references

@X-Guardian X-Guardian marked this pull request as ready for review February 1, 2025 16:30
@X-Guardian X-Guardian requested review from a team as code owners February 1, 2025 16:30
@X-Guardian X-Guardian requested review from GenPage, lukemassa and nitrocode and removed request for a team February 1, 2025 16:30
@dosubot dosubot bot added bug Something isn't working go Pull requests that update Go code labels Feb 1, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 1, 2025
@X-Guardian X-Guardian enabled auto-merge (squash) February 1, 2025 19:13
@X-Guardian X-Guardian merged commit 8157a8d into runatlantis:main Feb 1, 2025
39 checks passed
bub3n pushed a commit to bub3n/atlantis that referenced this pull request Feb 3, 2025
bub3n pushed a commit to bub3n/atlantis that referenced this pull request Feb 4, 2025
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 lgtm This PR has been approved by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

workspace does not exist
2 participants