Last active
April 8, 2024 15:07
-
-
Save RocketRene/701c342f429bfa2d6214e446b15fb38c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Find the commit hash of the last user commit before any Atlantis merge commits. | |
# Adjust "atlantis-merge" if Atlantis uses a different commit message. | |
atlantis_commit_pattern="atlantis-merge" | |
# Get the hash of the first Atlantis merge commit looking backwards from HEAD. | |
# The "^!" ensures we only get commits with messages not matching the Atlantis pattern. | |
atlantis_commit=$(git log --pretty=format:'%H %s' | grep -m 1 -B 1 "$atlantis_commit_pattern" | head -n1 | cut -d' ' -f1) | |
if [ ! -z "$atlantis_commit" ]; then | |
# Find the immediate parent commit of the found Atlantis commit, which should be the last user commit. | |
user_commit=$(git rev-parse "${atlantis_commit}^") | |
if [ ! -z "$user_commit" ]; then | |
echo "Checking out to user's last commit $user_commit before Atlantis merge." | |
git checkout $user_commit | |
else | |
echo "Could not find the user's last commit before the Atlantis merge." | |
fi | |
else | |
echo "No Atlantis merge commit found. Staying on current commit." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment