Skip to content

Commit 3eea1f1

Browse files
authored
Add git hook suggestions for Arm development (#7785)
Pre-commit runs lintrunner on commited files, tries applying the changes. Pre-push does not push if lintrunner or a simple license check does not pass. If WIP is included in commit header, no checks are done. setup-env.sh symlinks the hooks to your .git/hooks. install-editable.sh contains commands needed to do an editable install. Signed-off-by: Erik Lundell <[email protected]>
1 parent 0c855de commit 3eea1f1

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

backends/arm/scripts/pre-commit

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
# Copyright 2025 Arm Limited and/or its affiliates.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# Check 1: If commit header contains WIP, everything is ok
8+
git rev-list --format=%s --max-count=1 HEAD | grep -q WIP && exit 0
9+
10+
# Check 2: lintunner on latest patch.
11+
lintrunner -a --revision 'HEAD^' --skip MYPY
12+
commit_files=$(git diff-tree --no-commit-id --name-only --diff-filter=M HEAD -r)
13+
git add $commit_files || true

backends/arm/scripts/pre-push

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
# Copyright 2025 Arm Limited and/or its affiliates.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# Check 1: If commit header contains WIP, everything is ok
8+
git rev-list --format=%s --max-count=1 HEAD | grep -q WIP && exit 0
9+
10+
# Check 2: lintunner on latest patches.
11+
lintrunner --revision 'HEAD^'
12+
if [[ $? != 0 ]]
13+
then
14+
echo "Failed linting"
15+
exit 1
16+
fi
17+
18+
# Check 3: License headers
19+
# We do a simple check of if all committed headers contain "$current_year Arm".
20+
# This does not guarantee OK in ci but should be ok most of the time.
21+
22+
current_year=$(date +%Y)
23+
failed_license_check=false
24+
commit_files=$(git diff-tree --no-commit-id --name-only --diff-filter=ACMR HEAD -r)
25+
26+
27+
for commited_file in $commit_files; do
28+
head $commited_file | grep -q "$current_year Arm"
29+
if [[ $? != 0 ]]
30+
then
31+
echo "Header in $commited_file did not contain '$current_year Arm'"
32+
failed_license_check=true
33+
else
34+
echo "$commited_file passed license check"
35+
fi
36+
done
37+
38+
if [[ $failed_license_check == true ]]
39+
then
40+
exit 1
41+
else
42+
echo "Passed simple license check"
43+
fi
44+
45+
exit 0

backends/arm/scripts/setup-dev-env.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
# Copyright 2025 Arm Limited and/or its affiliates.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
git_dir=$(git rev-parse --git-dir)
8+
ln $git_dir/../backends/arm/scripts/pre-push $git_dir/hooks
9+
ln $git_dir/../backends/arm/scripts/pre-commit $git_dir/hooks

0 commit comments

Comments
 (0)