Skip to content
Permalink
Browse files
[git] Allow pre-commit hook to feed from staged ChangeLogs
https://bugs.webkit.org/show_bug.cgi?id=239419

Patch by Philippe Normand <pnormand@igalia.com> on 2022-04-25
Reviewed by Jonathan Bedard.

In workflows where prepare-ChangeLog is executed manually before staging and committing
changes the prepare-commit-msg hook can now read the curated ChangeLog from the git stage
and present it in the editor for validation. In case no ChangeLog was staged, the hook will
generate a message itself.

* Scripts/hooks/prepare-commit-msg:

Canonical link: https://commits.webkit.org/249941@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@293318 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
philn authored and webkit-commit-queue committed Apr 25, 2022
1 parent dbf2157 commit ef06f577b9fcae23a1ad940f51e0ac82b095d006
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
@@ -1,3 +1,17 @@
2022-04-16 Philippe Normand <philn@igalia.com>

[git] Allow pre-commit hook to feed from staged ChangeLogs
https://bugs.webkit.org/show_bug.cgi?id=239419

Reviewed by Jonathan Bedard.

In workflows where prepare-ChangeLog is executed manually before staging and committing
changes the prepare-commit-msg hook can now read the curated ChangeLog from the git stage
and present it in the editor for validation. In case no ChangeLog was staged, the hook will
generate a message itself.

* Scripts/hooks/prepare-commit-msg:

2022-04-23 Brady Eidson <beidson@apple.com>

Add WKNotification and WKWebsiteDataStore SPI for handling click/close of persistent notifications
@@ -8,8 +8,36 @@ LOCATION = '{{ location }}'
SPACING = 8
SCRIPTS = os.path.dirname(os.path.dirname(LOCATION))

sys.path.append(SCRIPTS)
from webkitpy.common.checkout.diff_parser import DiffParser

def message_from_staged_changelogs():
try:
diff = subprocess.check_output(['{{ git }}', 'diff', '--staged'])
except subprocess.CalledProcessError:
return ''

modified_files = DiffParser(diff.splitlines()).files
message = ''
for path, parsed_diff in modified_files.items():
if not path.endswith('ChangeLog'):
continue

# Ignore first line (date, name, email) and second line (empty).
diff_lines = parsed_diff.lines[2:]

# Get added lines and strip leading 8 characters indentation.
lines = [line[2][SPACING:] for line in diff_lines if not line[0]]

message += '\n'.join(lines)

return message

def message(source=None, sha=None):
msg = message_from_staged_changelogs()
if msg:
return msg

dirname = None
commit_message = []

0 comments on commit ef06f57

Please sign in to comment.