Skip to content

Commit 3ce462c

Browse files
committed
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.
1 parent e26dcc0 commit 3ce462c

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

build-aux/git-hooks/commit-msg-files.awk

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
function get_commit_changes(commit_sha, changes, cmd, i, j, len, \
3434
bits, filename) {
3535
# 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)
3737
while ((cmd | getline) > 0) {
3838
for (i = 2; i <= NF; i++) {
3939
len = split($i, bits, "/")

build-aux/git-hooks/pre-push

+6-3
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,17 @@ else
3939
fi
4040

4141
# 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
4343
$awk -v origin_name="$1" '
4444
# If the local SHA is all zeroes, ignore it.
4545
$2 ~ /^0{40}$/ {
4646
next
4747
}
4848
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]+)$/ {
5053
newref = $2
5154
# If the remote SHA is all zeroes, this is a new object to be
5255
# pushed (likely a branch)...
@@ -78,6 +81,6 @@ $awk -v origin_name="$1" '
7881
}
7982
8083
# 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)
8285
}
8386
' | $awk -v reason=pre-push -f .git/hooks/commit-msg-files.awk

0 commit comments

Comments
 (0)