mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 11:36:54 +00:00
Allow for more control in template variables
Sepearate commit message coming from git for handling in template.
This commit is contained in:
parent
f072bb622f
commit
912f1a5f41
4 changed files with 53 additions and 6 deletions
|
|
@ -52,13 +52,13 @@ TESTS = (
|
|||
),
|
||||
(
|
||||
b'',
|
||||
b'\n\nRelates: AA-01',
|
||||
b'\n\nRelates: #AA-01\n\n',
|
||||
'feature/AA-01',
|
||||
get_template_path('prepare_commit_msg_append.j2'),
|
||||
),
|
||||
(
|
||||
b'Initial message',
|
||||
b'Initial message\n\nRelates: AA-02',
|
||||
b'Initial message\n\nRelates: #AA-02\n\n',
|
||||
'feature/AA-02',
|
||||
get_template_path('prepare_commit_msg_append.j2'),
|
||||
),
|
||||
|
|
@ -110,3 +110,44 @@ def test_main(
|
|||
],
|
||||
) == 0
|
||||
assert path.read_binary() == expected_val
|
||||
|
||||
|
||||
TESTS_TEMPLATES = (
|
||||
(
|
||||
b'Initial Message\n\n# Git commented\n# output simulated',
|
||||
b'[1.0.0] Initial Message\n\n# Git commented\n# output simulated',
|
||||
'release/1.0.0', # but this should
|
||||
get_template_path('prepare_commit_msg_prepend.j2'),
|
||||
),
|
||||
(
|
||||
b'Initial Message\n# Git commented\n# output simulated',
|
||||
b'Initial Message\n\nRelates: #1.0.0\n\n'
|
||||
b'# Git commented\n# output simulated',
|
||||
'release/1.0.0', # but this should
|
||||
get_template_path('prepare_commit_msg_append.j2'),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('input_s', 'expected_val', 'branch_name', 'template'),
|
||||
TESTS_TEMPLATES,
|
||||
)
|
||||
def test_main_separating_content(
|
||||
input_s, expected_val, branch_name, template,
|
||||
temp_git_dir,
|
||||
):
|
||||
with temp_git_dir.as_cwd():
|
||||
path = temp_git_dir.join('file.txt')
|
||||
path.write_binary(input_s)
|
||||
assert path.read_binary() == input_s
|
||||
|
||||
cmd_output('git', 'checkout', '-b', branch_name)
|
||||
assert main(
|
||||
argv=[
|
||||
'-t', template,
|
||||
'-p', '(?<=release/).*',
|
||||
str(path),
|
||||
],
|
||||
) == 0
|
||||
assert path.read_binary() == expected_val
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue