Skip to content

Commit 96cf9c8

Browse files
authored
Arm backend: Improve pre-push hook checks (pytorch#16777)
Update the pre-push hook: - Only check if the 'Arm backend: ' prefix is present in case all file modifications are in backends/arm or examples/arm; otherwise, skip the check. However, missing this prefix when it should be in place is now a fatal error for the pre-push hook. - The imperative mood check is still in place but it is now able to check patches no matter if they have the 'Arm backend: ' or not. Effectively it is now independent from the prefix check. When the imperative mood check fails, it is still just a warning. - Add a non-zero exit code (1) in case parse_test_names.py finds any test name violations. Otherwise the pre-push hook will not fail in case the script finds any violations. Signed-off-by: Martin Lindström <Martin.Lindstroem@arm.com>
1 parent e5311bf commit 96cf9c8

2 files changed

Lines changed: 34 additions & 10 deletions

File tree

‎backends/arm/scripts/parse_test_names.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2025 Arm Limited and/or its affiliates.
1+
# Copyright 2025-2026 Arm Limited and/or its affiliates.
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
@@ -269,3 +269,6 @@ def check_test_convention( # noqa: C901
269269
print(entry)
270270

271271
print(f"Total tests needing renaming: {len(violations)}")
272+
273+
if violations:
274+
sys.exit(1)

‎backends/arm/scripts/pre-push‎

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Copyright 2025 Arm Limited and/or its affiliates.
2+
# Copyright 2025-2026 Arm Limited and/or its affiliates.
33
#
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.
@@ -89,6 +89,9 @@ for COMMIT in ${COMMITS}; do
8989
echo -e "${SUCCESS} Lintrunner OK"
9090
fi
9191

92+
commit_files=$(git diff-tree --no-commit-id --name-only \
93+
--diff-filter=ACMR ${COMMIT} -r)
94+
9295
# Check license headers
9396
# We do a simple check of if all committed headers contain
9497
# "$current_year Arm". This does not guarantee OK in ci but should be ok
@@ -97,8 +100,6 @@ for COMMIT in ${COMMITS}; do
97100

98101
current_year=$(date +%Y)
99102
failed_license_check=false
100-
commit_files=$(git diff-tree --no-commit-id --name-only \
101-
--diff-filter=ACMR ${COMMIT} -r)
102103
for commited_file in $commit_files; do
103104
file_header=$(head "$commited_file")
104105
if ! echo "$file_header" | grep -qi "Arm"; then
@@ -169,19 +170,39 @@ for COMMIT in ${COMMITS}; do
169170
FAILED=1
170171
fi
171172

172-
# Check subject format, should start with 'Arm backend: ' and be
173-
# imperative mood.
174-
if [[ ! "$SUBJECT" =~ ^"Arm backend":\ (${VERBS}) ]]; then
175-
echo -e "${WARNING} Subject should start with 'Arm backend: '"\
176-
"followed by an imperative verb." >&2
173+
# Determine whether all modifications are under backends/arm or examples/arm
174+
only_arm_changes=true
175+
for commited_file in $commit_files; do
176+
if [[ $commited_file != backends/arm/* && $commited_file != examples/arm/* ]]; then
177+
only_arm_changes=false
178+
break
179+
fi
180+
done
181+
182+
# Determine if subject has 'Arm backend: ' prefix
183+
subject_prefix="Arm backend: "
184+
has_arm_backend_prefix=false
185+
subject_without_prefix="$SUBJECT"
186+
if [[ "$SUBJECT" == ${subject_prefix}* ]]; then
187+
has_arm_backend_prefix=true
188+
subject_without_prefix=${SUBJECT#"${subject_prefix}"}
189+
fi
190+
191+
# Require 'Arm backend: ' prefix when the commit only touches Arm backend/examples files
192+
if [[ $only_arm_changes == true && $has_arm_backend_prefix == false ]]; then
193+
echo -e "${ERROR} Subject must start with 'Arm backend: ' when only backends/arm or examples/arm files are modified." >&2
194+
FAILED=1
195+
fi
177196

197+
# Imperative mood check (after optional prefix removal)
198+
if [[ ! "$subject_without_prefix" =~ ^(${VERBS})(\ |$) ]]; then
199+
echo -e "${WARNING} Commit message should begin with an imperative verb." >&2
178200
if [ $is_script_interactive -eq 1 ]; then
179201
echo -n "There are warnings in your commit message. Do you want to"\
180202
"ignore the warning (y/N): " > /dev/tty
181203

182204
read USER_INPUT < /dev/tty
183205

184-
# Check user input for warnings
185206
if [[ ! "$USER_INPUT" =~ ^[Yy]$ ]]; then
186207
FAILED=1
187208
fi

0 commit comments

Comments
 (0)