aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Porter2023-04-23 11:43:07 -0700
committerJim Porter2023-04-23 12:07:08 -0700
commit3ce462c8fda02c29e79ec80fb389fc44d550142a (patch)
treeddbfa1d0b863ce8e1372ba1cef3b851691b26399
parente26dcc0e1441ded286b83eefb358d965748dd6db (diff)
downloademacs-3ce462c8fda02c29e79ec80fb389fc44d550142a.tar.gz
emacs-3ce462c8fda02c29e79ec80fb389fc44d550142a.zip
When examining merge commits in our Git hooks, only check the first parent
This does two things: 1. We can properly validate log entries in merge commits. 2. We don't check commits that were merged in from other branches. * build-aux/git-hooks/commit-msg-files.awk (get_commit_changes): Get the changes compared to the first parent. * build-aux/git-hooks/pre-push: Only get the first parent of merge commits when returning the rev-list, and only check "master" or "emacs-NN" branches.
-rw-r--r--build-aux/git-hooks/commit-msg-files.awk2
-rwxr-xr-xbuild-aux/git-hooks/pre-push9
2 files changed, 7 insertions, 4 deletions
diff --git a/build-aux/git-hooks/commit-msg-files.awk b/build-aux/git-hooks/commit-msg-files.awk
index 2117681343f..5c9b70a5de5 100644
--- a/build-aux/git-hooks/commit-msg-files.awk
+++ b/build-aux/git-hooks/commit-msg-files.awk
@@ -33,7 +33,7 @@
33function get_commit_changes(commit_sha, changes, cmd, i, j, len, \ 33function get_commit_changes(commit_sha, changes, cmd, i, j, len, \
34 bits, filename) { 34 bits, filename) {
35 # Collect all the files touched in the specified commit. 35 # Collect all the files touched in the specified commit.
36 cmd = ("git log -1 --name-status --format= " commit_sha) 36 cmd = ("git show --name-status --first-parent --format= " commit_sha)
37 while ((cmd | getline) > 0) { 37 while ((cmd | getline) > 0) {
38 for (i = 2; i <= NF; i++) { 38 for (i = 2; i <= NF; i++) {
39 len = split($i, bits, "/") 39 len = split($i, bits, "/")
diff --git a/build-aux/git-hooks/pre-push b/build-aux/git-hooks/pre-push
index 65c96bfdec9..03fbede4865 100755
--- a/build-aux/git-hooks/pre-push
+++ b/build-aux/git-hooks/pre-push
@@ -39,14 +39,17 @@ else
39fi 39fi
40 40
41# Standard input receives lines of the form: 41# Standard input receives lines of the form:
42# <local ref> SP <local name> SP <remote ref> SP <remote name> LF 42# <local ref> SP <local sha> SP <remote ref> SP <remote sha> LF
43$awk -v origin_name="$1" ' 43$awk -v origin_name="$1" '
44 # If the local SHA is all zeroes, ignore it. 44 # If the local SHA is all zeroes, ignore it.
45 $2 ~ /^0{40}$/ { 45 $2 ~ /^0{40}$/ {
46 next 46 next
47 } 47 }
48 48
49 $2 ~ /^[a-z0-9]{40}$/ { 49 # Check any lines with a valid local SHA and whose remote ref is
50 # master or an emacs-NN release branch. (We want to avoid checking
51 # feature or scratch branches here.)
52 $2 ~ /^[a-z0-9]{40}$/ && $3 ~ /^refs/heads/(master|emacs-[0-9]+)$/ {
50 newref = $2 53 newref = $2
51 # If the remote SHA is all zeroes, this is a new object to be 54 # If the remote SHA is all zeroes, this is a new object to be
52 # pushed (likely a branch)... 55 # pushed (likely a branch)...
@@ -78,6 +81,6 @@ $awk -v origin_name="$1" '
78 } 81 }
79 82
80 # Print every SHA after oldref, up to (and including) newref. 83 # Print every SHA after oldref, up to (and including) newref.
81 system("git rev-list --reverse " oldref ".." newref) 84 system("git rev-list --first-parent --reverse " oldref ".." newref)
82 } 85 }
83' | $awk -v reason=pre-push -f .git/hooks/commit-msg-files.awk 86' | $awk -v reason=pre-push -f .git/hooks/commit-msg-files.awk