Skip to content

Commit

Permalink
[git-webkit] Handle multiple bugs associated with a single branch
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264450
rdar://118144919

Reviewed by Elliott Williams.

Parse `git config` output backwards to prefer newer config values.
Except for bugs, only allow a single line to be passed to the template
via 'git config'. For bugs, we should only allow a single bug from each
tracker to be associated with the issue.

* Tools/Scripts/hooks/prepare-commit-msg:

Canonical link: https://commits.webkit.org/270921@main
  • Loading branch information
JonWBedard committed Nov 18, 2023
1 parent ed1571f commit 88a259f
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions Tools/Scripts/hooks/prepare-commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,34 @@ from webkitbugspy import radar

def set_env_variables_from_branch_config():
BRANCH = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], **ENCODING_KWARGS).strip()
for name, variable in dict(
title='COMMIT_MESSAGE_TITLE',
bug='COMMIT_MESSAGE_BUG',
cherry_picked='GIT_WEBKIT_CHERRY_PICKED',
for name, data in dict(
title=('COMMIT_MESSAGE_TITLE', 1),
bug=('COMMIT_MESSAGE_BUG', re.compile(r'^(\D+)\d+$')),
cherry_picked=('GIT_WEBKIT_CHERRY_PICKED', 1),
).items():
variable, mode = data
if variable in os.environ:
continue
try:
value = subprocess.check_output(
value = ''
count = 0
for line in reversed(subprocess.check_output(
['git', 'config', '--get-all', 'branch.{}.{}'.format(BRANCH, name)],
stderr=subprocess.PIPE,
**ENCODING_KWARGS
).strip()
).strip().splitlines()):
if isinstance(mode, int) and count >= mode:
break
elif isinstance(mode, re.Pattern):
match = mode.match(line)
if match and match.group(1) in value:
continue

if line:
value += line + '\n'
count += 1

value = value.strip()
if value:
os.environ[variable] = value
except subprocess.CalledProcessError as error:
Expand Down

0 comments on commit 88a259f

Please sign in to comment.