Add --no-stash option.

This commit is contained in:
Anthony Sottile
2014-04-13 20:00:10 -07:00
parent 5386b0eea0
commit 8a8b2241a6
4 changed files with 54 additions and 11 deletions

View File

@@ -21,6 +21,7 @@ from pre_commit.jsonschema_extensions import remove_defaults
from pre_commit.logging_handler import LoggingHandler
from pre_commit.repository import Repository
from pre_commit.staged_files_only import staged_files_only
from pre_commit.util import noop_context
logger = logging.getLogger('pre_commit')
@@ -233,7 +234,12 @@ def run(runner, args, write=sys.stdout.write):
logger.addHandler(LoggingHandler(args.color, write=write))
logger.setLevel(logging.INFO)
with staged_files_only(runner.cmd_runner):
if args.no_stash:
ctx = noop_context()
else:
ctx = staged_files_only(runner.cmd_runner)
with ctx:
if args.hook:
return _run_hook(runner, args.hook, args, write=write)
else:

View File

@@ -31,6 +31,10 @@ def run(argv):
'--color', default='auto', type=color.use_color,
help='Whether to use color in output. Defaults to `auto`',
)
run_parser.add_argument(
'--no-stash', default=False, action='store_true',
help='Use this option to prevent auto stashing of unstaged files.',
)
run_parser.add_argument('--verbose', '-v', action='store_true', default=False)
help = subparsers.add_parser('help', help='Show help for a specific command.')

View File

@@ -62,3 +62,9 @@ def clean_path_on_failure(path):
if os.path.exists(path):
shutil.rmtree(path)
raise
# TODO: asottile.contextlib this with a forward port of nested
@contextlib.contextmanager
def noop_context():
yield