atlantis icon indicating copy to clipboard operation
atlantis copied to clipboard

fix: post workflow hook failures with delete source branch on merge

Open dorian-tsorfy opened this issue 5 months ago • 2 comments

What

  • Fixed post-workflow hooks failure after MR merge with deleted source branches: Modified PostWorkflowHooksCommandRunner to detect closed/merged MRs and use a different cloning strategy that doesn't attempt to fetch deleted source branches.
  • Added comprehensive test coverage: Created test case specifically for the closed MR scenario to ensure the fix works correctly

Why

  • Root cause: When delete_source_branch_on_merge: true is configured, Atlantis merges the MR and deletes the source branch, but post-workflow hooks still try to fetch the deleted branch using the merge strategy, causing fatal: couldn't find remote ref refs/heads/foo errors
  • Business impact: This bug was preventing post-workflow hooks from executing after successful applies, breaking CI/CD pipelines and automated post-apply processes
  • Solution approach: Detect when an MR is closed (merged) and use base branch cloning instead of merge strategy, avoiding the need to fetch deleted source branches

Tests

[x] I have tested my changes by creating a comprehensive test case in post_workflow_hooks_command_runner_test.go that verifies the closed MR scenario [x] I have validated that the fix handles both scenarios: existing working directories and new directory creation [x] I have confirmed that the existing functionality for open MRs remains unchanged

References

  • Closing issue #4057

dorian-tsorfy avatar Jul 31 '25 11:07 dorian-tsorfy

@jamengual Hello :) Should I change something regarding these check failures? Because there is usage of exec.Command all over the repo with variables coming from the client

dorian-tsorfy avatar Aug 05 '25 06:08 dorian-tsorfy

Any update on this one?

dorian-tsorfy avatar Sep 21 '25 10:09 dorian-tsorfy