Skip to content

Commit 8457740

Browse files
committed
Amend commit instead, and sanitize input prompts
Signed-off-by: methylDragon <methylDragon@gmail.com>
1 parent 0ab424b commit 8457740

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

jenkins-scripts/tools/header_migration_script.sh

+35-8
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,22 @@ startFromCleanBranch() {
158158
# $3: Commit message
159159
gitCommit() {
160160
local OPTIND ADD_ALL STAGED_DIFF FORCE_COMMIT
161-
while getopts acfs flag; do
161+
while getopts acefs flag; do
162162
case "${flag}" in
163163
a)
164164
local ADD_ALL="true" && echo -e "${GREEN}[gitCommit] Adding all unstaged files to commit!${DEFAULT}"
165165
;;
166166
c|s)
167167
local STAGED_DIFF="true" && echo -e "${GREEN}[gitCommit] Checking diff for staged files!${DEFAULT}"
168168
;;
169+
e)
170+
local AMEND="true" && echo -e "${GREEN}[gitCommit] Amending commit!${DEFAULT}"
171+
;;
169172
f)
170173
local FORCE_COMMIT="true" && echo -e "${GREEN}[gitCommit] Ignoring diffs!${DEFAULT}"
171174
;;
172175
*)
173-
echo -e "${RED}[gitCommit] Invalid flag passed! Valid: -s -c -a ${DEFAULT}"
176+
echo -e "${RED}[gitCommit] Invalid flag passed! Valid: -s -c -e -a ${DEFAULT}"
174177
;;
175178
esac
176179
done
@@ -203,13 +206,30 @@ gitCommit() {
203206
return
204207
fi
205208

206-
echo -e "${GREEN_BG}${REPO}: Commit ${REPO}: ${COMMIT_MSG} ? (y/n)${DEFAULT_BG}"
207-
read CONTINUE
209+
while true; do
210+
if [[ "${AMEND}" == "true" ]] ; then
211+
echo -e "${GREEN_BG}${REPO}: Amend latest commit on ${REPO}? (y/n)${DEFAULT_BG}"
212+
else
213+
echo -e "${GREEN_BG}${REPO}: Commit ${REPO}: ${COMMIT_MSG} ? (y/n)${DEFAULT_BG}"
214+
fi
215+
216+
read CONTINUE
217+
218+
case $CONTINUE in
219+
y) break;;
220+
n) echo "${GREEN}Skipping commit${DEFAULT}" && break;;
221+
esac
222+
done
223+
208224
if [ "$CONTINUE" = "y" ]; then
209225
if [[ "${ADD_ALL}" == "true" ]] ; then
210226
git add -A
211227
fi
212-
git commit -sam "${COMMIT_MSG}"
228+
if [[ "${AMEND}" == "true" ]] ; then
229+
git commit --amend -C HEAD
230+
else
231+
git commit -sam "${COMMIT_MSG}"
232+
fi
213233
fi
214234
}
215235

@@ -239,8 +259,15 @@ gitPushAndPR() {
239259

240260
# METHODS AND CONSTANTS ============================================================================
241261
reviewConfirm() {
242-
echo -e "${GREEN_BG}Reviewed changes, ready to commit? (y/n)${DEFAULT_BG}"
243-
read CONTINUE
262+
while true; do
263+
echo -e "${GREEN_BG}Have you reviewed the changes above, and are you ready to commit? (y?)${DEFAULT_BG}"
264+
read CONTINUE
265+
266+
case $CONTINUE in
267+
y) break;;
268+
esac
269+
done
270+
244271
if [ "$CONTINUE" = "y" ]; then
245272
return
246273
fi
@@ -390,7 +417,7 @@ git restore .
390417
git apply <<< "${PATCHED_GIT_DIFF}"
391418

392419
reviewConfirm
393-
gitCommit -a ${IGN_ORG} "Provision redirection aliases"
420+
gitCommit -f -a -e ${IGN_ORG}
394421

395422
# Migrate Gz sources
396423
find . -regex '.*/\[src\|test\|examples\]/.*\|.*include\(.*\)*/[gz|Gz].*' -type f -print0 | xargs -0 -I {} bash -c 'migrateSources {}' _

0 commit comments

Comments
 (0)