unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob c1edccdf3e5d9b1710842f01bb0039fc65b5fc48 2942 bytes (raw)
name: build-aux/git-hooks/commit-msg-files.awk 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
 
# Check the file list of GNU Emacs change log entries for each commit SHA.

# Copyright 2023 Free Software Foundation, Inc.

# This file is part of GNU Emacs.

# GNU Emacs is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# GNU Emacs is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

function get_commit_changes(commit_sha, changes,    i, j, len, bits, filename) {
  # Collect all the files touched in the specified commit.
  while ((("git log -1 --name-status --format= " commit_sha) | getline) > 0) {
    for (i = 2; i <= NF; i++) {
      len = split($i, bits, "/")
      for (j = 1; j <= len; j++) {
        if (j == 1)
          filename = bits[j]
        else
          filename = filename "/" bits[j]
        changes[filename] = 1
      }
    }
  }
}

function check_commit_msg_files(commit_sha, verbose,    changes, good, msg, \
                                filenames_str, filenames, i) {
  get_commit_changes(commit_sha, changes)
  good = 1

  while ((("git log -1 --format=%B " commit_sha) | getline) > 0) {
    if (verbose && ! msg)
      msg = $0

    # Find lines that reference files.  We look at any line starting
    # with "*" (possibly prefixed by "; ") where the file part starts
    # with an alphanumeric character.  The file part ends if we
    # encounter any of the following characters: [ ( < { :
    if (/^(; )?\*[ \t]+[[:alnum:]]/ && match($0, "[[:alnum:]][^[(<{:]*")) {
      # There might be multiple files listed on this line, separated
      # by a comma and/or space.  Iterate over each of them.
      split(substr($0, RSTART, RLENGTH), filenames, "[[:blank:],][[:blank:]]*")
      for (i in filenames) {
        if (length(filenames[i]) && ! (filenames[i] in changes)) {
          if (good) {
            # Print a header describing the error.
            if (verbose)
              printf("In commit %s \"%s\"...\n", substr(commit_sha, 1, 10), msg)
            printf("Files listed in commit message, but not in diff:\n")
          }
          printf("  %s\n", filenames[i])
          good = 0
        }
      }
    }
  }

  return good
}

BEGIN {
  if (reason == "pre-push")
    verbose = 1
}

/^[a-z0-9]{40}$/ {
  if (! check_commit_msg_files($0, verbose)) {
    status = 1
  }
}

END {
  if (status != 0) {
    if (reason == "pre-push")
      error_msg = "Push aborted"
    else
      error_msg = "Bad commit message"
    printf("%s; please see the file 'CONTRIBUTE'\n", error_msg)
  }
  exit status
}

debug log:

solving c1edccdf3e5 ...
found c1edccdf3e5 in https://yhetil.org/emacs-devel/5adfbf6f-fbcb-f4e8-3662-48bd5eb6a269@gmail.com/

applying [1/1] https://yhetil.org/emacs-devel/5adfbf6f-fbcb-f4e8-3662-48bd5eb6a269@gmail.com/
diff --git a/build-aux/git-hooks/commit-msg-files.awk b/build-aux/git-hooks/commit-msg-files.awk
new file mode 100644
index 00000000000..c1edccdf3e5

Checking patch build-aux/git-hooks/commit-msg-files.awk...
Applied patch build-aux/git-hooks/commit-msg-files.awk cleanly.

index at:
100644 c1edccdf3e5d9b1710842f01bb0039fc65b5fc48	build-aux/git-hooks/commit-msg-files.awk

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).