|
4 | 4 | # This source code is licensed under the BSD-style license found in the
|
5 | 5 | # LICENSE file in the root directory of this source tree.
|
6 | 6 |
|
| 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 | + |
7 | 11 | RESET='\e[0m'
|
8 | 12 | RED='\e[31m'
|
9 | 13 | GREEN='\e[32m'
|
@@ -31,8 +35,10 @@ VERBS="Add|Fix|Update|Refactor|Improve|Remove|Change|Implement|Create|Modify|"\
|
31 | 35 |
|
32 | 36 | # Remote branch
|
33 | 37 | 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 |
36 | 42 | echo -e "${WARNING} Could not find upstream branch to compare to."
|
37 | 43 | echo "Please specify the number of commits you are pushing."
|
38 | 44 | echo -n "Enter number of commits to check (default 1): " > /dev/tty
|
@@ -155,14 +161,17 @@ for COMMIT in ${COMMITS}; do
|
155 | 161 | if [[ ! "$SUBJECT" =~ ^"Arm backend":\ (${VERBS}) ]]; then
|
156 | 162 | echo -e "${WARNING} Subject should start with 'Arm backend: '"\
|
157 | 163 | "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 |
160 | 164 |
|
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 |
162 | 168 |
|
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 |
166 | 175 | fi
|
167 | 176 | fi
|
168 | 177 |
|
|
0 commit comments