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: improve branch reference handling and compare with merged state #14

Merged
merged 1 commit into from
Mar 13, 2025

Conversation

swade1987
Copy link
Owner

@swade1987 swade1987 commented Mar 13, 2025

This PR addresses an issue where the kustomize-diff action would fail when trying to create and merge temporary branches.

Problem
The action was attempting to compare BASE with the result of merging HEAD into BASE (which is the correct approach), but was failing with:

 printf '[DEBUG] %s \n' 'Creating temporary merge of test into main'
+ git merge test --quiet
merge: test - not something we can merge

Did you mean this?
	origin/test
+ echo 'Merge conflict detected. Cannot automatically merge test into main.'
Merge conflict detected. Cannot automatically merge test into main.
+ git merge --abort
fatal: There is no merge to abort (MERGE_HEAD missing).

This occurred because:

  1. GitHub Actions often use detached HEAD states
  2. Branch references need to handle both local and remote formats (e.g., main vs origin/main)
  3. Sometimes GitHub provides commit SHAs instead of branch names

Solution
Implemented robust branch reference resolution that:

  • Correctly detects whether a reference is available as a local branch, remote branch, or direct commit SHA
  • Resolves references to their correct format before attempting checkout or merge operations
  • Handles the detached HEAD state common in GitHub Actions environments

This fix enables the action to correctly implement the "compare with merged state" approach as initially intended, ensuring accurate diffs are displayed in PR comments.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have signed-off my commits with git commit -s

@swade1987 swade1987 merged commit 4ceac70 into next Mar 13, 2025
7 checks passed
@swade1987
Copy link
Owner Author

🎉 This PR is included in version 0.3.0-next.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

1 participant