mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-13 20:40:08 -06:00
fix for #157
This commit is contained in:
@@ -139,6 +139,18 @@ def _has_unmerged_paths(runner):
|
||||
return bool(stdout.strip())
|
||||
|
||||
|
||||
def _has_unstaged_config(runner):
|
||||
retcode, stdout, stderr = runner.cmd_runner.run(
|
||||
[
|
||||
'git', 'diff', '--exit-code', runner.config_file_path
|
||||
],
|
||||
retcode=None,
|
||||
encoding=None,
|
||||
)
|
||||
# be explicit, other git errors don't mean it has an unstaged config.
|
||||
return retcode == 1
|
||||
|
||||
|
||||
def run(runner, args, write=sys_stdout_write_wrapper, environ=os.environ):
|
||||
# Set up our logging handler
|
||||
logger.addHandler(LoggingHandler(args.color, write=write))
|
||||
@@ -151,6 +163,16 @@ def run(runner, args, write=sys_stdout_write_wrapper, environ=os.environ):
|
||||
if bool(args.source) != bool(args.origin):
|
||||
logger.error('Specify both --origin and --source.')
|
||||
return 1
|
||||
if _has_unstaged_config(runner) and not args.no_stash:
|
||||
if args.allow_unstaged_config:
|
||||
logger.warn('You have an unstaged config file and have '
|
||||
'specified the --allow-unstaged-config option.\n'
|
||||
'Note that your config will be stashed before the '
|
||||
'config is parsed unless --no-stash is specified.')
|
||||
else:
|
||||
logger.error('You have an unstaged config file and have not '
|
||||
'specified the --allow-unstaged-config option.\n')
|
||||
return 1
|
||||
|
||||
# Don't stash if specified or files are specified
|
||||
if args.no_stash or args.all_files or args.files:
|
||||
|
||||
@@ -94,6 +94,11 @@ def main(argv=None):
|
||||
'--source', '-s',
|
||||
help='The remote branch"s commit_id when using `git push`',
|
||||
)
|
||||
run_parser.add_argument(
|
||||
'--allow-unstaged-config', default=False, action='store_true',
|
||||
help='Allow an unstaged config to be present. Note that this will'
|
||||
'be stashed before parsing unless --no-stash is specified'
|
||||
)
|
||||
run_mutex_group = run_parser.add_mutually_exclusive_group(required=False)
|
||||
run_mutex_group.add_argument(
|
||||
'--all-files', '-a', action='store_true', default=False,
|
||||
|
||||
Reference in New Issue
Block a user