Skip to content

Commit a950be7

Browse files
committed
fix: properly handle github pr merge commits
1 parent d3dfb38 commit a950be7

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

suspicious_patterns.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ set -euo pipefail
2727
exclude_pattern="public_key|not-suspicious"
2828

2929
# Array of filenames to exclude from checking (basename matching)
30-
exclude_files=("Import_test.cpp")
30+
exclude_files=(
31+
"Import_test.cpp"
32+
"validators-example.txt"
33+
)
3134

3235
# Get the repository's root directory
3336
repo_root=$(git rev-parse --show-toplevel)
@@ -53,7 +56,17 @@ else
5356
git fetch --depth=1 origin "$base_ref"
5457
fi
5558

56-
files_changed=$(git diff --name-only "origin/$base_ref"...HEAD)
59+
# Since there's no merge base in shallow clones, we need to be creative
60+
# Save current HEAD, switch to base, then diff the trees
61+
current_head=$(git rev-parse HEAD)
62+
echo "Comparing against base branch origin/$base_ref..."
63+
64+
# Get the tree objects to compare (this works even without shared history)
65+
base_tree=$(git rev-parse "origin/$base_ref^{tree}")
66+
head_tree=$(git rev-parse "$current_head^{tree}")
67+
68+
# Compare the two trees directly
69+
files_changed=$(git diff --name-only "$base_tree" "$head_tree")
5770
mode="PR changes"
5871
else
5972
# Regular push event: Check the actual commit that was pushed

0 commit comments

Comments
 (0)