mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Fixes crash during merge conflict. Closes #82.
This commit is contained in:
parent
5f0cab9114
commit
846ddeed67
3 changed files with 35 additions and 2 deletions
|
|
@ -30,6 +30,9 @@ COLS = int(subprocess.Popen(['tput', 'cols'], stdout=subprocess.PIPE).communicat
|
|||
|
||||
PASS_FAIL_LENGTH = 6
|
||||
|
||||
# Grabbed from `git help status`
|
||||
CONFLICTING_GIT_STATUSES = set(('DD', 'AU', 'UD', 'UA', 'DU', 'AA', 'UU'))
|
||||
|
||||
|
||||
def install(runner):
|
||||
"""Install the pre-commit hooks."""
|
||||
|
|
@ -229,11 +232,24 @@ def _run_hook(runner, hook_id, args, write):
|
|||
return 1
|
||||
|
||||
|
||||
def _has_unmerged_paths(runner):
|
||||
_, stdout, _ = runner.cmd_runner.run(
|
||||
['git', 'status', '--short'], retcode=None,
|
||||
)
|
||||
codes = set(line[:2] for line in stdout.splitlines())
|
||||
return codes & CONFLICTING_GIT_STATUSES > set()
|
||||
|
||||
|
||||
def run(runner, args, write=sys.stdout.write):
|
||||
# Set up our logging handler
|
||||
logger.addHandler(LoggingHandler(args.color, write=write))
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
# Check if we have unresolved merge conflict files and fail fast.
|
||||
if _has_unmerged_paths(runner):
|
||||
logger.error('Unmerged files. Resolve before committing.')
|
||||
return 1
|
||||
|
||||
if args.no_stash or args.all_files:
|
||||
ctx = noop_context()
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue