Skip to content

Commit b230a1c

Browse files
committed
[LTRM] Shell Check changes
Includes PR Copilot suggestions, mostly just some minor grammar and print safety checks not identified by shellcheck.
1 parent 2babab6 commit b230a1c

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

lt_rebase_merge.sh

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,30 @@ if [ -z "$PR_BRANCH" ] || [ -z "$TARGET_BRANCH" ]; then
1212
fi
1313

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

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

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

3333

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

51-
NEW_GKH_TAG=$(git describe --tags --abbrev=0 $PR_BRANCH | sed 's/^.//g')
51+
NEW_GKH_TAG=$(git describe --tags --abbrev=0 "${PR_BRANCH}" | sed 's/^.//g')
5252
if [ -z "$NEW_GKH_TAG" ]; then
5353
echo "Failed to get a GKH Tag from ${PR_BRANCH}."
54-
echo "LastTag: $(git describe --tags --abbrev=0 $PR_BRANCH)"
54+
echo "LastTag: $(git describe --tags --abbrev=0 "${PR_BRANCH}")"
5555
exit 1
5656
fi
5757
# Check if NEW_GKH_TAG matches the regex
@@ -63,43 +63,43 @@ NEW_CIQ_TAG="ciq_kernel-${NEW_GKH_TAG}-1"
6363
# merge PR branch into next branch
6464
set +x
6565

66-
echo "Commands expected to run (This is in the even it fails during the run)"
67-
echo "git checkout $NEXT_BRANCH"
68-
echo "git pull origin $NEXT_BRANCH"
69-
echo "git merge --ff-only $PR_BRANCH"
70-
echo "git push origin $NEXT_BRANCH"
71-
echo "git branch -m $TARGET_BRANCH $PAST_VERSION_BRANCH"
72-
echo "git push origin :$TARGET_BRANCH $PAST_VERSION_BRANCH"
73-
echo "git push origin -u $PAST_VERSION_BRANCH"
74-
echo "git branch -m $NEXT_BRANCH $TARGET_BRANCH"
75-
echo "git push origin :$NEXT_BRANCH $TARGET_BRANCH"
76-
echo "git push origin -u $TARGET_BRANCH"
77-
echo "git tag $NEW_CIQ_TAG $TARGET_BRANCH"
78-
echo "git push origin $NEW_CIQ_TAG"
66+
echo "Commands expected to run (This is in the event it fails during the run)"
67+
echo "git checkout \"${NEXT_BRANCH}\""
68+
echo "git pull origin \"${NEXT_BRANCH}\""
69+
echo "git merge --ff-only \"${PR_BRANCH}\""
70+
echo "git push origin \"${NEXT_BRANCH}\""
71+
echo "git branch -m \"${TARGET_BRANCH}\" \"${PAST_VERSION_BRANCH}\""
72+
echo "git push origin :\"${TARGET_BRANCH}\" \"${PAST_VERSION_BRANCH}\""
73+
echo "git push origin -u \"${PAST_VERSION_BRANCH}\""
74+
echo "git branch -m \"${NEXT_BRANCH}\" \"${TARGET_BRANCH}\""
75+
echo "git push origin :\"${NEXT_BRANCH}\" \"${TARGET_BRANCH}\""
76+
echo "git push origin -u \"${TARGET_BRANCH}\""
77+
echo "git tag \"${NEW_CIQ_TAG}\" \"${TARGET_BRANCH}\""
78+
echo "git push origin \"${NEW_CIQ_TAG}\""
7979

8080
echo "git checkout $NEXT_BRANCH"
81-
git checkout $NEXT_BRANCH
81+
git checkout "${NEXT_BRANCH}"
8282
if [ $? -ne 0 ]; then
8383
echo "Failed to checkout ${NEXT_BRANCH}."
8484
exit 1
8585
fi
8686

8787
echo "git pull origin $NEXT_BRANCH"
88-
git pull origin $NEXT_BRANCH
88+
git pull origin "${NEXT_BRANCH}"
8989
if [ $? -ne 0 ]; then
9090
echo "Failed to pull ${NEXT_BRANCH}."
9191
exit 1
9292
fi
9393

94-
echo "git merge --ff-only $PR_BRANCH"
95-
git merge --ff-only $PR_BRANCH
94+
echo "git merge --ff-only ${PR_BRANCH}"
95+
git merge --ff-only "${PR_BRANCH}"
9696
if [ $? -ne 0 ]; then
9797
echo "Failed to merge ${PR_BRANCH} into ${NEXT_BRANCH}."
9898
exit 1
9999
fi
100100

101101
echo "git push origin $NEXT_BRANCH"
102-
git push origin $NEXT_BRANCH
102+
git push origin "${NEXT_BRANCH}"
103103
if [ $? -ne 0 ]; then
104104
echo "Failed to push ${NEXT_BRANCH}."
105105
exit 1
@@ -112,59 +112,64 @@ if [ $? -ne 0 ]; then
112112
echo "Failed to delete ${PR_BRANCH} remotely."
113113
exit 1
114114
fi
115+
git branch -d "${PR_BRANCH}"
116+
if [ $? -ne 0 ]; then
117+
echo "Failed to delete ${PR_BRANCH} locally."
118+
exit 1
119+
fi
115120

116121

117122
echo "git branch -m $TARGET_BRANCH $PAST_VERSION_BRANCH"
118-
git branch -m $TARGET_BRANCH $PAST_VERSION_BRANCH
123+
git branch -m "${TARGET_BRANCH}" "${PAST_VERSION_BRANCH}"
119124
if [ $? -ne 0 ]; then
120125
echo "Failed to rename ${TARGET_BRANCH} to ${PAST_VERSION_BRANCH}."
121126
exit 1
122127
fi
123128

124129
echo "git push origin :$TARGET_BRANCH $PAST_VERSION_BRANCH"
125-
git push origin :$TARGET_BRANCH $PAST_VERSION_BRANCH
130+
git push origin :"${TARGET_BRANCH}" "${PAST_VERSION_BRANCH}"
126131
if [ $? -ne 0 ]; then
127132
echo "Failed to delete ${TARGET_BRANCH}."
128133
exit 1
129134
fi
130135

131136
echo "git push origin -u $PAST_VERSION_BRANCH"
132-
git push origin -u $PAST_VERSION_BRANCH
137+
git push origin -u "${PAST_VERSION_BRANCH}"
133138
if [ $? -ne 0 ]; then
134139
echo "Failed to push ${PAST_VERSION_BRANCH}."
135140
exit 1
136141
fi
137142

138143
echo "git branch -m $NEXT_BRANCH $TARGET_BRANCH"
139-
git branch -m $NEXT_BRANCH $TARGET_BRANCH
144+
git branch -m "${NEXT_BRANCH}" "${TARGET_BRANCH}"
140145
if [ $? -ne 0 ]; then
141146
echo "Failed to rename ${NEXT_BRANCH} to ${TARGET_BRANCH}."
142147
exit 1
143148
fi
144149

145150
echo "git push origin :$NEXT_BRANCH $TARGET_BRANCH"
146-
git push origin :$NEXT_BRANCH $TARGET_BRANCH
151+
git push origin :"${NEXT_BRANCH}" "${TARGET_BRANCH}"
147152
if [ $? -ne 0 ]; then
148153
echo "Failed to delete ${NEXT_BRANCH}."
149154
exit 1
150155
fi
151156

152157
echo "git push origin -u $TARGET_BRANCH"
153-
git push origin -u $TARGET_BRANCH
158+
git push origin -u "${TARGET_BRANCH}"
154159
if [ $? -ne 0 ]; then
155160
echo "Failed to push ${TARGET_BRANCH}."
156161
exit 1
157162
fi
158163

159164
echo "git tag $NEW_CIQ_TAG $TARGET_BRANCH"
160-
git tag $NEW_CIQ_TAG $TARGET_BRANCH
165+
git tag "${NEW_CIQ_TAG}" "${TARGET_BRANCH}"
161166
if [ $? -ne 0 ]; then
162167
echo "Failed to tag ${TARGET_BRANCH} with ${NEW_CIQ_TAG}."
163168
exit 1
164169
fi
165170

166171
echo "git push origin $NEW_CIQ_TAG"
167-
git push origin $NEW_CIQ_TAG
172+
git push origin "${NEW_CIQ_TAG}"
168173
if [ $? -ne 0 ]; then
169174
echo "Failed to push ${NEW_CIQ_TAG}."
170175
exit 1

0 commit comments

Comments
 (0)