mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Make pre_commit also support pre-push hook
This commit is contained in:
parent
d2b11a0c50
commit
b707cbba06
10 changed files with 227 additions and 42 deletions
|
|
@ -12,6 +12,7 @@ import pytest
|
|||
from pre_commit.commands.install_uninstall import install
|
||||
from pre_commit.commands.run import _get_skips
|
||||
from pre_commit.commands.run import _has_unmerged_paths
|
||||
from pre_commit.commands.run import get_changed_files
|
||||
from pre_commit.commands.run import run
|
||||
from pre_commit.runner import Runner
|
||||
from pre_commit.util import cmd_output
|
||||
|
|
@ -50,6 +51,8 @@ def _get_opts(
|
|||
verbose=False,
|
||||
hook=None,
|
||||
no_stash=False,
|
||||
origin='',
|
||||
source='',
|
||||
):
|
||||
# These are mutually exclusive
|
||||
assert not (all_files and files)
|
||||
|
|
@ -60,6 +63,8 @@ def _get_opts(
|
|||
verbose=verbose,
|
||||
hook=hook,
|
||||
no_stash=no_stash,
|
||||
origin=origin,
|
||||
source=source,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -126,6 +131,28 @@ def test_run(
|
|||
_test_run(repo_with_passing_hook, options, outputs, expected_ret, stage)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('origin', 'source', 'expect_stash'),
|
||||
(
|
||||
('master', 'master', False),
|
||||
('master', '', True),
|
||||
('', 'master', True),
|
||||
)
|
||||
)
|
||||
def test_origin_source_define(
|
||||
repo_with_passing_hook, origin, source, expect_stash,
|
||||
mock_out_store_directory):
|
||||
args = _get_opts(origin=origin, source=source)
|
||||
ret, printed = _do_run(repo_with_passing_hook, args)
|
||||
warning_msg = '--origin and --source depend on each other.'
|
||||
if expect_stash:
|
||||
assert ret == 1
|
||||
assert warning_msg in printed
|
||||
else:
|
||||
assert ret == 0
|
||||
assert warning_msg not in printed
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('no_stash', 'all_files', 'expect_stash'),
|
||||
(
|
||||
|
|
@ -267,3 +294,10 @@ def test_stdout_write_bug_py26(
|
|||
assert 'UnicodeEncodeError' not in stdout
|
||||
# Doesn't actually happen, but a reasonable assertion
|
||||
assert 'UnicodeDecodeError' not in stdout
|
||||
|
||||
|
||||
def test_get_changed_files():
|
||||
files = list(get_changed_files('78c682a1d13ba20e7cb735313b9314a74365cd3a',
|
||||
'3387edbb1288a580b37fe25225aa0b856b18ad1a'
|
||||
))
|
||||
assert files == ['CHANGELOG.md', 'setup.py']
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue