Skip to content

Commit

Permalink
prepare-commit-msg hook doesn't generate a changed file list with Win…
Browse files Browse the repository at this point in the history
…dows Git

https://bugs.webkit.org/show_bug.cgi?id=261097

Reviewed by Jonathan Bedard.

prepare-ChangeLog reproted "Can't locate VCSUtils.pm in @inc" error if
it was executed from prepare-commit-msg hook of Windows Git. It failed
to set a library path to 'Tools/Scripts' directory.

Windows Git includes msys perl. prepare-commit-msg hook unexpectedly
executed it. It should execute Windows Perl.

Use shutil.which to get perl's absolute path. But, it's available for
Python 3.3 or newer. Windows port developers have been switched to
Python 3. Use the original relative command name 'perl' for older
Python.

* Tools/Scripts/hooks/prepare-commit-msg:
* Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/install_hooks.py:
* (InstallHooks.main): Added a new template variable 'perl' to set
perl's absolute path.

Canonical link: https://commits.webkit.org/267649@main
  • Loading branch information
fujii committed Sep 5, 2023
1 parent 7c273eb commit 662e379
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Tools/Scripts/hooks/prepare-commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def parseChanges(command, commit_message):

def message(source=None, sha=None):
commit_message = []
command = ['perl', os.path.join(SCRIPTS, 'prepare-ChangeLog'), '--no-write', '--only-files', '--delimiters', '--git-index']
command = [{{ perl }}, os.path.join(SCRIPTS, 'prepare-ChangeLog'), '--no-write', '--only-files', '--delimiters', '--git-index']

if sha:
commit_message.append('Amend changes:')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import os
import re
import sys
import shutil

from .command import Command
from webkitbugspy import radar
Expand Down Expand Up @@ -181,6 +182,9 @@ def main(cls, args, repository, hooks=None, identifier_template=None, **kwargs):

trailers_to_strip = ['Identifier'] + ([identifier_template.split(':', 1)[0]] if identifier_template else [])
source_remotes = repository.source_remotes() or ['origin']
perl = 'perl'
if sys.version_info >= (3, 3):
perl = shutil.which('perl')

installed_hooks = 0
for hook in hook_names:
Expand All @@ -197,6 +201,7 @@ def main(cls, args, repository, hooks=None, identifier_template=None, **kwargs):
from jinja2 import Template
contents = Template(f.read()).render(
location=os.path.relpath(source_path, repository.root_path),
perl=repr(perl),
python=os.path.basename(sys.executable),
prefer_radar=bool(radar.Tracker.radarclient()),
default_pre_push_mode="'{}'".format(getattr(args, 'mode', cls.MODES[0])),
Expand Down

0 comments on commit 662e379

Please sign in to comment.