1
0
Fork 0

Adding upstream version 2.3.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-09 21:19:00 +01:00
parent c0d06915b7
commit 080d7f9289
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
17 changed files with 261 additions and 37 deletions

View file

@ -263,6 +263,45 @@ def test_does_not_reformat(tmpdir, out_of_date, store):
assert cfg.read() == expected
def test_does_not_change_mixed_endlines_read(up_to_date, tmpdir, store):
fmt = (
'repos:\n'
'- repo: {}\n'
' rev: {} # definitely the version I want!\r\n'
' hooks:\r\n'
' - id: foo\n'
' # These args are because reasons!\r\n'
' args: [foo, bar, baz]\r\n'
)
cfg = tmpdir.join(C.CONFIG_FILE)
expected = fmt.format(up_to_date, git.head_rev(up_to_date)).encode()
cfg.write_binary(expected)
assert autoupdate(str(cfg), store, freeze=False, tags_only=False) == 0
assert cfg.read_binary() == expected
def test_does_not_change_mixed_endlines_write(tmpdir, out_of_date, store):
fmt = (
'repos:\n'
'- repo: {}\n'
' rev: {} # definitely the version I want!\r\n'
' hooks:\r\n'
' - id: foo\n'
' # These args are because reasons!\r\n'
' args: [foo, bar, baz]\r\n'
)
cfg = tmpdir.join(C.CONFIG_FILE)
cfg.write_binary(
fmt.format(out_of_date.path, out_of_date.original_rev).encode(),
)
assert autoupdate(str(cfg), store, freeze=False, tags_only=False) == 0
expected = fmt.format(out_of_date.path, out_of_date.head_rev).encode()
assert cfg.read_binary() == expected
def test_loses_formatting_when_not_detectable(out_of_date, store, tmpdir):
"""A best-effort attempt is made at updating rev without rewriting
formatting. When the original formatting cannot be detected, this

View file

@ -89,6 +89,51 @@ def test_run_legacy_recursive(tmpdir):
call()
@pytest.mark.parametrize(
('hook_type', 'args'),
(
('pre-commit', []),
('pre-merge-commit', []),
('pre-push', ['branch_name', 'remote_name']),
('commit-msg', ['.git/COMMIT_EDITMSG']),
('post-checkout', ['old_head', 'new_head', '1']),
# multiple choices for commit-editmsg
('prepare-commit-msg', ['.git/COMMIT_EDITMSG']),
('prepare-commit-msg', ['.git/COMMIT_EDITMSG', 'message']),
('prepare-commit-msg', ['.git/COMMIT_EDITMSG', 'commit', 'deadbeef']),
),
)
def test_check_args_length_ok(hook_type, args):
hook_impl._check_args_length(hook_type, args)
def test_check_args_length_error_too_many_plural():
with pytest.raises(SystemExit) as excinfo:
hook_impl._check_args_length('pre-commit', ['run', '--all-files'])
msg, = excinfo.value.args
assert msg == (
'hook-impl for pre-commit expected 0 arguments but got 2: '
"['run', '--all-files']"
)
def test_check_args_length_error_too_many_singluar():
with pytest.raises(SystemExit) as excinfo:
hook_impl._check_args_length('commit-msg', [])
msg, = excinfo.value.args
assert msg == 'hook-impl for commit-msg expected 1 argument but got 0: []'
def test_check_args_length_prepare_commit_msg_error():
with pytest.raises(SystemExit) as excinfo:
hook_impl._check_args_length('prepare-commit-msg', [])
msg, = excinfo.value.args
assert msg == (
'hook-impl for prepare-commit-msg expected 1, 2, or 3 arguments '
'but got 0: []'
)
def test_run_ns_pre_commit():
ns = hook_impl._run_ns('pre-commit', True, (), b'')
assert ns is not None

View file

@ -52,6 +52,18 @@ def test_full_msg():
assert ret == 'start......end\n'
def test_full_msg_with_cjk():
ret = _full_msg(
start='啊あ아',
end_msg='end',
end_color='',
use_color=False,
cols=15,
)
# 5 dots: 15 - 6 - 3 - 1
assert ret == '啊あ아.....end\n'
def test_full_msg_with_color():
ret = _full_msg(
start='start',