Skip to content

Commit fb5f4c4

Browse files
committed
[LTR] Infer kernel version from UPSTREAM_REF
Use the inferred kernel version to construct all of the other branch references in the script. This should allow an UPSTREAM_REF of stable_6.18.y to be passed and the script to work the same way it does today for 6.12
1 parent 9e802b4 commit fb5f4c4

File tree

1 file changed

+42
-16
lines changed

1 file changed

+42
-16
lines changed

lt_rebase.sh

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,75 @@ if [ -z "$UPSTREAM_REF" ]; then
77
echo "UPSTREAM_REF not set, defaulting to $UPSTREAM_REF"
88
fi
99

10+
# Validate UPSTREAM_REF format to prevent shell injection
11+
case "$UPSTREAM_REF" in
12+
stable_[0-9]*.[0-9]*.y)
13+
# Valid format
14+
;;
15+
*)
16+
echo "Invalid UPSTREAM_REF format: $UPSTREAM_REF"
17+
echo "Expected format: stable_X.Y.y (e.g., stable_6.12.y)"
18+
exit 1
19+
;;
20+
esac
21+
22+
# Extract kernel version from UPSTREAM_REF (e.g., stable_6.12.y -> 6.12)
23+
KERNEL_VERSION=$(echo "$UPSTREAM_REF" | sed -E 's/.*_([0-9]+\.[0-9]+)\.y/\1/')
24+
if [ -z "$KERNEL_VERSION" ]; then
25+
echo "Failed to extract kernel version from UPSTREAM_REF: $UPSTREAM_REF"
26+
echo "Expected format: stable_X.Y.y (e.g., stable_6.12.y)"
27+
exit 1
28+
fi
29+
echo "Detected kernel version: $KERNEL_VERSION"
30+
31+
# Define branch names based on kernel version
32+
CIQ_BASE_BRANCH="ciq-${KERNEL_VERSION}.y"
33+
CIQ_NEXT_BRANCH="ciq-${KERNEL_VERSION}.y-next"
34+
CIQ_TMP_BRANCH="{automation_tmp}_ciq-${KERNEL_VERSION}.y-next"
35+
1036
git fetch --all
11-
git show-ref --verify --quiet refs/remotes/origin/$UPSTREAM_REF
37+
git show-ref --verify --quiet "refs/remotes/origin/${UPSTREAM_REF}"
1238
if [ $? -ne 0 ]; then
1339
echo "UPSTREAM_REF $UPSTREAM_REF does not exist, please check status of remote and local branches"
1440
exit 1
1541
fi
1642

17-
git checkout $UPSTREAM_REF
43+
git checkout "${UPSTREAM_REF}"
1844
if [ $? -ne 0 ]; then
1945
echo "Failed to checkout $UPSTREAM_REF, please check status of remote and local branches"
2046
exit 1
2147
fi
2248

23-
git show-ref --verify --quiet refs/heads/ciq-6.12.y-next
24-
if [ $? -eq 0 ]; then
25-
echo "ciq-6.12.y-next branch already exists, please check status of remote and local branches"
49+
git show-ref --verify --quiet "refs/heads/${CIQ_NEXT_BRANCH}"
50+
if [ $? -eq 0 ]; then
51+
echo "$CIQ_NEXT_BRANCH branch already exists, please check status of remote and local branches"
2652
exit 1
2753
fi
2854

29-
git show-ref --verify --quiet refs/heads/{automation_tmp}_ciq-6.12.y-next
30-
if [ $? -eq 0 ]; then
31-
echo "{automation_tmp}_ciq-6.12.y-next branch already exists, please check status of remote and local branches"
55+
git show-ref --verify --quiet "refs/heads/${CIQ_TMP_BRANCH}"
56+
if [ $? -eq 0 ]; then
57+
echo "$CIQ_TMP_BRANCH branch already exists, please check status of remote and local branches"
3258
exit 1
3359
fi
3460

35-
git checkout -b ciq-6.12.y-next $UPSTREAM_REF
61+
git checkout -b "${CIQ_NEXT_BRANCH}" "${UPSTREAM_REF}"
3662
if [ $? -ne 0 ]; then
37-
echo "Failed to checkout ciq-6.12.y-next, please check status of remote and local branches"
63+
echo "Failed to checkout $CIQ_NEXT_BRANCH, please check status of remote and local branches"
3864
exit 1
3965
fi
40-
git checkout ciq-6.12.y
66+
git checkout "${CIQ_BASE_BRANCH}"
4167
if [ $? -ne 0 ]; then
42-
echo "Failed to checkout ciq-6.12.y, please check status of remote and local branches"
68+
echo "Failed to checkout $CIQ_BASE_BRANCH, please check status of remote and local branches"
4369
exit 1
4470
fi
45-
git checkout -b {automation_tmp}_ciq-6.12.y-next
71+
git checkout -b "${CIQ_TMP_BRANCH}"
4672
if [ $? -ne 0 ]; then
47-
echo "Failed to checkout {automation_tmp}_ciq-6.12.y-next, please check status of remote and local branches"
73+
echo "Failed to checkout $CIQ_TMP_BRANCH, please check status of remote and local branches"
4874
exit 1
4975
fi
50-
git rebase ciq-6.12.y-next
76+
git rebase "${CIQ_NEXT_BRANCH}"
5177
if [ $? -ne 0 ]; then
52-
echo "Failed to rebase {automation_tmp}_ciq-6.12.y-next, please check status of remote and local branches"
78+
echo "Failed to rebase $CIQ_TMP_BRANCH, please check status of remote and local branches"
5379
exit 1
5480
fi
5581

0 commit comments

Comments
 (0)