Skip to content

Commit

Permalink
Amend commit instead, and sanitize input prompts
Browse files Browse the repository at this point in the history
Signed-off-by: methylDragon <[email protected]>
  • Loading branch information
methylDragon committed Apr 27, 2022
1 parent 0ab424b commit 9c353f2
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions jenkins-scripts/tools/header_migration_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,22 @@ startFromCleanBranch() {
# $3: Commit message
gitCommit() {
local OPTIND ADD_ALL STAGED_DIFF FORCE_COMMIT
while getopts acfs flag; do
while getopts acefs flag; do
case "${flag}" in
a)
local ADD_ALL="true" && echo -e "${GREEN}[gitCommit] Adding all unstaged files to commit!${DEFAULT}"
;;
c|s)
local STAGED_DIFF="true" && echo -e "${GREEN}[gitCommit] Checking diff for staged files!${DEFAULT}"
;;
e)
local AMEND="true" && echo -e "${GREEN}[gitCommit] Amending commit!${DEFAULT}"
;;
f)
local FORCE_COMMIT="true" && echo -e "${GREEN}[gitCommit] Ignoring diffs!${DEFAULT}"
;;
*)
echo -e "${RED}[gitCommit] Invalid flag passed! Valid: -s -c -a ${DEFAULT}"
echo -e "${RED}[gitCommit] Invalid flag passed! Valid: -s -c -e -a ${DEFAULT}"
;;
esac
done
Expand Down Expand Up @@ -203,13 +206,30 @@ gitCommit() {
return
fi

echo -e "${GREEN_BG}${REPO}: Commit ${REPO}: ${COMMIT_MSG} ? (y/n)${DEFAULT_BG}"
read CONTINUE
while true; do
if [[ "${AMEND}" == "true" ]] ; then
echo -e "${GREEN_BG}${REPO}: Amend latest commit on ${REPO}? (y/n)${DEFAULT_BG}"
else
echo -e "${GREEN_BG}${REPO}: Commit ${REPO}: ${COMMIT_MSG} ? (y/n)${DEFAULT_BG}"
fi

read CONTINUE

case $CONTINUE in
y) break;;
n) echo -e "${GREEN}Skipping commit${DEFAULT}" && break;;
esac
done

if [ "$CONTINUE" = "y" ]; then
if [[ "${ADD_ALL}" == "true" ]] ; then
git add -A
fi
git commit -sam "${COMMIT_MSG}"
if [[ "${AMEND}" == "true" ]] ; then
git commit --amend -C HEAD
else
git commit -sam "${COMMIT_MSG}"
fi
fi
}

Expand Down Expand Up @@ -239,8 +259,15 @@ gitPushAndPR() {

# METHODS AND CONSTANTS ============================================================================
reviewConfirm() {
echo -e "${GREEN_BG}Reviewed changes, ready to commit? (y/n)${DEFAULT_BG}"
read CONTINUE
while true; do
echo -e "${GREEN_BG}Have you reviewed the changes above, and are you ready to commit? (y?)${DEFAULT_BG}"
read CONTINUE

case $CONTINUE in
y) break;;
esac
done

if [ "$CONTINUE" = "y" ]; then
return
fi
Expand Down Expand Up @@ -390,7 +417,7 @@ git restore .
git apply <<< "${PATCHED_GIT_DIFF}"

reviewConfirm
gitCommit -a ${IGN_ORG} "Provision redirection aliases"
gitCommit -f -a -e ${IGN_ORG}

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

0 comments on commit 9c353f2

Please sign in to comment.