Skip to content

Commit 724bc65

Browse files
committed
Arm backend: Add non-interactive in git hook
The pre-push script is a nice to have script as a git hook for your work with the arm backend. In fact, it is so nice that we would like it to be part of CI jobs but to make that happen it needs to be non-interactive. This patch adds support for launching the script and never ending up in a scenario where the user has to interact with it. Signed-off-by: [email protected] Change-Id: I345a3a71f1b81446228150baf4db28bf4a47b0f1
1 parent 7a1131c commit 724bc65

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

backends/arm/scripts/pre-push

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7+
# Calling this script with any argument is equal to launching it in
8+
# non-interactive mode. "$#" gives the number of positional arguments.
9+
[ "$#" -eq 0 ] && is_script_interactive=1 || is_script_interactive=0
10+
711
RESET='\e[0m'
812
RED='\e[31m'
913
GREEN='\e[32m'
@@ -31,8 +35,10 @@ VERBS="Add|Fix|Update|Refactor|Improve|Remove|Change|Implement|Create|Modify|"\
3135

3236
# Remote branch
3337
REMOTE=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null)
34-
35-
if [ -z "$REMOTE" ]; then
38+
if [ $is_script_interactive -eq 0 ]; then
39+
# Just use the one commit
40+
COMMITS=$(git rev-list HEAD -n 1)
41+
elif [ -z "$REMOTE" ]; then
3642
echo -e "${WARNING} Could not find upstream branch to compare to."
3743
echo "Please specify the number of commits you are pushing."
3844
echo -n "Enter number of commits to check (default 1): " > /dev/tty
@@ -155,14 +161,17 @@ for COMMIT in ${COMMITS}; do
155161
if [[ ! "$SUBJECT" =~ ^"Arm backend":\ (${VERBS}) ]]; then
156162
echo -e "${WARNING} Subject should start with 'Arm backend: '"\
157163
"followed by an imperative verb." >&2
158-
echo -n "There are warnings in your commit message. Do you want to"\
159-
"ignore the warning (y/N): " > /dev/tty
160164

161-
read USER_INPUT < /dev/tty
165+
if [ $is_script_interactive -eq 1 ]; then
166+
echo -n "There are warnings in your commit message. Do you want to"\
167+
"ignore the warning (y/N): " > /dev/tty
162168

163-
# Check user input for warnings
164-
if [[ ! "$USER_INPUT" =~ ^[Yy]$ ]]; then
165-
FAILED=1
169+
read USER_INPUT < /dev/tty
170+
171+
# Check user input for warnings
172+
if [[ ! "$USER_INPUT" =~ ^[Yy]$ ]]; then
173+
FAILED=1
174+
fi
166175
fi
167176
fi
168177

0 commit comments

Comments
 (0)