Title: [293318] trunk/Tools
- Revision
- 293318
- Author
- [email protected]
- Date
- 2022-04-25 00:57:24 -0700 (Mon, 25 Apr 2022)
Log Message
[git] Allow pre-commit hook to feed from staged ChangeLogs
https://bugs.webkit.org/show_bug.cgi?id=239419
Patch by Philippe Normand <[email protected]> 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
Modified Paths
Diff
Modified: trunk/Tools/ChangeLog (293317 => 293318)
--- trunk/Tools/ChangeLog 2022-04-25 07:04:37 UTC (rev 293317)
+++ trunk/Tools/ChangeLog 2022-04-25 07:57:24 UTC (rev 293318)
@@ -1,3 +1,17 @@
+2022-04-16 Philippe Normand <[email protected]>
+
+ [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 <[email protected]>
Add WKNotification and WKWebsiteDataStore SPI for handling click/close of persistent notifications
Modified: trunk/Tools/Scripts/hooks/prepare-commit-msg (293317 => 293318)
--- trunk/Tools/Scripts/hooks/prepare-commit-msg 2022-04-25 07:04:37 UTC (rev 293317)
+++ trunk/Tools/Scripts/hooks/prepare-commit-msg 2022-04-25 07:57:24 UTC (rev 293318)
@@ -8,8 +8,36 @@
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 = []
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes