Skip to content

LT Rebase Merge: Deal with failure better, Shell Check fixes #23

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

Open
wants to merge 3 commits into
base: mainline
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 49 additions & 22 deletions lt_rebase_merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ if [ -z "$PR_BRANCH" ] || [ -z "$TARGET_BRANCH" ]; then
fi

# Check if all branches exist
git show-ref --verify --quiet refs/heads/$PR_BRANCH
git show-ref --verify --quiet refs/heads/"${PR_BRANCH}"
if [ $? -ne 0 ]; then
echo "Branch ${PR_BRANCH} does not exist."
exit 1
fi

git show-ref --verify --quiet refs/heads/$TARGET_BRANCH
git show-ref --verify --quiet refs/heads/"${TARGET_BRANCH}"
if [ $? -ne 0 ]; then
echo "Branch ${TARGET_BRANCH} does not exist."
exit 1
fi

git show-ref --verify --quiet refs/heads/$NEXT_BRANCH
git show-ref --verify --quiet refs/heads/"${NEXT_BRANCH}"
if [ $? -ne 0 ] ; then
echo "Branch ${NEXT_BRANCH} does not exist."
exit 1
fi


#collect all static data fire before making alterations to the local and remote repositories
PAST_VERSION=$(git describe --tags --abbrev=0 $TARGET_BRANCH | awk -F '-' '{print $2}')
PAST_VERSION=$(git describe --tags --abbrev=0 "${TARGET_BRANCH}" | awk -F '-' '{print $2}')
if [ -z "$PAST_VERSION" ]; then
echo "Failed to get a CIQ Tag from ${TARGET_BRANCH}."
echo "LastTag: $(git describe --tags --abbrev=0 $TARGET_BRANCH)"
echo "LastTag: $(git describe --tags --abbrev=0 "${TARGET_BRANCH}")"
exit 1
fi
# Check if PAST_VERSION matches the regex
Expand All @@ -48,10 +48,10 @@ PAST_VERSION_BRANCH="ciq-${PAST_VERSION}"
echo "PAST_VERSION: $PAST_VERSION"
echo "PAST_VERSION_BRANCH: $PAST_VERSION_BRANCH"

NEW_GKH_TAG=$(git describe --tags --abbrev=0 $PR_BRANCH | sed 's/^.//g')
NEW_GKH_TAG=$(git describe --tags --abbrev=0 "${PR_BRANCH}" | sed 's/^.//g')
if [ -z "$NEW_GKH_TAG" ]; then
echo "Failed to get a GKH Tag from ${PR_BRANCH}."
echo "LastTag: $(git describe --tags --abbrev=0 $PR_BRANCH)"
echo "LastTag: $(git describe --tags --abbrev=0 "${PR_BRANCH}")"
exit 1
fi
# Check if NEW_GKH_TAG matches the regex
Expand All @@ -60,89 +60,116 @@ if ! [[ $NEW_GKH_TAG =~ $NVR_REGEX ]]; then # check if NEW_GKH_TAG matches the r
exit 1
fi
NEW_CIQ_TAG="ciq_kernel-${NEW_GKH_TAG}-1"


# merge PR branch into next branch
set +x

echo "Commands expected to run (This is in the event it fails during the run)"
echo "git checkout \"${NEXT_BRANCH}\""
echo "git pull origin \"${NEXT_BRANCH}\""
echo "git merge --ff-only \"${PR_BRANCH}\""
echo "git push origin \"${NEXT_BRANCH}\""
echo "git branch -m \"${TARGET_BRANCH}\" \"${PAST_VERSION_BRANCH}\""
echo "git push origin :\"${TARGET_BRANCH}\" \"${PAST_VERSION_BRANCH}\""
echo "git push origin -u \"${PAST_VERSION_BRANCH}\""
echo "git branch -m \"${NEXT_BRANCH}\" \"${TARGET_BRANCH}\""
echo "git push origin :\"${NEXT_BRANCH}\" \"${TARGET_BRANCH}\""
echo "git push origin -u \"${TARGET_BRANCH}\""
echo "git tag \"${NEW_CIQ_TAG}\" \"${TARGET_BRANCH}\""
echo "git push origin \"${NEW_CIQ_TAG}\""

echo "git checkout $NEXT_BRANCH"
git checkout $NEXT_BRANCH
git checkout "${NEXT_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to checkout ${NEXT_BRANCH}."
exit 1
fi

echo "git pull origin $NEXT_BRANCH"
git pull origin $NEXT_BRANCH
git pull origin "${NEXT_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to pull ${NEXT_BRANCH}."
exit 1
fi

Comment on lines +81 to 93
Copy link
Preview

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

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

[nitpick] The repeated pattern of echo + command + if [ $? -ne 0 ] could be refactored into a helper function to reduce duplication and improve readability.

Copilot uses AI. Check for mistakes.

echo "git merge --ff-only $PR_BRANCH"
git merge --ff-only $PR_BRANCH
echo "git merge --ff-only ${PR_BRANCH}"
git merge --ff-only "${PR_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to merge ${PR_BRANCH} into ${NEXT_BRANCH}."
exit 1
fi

echo "git push origin $NEXT_BRANCH"
git push origin $NEXT_BRANCH
git push origin "${NEXT_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to push ${NEXT_BRANCH}."
exit 1
fi

echo "Delete PR branch ${PR_BRANCH} locally and remotely"
echo "git push origin :${PR_BRANCH}"
git push origin :"${PR_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to delete ${PR_BRANCH} remotely."
exit 1
fi
git branch -d "${PR_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to delete ${PR_BRANCH} locally."
exit 1
fi


echo "git branch -m $TARGET_BRANCH $PAST_VERSION_BRANCH"
git branch -m $TARGET_BRANCH $PAST_VERSION_BRANCH
git branch -m "${TARGET_BRANCH}" "${PAST_VERSION_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to rename ${TARGET_BRANCH} to ${PAST_VERSION_BRANCH}."
exit 1
fi

echo "git push origin :$TARGET_BRANCH $PAST_VERSION_BRANCH"
git push origin :$TARGET_BRANCH $PAST_VERSION_BRANCH
git push origin :"${TARGET_BRANCH}" "${PAST_VERSION_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to delete ${TARGET_BRANCH}."
exit 1
fi

echo "git push origin -u $PAST_VERSION_BRANCH"
git push origin -u $PAST_VERSION_BRANCH
git push origin -u "${PAST_VERSION_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to push ${PAST_VERSION_BRANCH}."
exit 1
fi

echo "git branch -m $NEXT_BRANCH $TARGET_BRANCH"
git branch -m $NEXT_BRANCH $TARGET_BRANCH
git branch -m "${NEXT_BRANCH}" "${TARGET_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to rename ${NEXT_BRANCH} to ${TARGET_BRANCH}."
exit 1
fi

echo "git push origin :$NEXT_BRANCH $TARGET_BRANCH"
git push origin :$NEXT_BRANCH $TARGET_BRANCH
git push origin :"${NEXT_BRANCH}" "${TARGET_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to delete ${NEXT_BRANCH}."
exit 1
fi

echo "git push origin -u $TARGET_BRANCH"
git push origin -u $TARGET_BRANCH
git push origin -u "${TARGET_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to push ${TARGET_BRANCH}."
exit 1
fi

echo "git tag $NEW_CIQ_TAG $TARGET_BRANCH"
git tag $NEW_CIQ_TAG $TARGET_BRANCH
git tag "${NEW_CIQ_TAG}" "${TARGET_BRANCH}"
if [ $? -ne 0 ]; then
echo "Failed to tag ${TARGET_BRANCH} with ${NEW_CIQ_TAG}."
exit 1
fi

echo "git push origin $NEW_CIQ_TAG"
git push origin $NEW_CIQ_TAG
git push origin "${NEW_CIQ_TAG}"
if [ $? -ne 0 ]; then
echo "Failed to push ${NEW_CIQ_TAG}."
exit 1
Expand Down