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
|
|
@ -11,6 +11,7 @@ from pre_commit.logging_handler import LoggingHandler
|
|||
from pre_commit.output import get_hook_message
|
||||
from pre_commit.output import sys_stdout_write_wrapper
|
||||
from pre_commit.staged_files_only import staged_files_only
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import noop_context
|
||||
|
||||
|
||||
|
|
@ -48,8 +49,20 @@ def _print_user_skipped(hook, write, args):
|
|||
))
|
||||
|
||||
|
||||
def get_changed_files(new, old):
|
||||
changed_files = cmd_output(
|
||||
'git', 'diff', '--name-only', '{0}..{1}'.format(old, new),
|
||||
)[1].splitlines()
|
||||
for f in changed_files:
|
||||
if f:
|
||||
yield f
|
||||
|
||||
|
||||
def _run_single_hook(runner, repository, hook, args, write, skips=set()):
|
||||
if args.files:
|
||||
if args.origin and args.source:
|
||||
get_filenames = git.get_files_matching(
|
||||
lambda: get_changed_files(args.origin, args.source))
|
||||
elif args.files:
|
||||
get_filenames = git.get_files_matching(lambda: args.files)
|
||||
elif args.all_files:
|
||||
get_filenames = git.get_all_files_matching
|
||||
|
|
@ -137,6 +150,10 @@ def run(runner, args, write=sys_stdout_write_wrapper, environ=os.environ):
|
|||
if _has_unmerged_paths(runner):
|
||||
logger.error('Unmerged files. Resolve before committing.')
|
||||
return 1
|
||||
if (args.source and not args.origin) or \
|
||||
(args.origin and not args.source):
|
||||
logger.error('--origin and --source depend on each other.')
|
||||
return 1
|
||||
|
||||
# Don't stash if specified or files are specified
|
||||
if args.no_stash or args.all_files or args.files:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue