This commit is contained in:
snakescott 2016-12-02 19:16:14 +00:00 committed by GitHub
commit e7a5a376f9
2 changed files with 12 additions and 4 deletions

View file

@ -34,6 +34,10 @@ def _add_color_option(parser):
) )
def _add_config_option(parser):
parser.add_argument('-c', '--config', help='Path to alternate config file')
def main(argv=None): def main(argv=None):
argv = argv if argv is not None else sys.argv[1:] argv = argv if argv is not None else sys.argv[1:]
argv = [five.to_text(arg) for arg in argv] argv = [five.to_text(arg) for arg in argv]
@ -89,6 +93,7 @@ def main(argv=None):
help="Auto-update pre-commit config to the latest repos' versions.", help="Auto-update pre-commit config to the latest repos' versions.",
) )
_add_color_option(autoupdate_parser) _add_color_option(autoupdate_parser)
_add_config_option(autoupdate_parser)
run_parser = subparsers.add_parser('run', help='Run hooks.') run_parser = subparsers.add_parser('run', help='Run hooks.')
_add_color_option(run_parser) _add_color_option(run_parser)
@ -119,6 +124,8 @@ def main(argv=None):
'--hook-stage', choices=('commit', 'push'), default='commit', '--hook-stage', choices=('commit', 'push'), default='commit',
help='The stage during which the hook is fired e.g. commit or push.', help='The stage during which the hook is fired e.g. commit or push.',
) )
_add_config_option(run_parser)
run_mutex_group = run_parser.add_mutually_exclusive_group(required=False) run_mutex_group = run_parser.add_mutually_exclusive_group(required=False)
run_mutex_group.add_argument( run_mutex_group.add_argument(
'--all-files', '-a', action='store_true', default=False, '--all-files', '-a', action='store_true', default=False,

View file

@ -16,18 +16,19 @@ class Runner(object):
repository under test. repository under test.
""" """
def __init__(self, git_root): def __init__(self, git_root, config_file=None):
self.git_root = git_root self.git_root = git_root
self.config_file = config_file or C.CONFIG_FILE
@classmethod @classmethod
def create(cls): def create(cls, config_file=None):
"""Creates a PreCommitRunner by doing the following: """Creates a PreCommitRunner by doing the following:
- Finds the root of the current git repository - Finds the root of the current git repository
- chdir to that directory - chdir to that directory
""" """
root = git.get_root() root = git.get_root()
os.chdir(root) os.chdir(root)
return cls(root) return cls(root, config_file=config_file)
@cached_property @cached_property
def git_dir(self): def git_dir(self):
@ -35,7 +36,7 @@ class Runner(object):
@cached_property @cached_property
def config_file_path(self): def config_file_path(self):
return os.path.join(self.git_root, C.CONFIG_FILE) return os.path.join(self.git_root, self.config_file)
@cached_property @cached_property
def repositories(self): def repositories(self):