⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 293318 in webkit


Ignore:
Timestamp:
Apr 25, 2022, 12:57:24 AM (4 years ago)
Author:
commit-queue@webkit.org
Message:

[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

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r293296 r293318  
     12022-04-16  Philippe Normand  <philn@igalia.com>
     2
     3        [git] Allow pre-commit hook to feed from staged ChangeLogs
     4        https://bugs.webkit.org/show_bug.cgi?id=239419
     5
     6        Reviewed by Jonathan Bedard.
     7
     8        In workflows where prepare-ChangeLog is executed manually before staging and committing
     9        changes the prepare-commit-msg hook can now read the curated ChangeLog from the git stage
     10        and present it in the editor for validation. In case no ChangeLog was staged, the hook will
     11        generate a message itself.
     12
     13        * Scripts/hooks/prepare-commit-msg:
     14
    1152022-04-23  Brady Eidson  <beidson@apple.com>
    216   
  • trunk/Tools/Scripts/hooks/prepare-commit-msg

    r289656 r293318  
    99SCRIPTS = os.path.dirname(os.path.dirname(LOCATION))
    1010
     11sys.path.append(SCRIPTS)
     12from webkitpy.common.checkout.diff_parser import DiffParser
     13
     14def message_from_staged_changelogs():
     15    try:
     16        diff = subprocess.check_output(['{{ git }}', 'diff', '--staged'])
     17    except subprocess.CalledProcessError:
     18        return ''
     19
     20    modified_files = DiffParser(diff.splitlines()).files
     21    message = ''
     22    for path, parsed_diff in modified_files.items():
     23        if not path.endswith('ChangeLog'):
     24            continue
     25
     26        # Ignore first line (date, name, email) and second line (empty).
     27        diff_lines = parsed_diff.lines[2:]
     28
     29        # Get added lines and strip leading 8 characters indentation.
     30        lines = [line[2][SPACING:] for line in diff_lines if not line[0]]
     31
     32        message += '\n'.join(lines)
     33
     34    return message
    1135
    1236def message(source=None, sha=None):
     37    msg = message_from_staged_changelogs()
     38    if msg:
     39        return msg
     40
    1341    dirname = None
    1442    commit_message = []
Note: See TracChangeset for help on using the changeset viewer.