Skip to content

Commit b1ef5f6

Browse files
committed
fix: squash merges check
Signed-off-by: shitrerohit <rohit.shitre@ayanworks.com>
1 parent 71e9db4 commit b1ef5f6

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

.husky/pre-push

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ RESET="\033[0m"
1010

1111
echo "🔒 Checking commit signatures..."
1212

13+
# Get the email of the current user
14+
# CURRENT_EMAIL=$(git config user.email)
15+
1316
while read local_ref local_sha remote_ref remote_sha; do
1417
# Determine range of commits
1518
if [ "$remote_sha" = "0000000000000000000000000000000000000000" ]; then
@@ -29,9 +32,16 @@ while read local_ref local_sha remote_ref remote_sha; do
2932
continue
3033
fi
3134

32-
sig_status=$(git log --format='%G?' -n 1 $commit)
35+
# Skip commits not authored by the current user
36+
# author_email=$(git log -1 --format='%ae' $commit)
37+
# if [ "$author_email" != "$CURRENT_EMAIL" ]; then
38+
# echo "${CYAN}ℹ️ Skipping commit $commit authored by $author_email${RESET}"
39+
# continue
40+
# fi
3341

34-
if [ "$sig_status" != "G" ]; then
42+
# Check signature
43+
sig_status=$(git log --format='%G?' -n 1 $commit)
44+
if [ "$sig_status" = "N" ]; then
3545
unsigned_commits="$unsigned_commits $commit"
3646
fi
3747
done
@@ -49,18 +59,17 @@ while read local_ref local_sha remote_ref remote_sha; do
4959
parent_commit=$(git rev-parse "${earliest_commit}^")
5060

5161
echo "${CYAN}🔧 Auto-signing earliest local unsigned commit $earliest_commit...${RESET}"
52-
# Avoid flattening of merge commits
62+
# Rebase to amend only the earliest commit and skip merge commits
5363
git rebase --onto "$parent_commit" "$parent_commit" \
5464
--exec 'if [ $(git rev-list --parents -n 1 HEAD | awk "{print NF-1}") -eq 1 ]; then git commit --amend -sS --no-edit; else echo "Skipping merge commit $(git rev-parse --short HEAD)"; fi'
5565

5666
echo "${GREEN}✅ Earliest unsigned commit has been signed.${RESET}"
57-
echo "Please push again: git push --force-with-lease"
67+
echo "Please push again: git push"
5868
exit 1
5969
else
6070
echo "${YELLOW}You can manually sign commits using:${RESET}"
6171
echo
6272
# Latest commit (HEAD)
63-
head_commit=$(git rev-parse HEAD)
6473
echo " - For the latest commit (HEAD):"
6574
echo " git commit --amend -sS --no-edit"
6675
echo
@@ -71,7 +80,6 @@ while read local_ref local_sha remote_ref remote_sha; do
7180
echo " - For the earliest unsigned commit $short_hash (skipping merge commits):"
7281
echo " git rebase --onto $parent_commit $parent_commit \\"
7382
echo " --exec 'if [ \$(git rev-list --parents -n 1 HEAD | awk \"{print NF-1}\") -eq 1 ]; then git commit --amend -sS --no-edit; else echo \"Skipping merge commit \$(git rev-parse --short HEAD)\"; fi'"
74-
7583
echo
7684
echo "Then push normally with:"
7785
echo " git push"
@@ -88,4 +96,4 @@ while read local_ref local_sha remote_ref remote_sha; do
8896
fi
8997
done
9098

91-
echo "${GREEN}✅ All commits are signed and verified${RESET}"
99+
echo "${GREEN}✅ All commits are signed and verified${RESET}"

0 commit comments

Comments
 (0)