|
20 | 20 | from pre_commit.commands.try_repo import try_repo |
21 | 21 | from pre_commit.error_handler import error_handler |
22 | 22 | from pre_commit.logging_handler import add_logging_handler |
23 | | -from pre_commit.runner import Runner |
24 | 23 | from pre_commit.store import Store |
25 | 24 |
|
26 | 25 |
|
@@ -89,6 +88,20 @@ def _add_run_options(parser): |
89 | 88 | ) |
90 | 89 |
|
91 | 90 |
|
| 91 | +def _adjust_args_and_chdir(args): |
| 92 | + # `--config` was specified relative to the non-root working directory |
| 93 | + if os.path.exists(args.config): |
| 94 | + args.config = os.path.abspath(args.config) |
| 95 | + if args.command in {'run', 'try-repo'}: |
| 96 | + args.files = [os.path.abspath(filename) for filename in args.files] |
| 97 | + |
| 98 | + os.chdir(git.get_root()) |
| 99 | + |
| 100 | + args.config = os.path.relpath(args.config) |
| 101 | + if args.command in {'run', 'try-repo'}: |
| 102 | + args.files = [os.path.relpath(filename) for filename in args.files] |
| 103 | + |
| 104 | + |
92 | 105 | def main(argv=None): |
93 | 106 | argv = argv if argv is not None else sys.argv[1:] |
94 | 107 | argv = [five.to_text(arg) for arg in argv] |
@@ -222,43 +235,40 @@ def main(argv=None): |
222 | 235 | parser.parse_args([args.help_cmd, '--help']) |
223 | 236 | elif args.command == 'help': |
224 | 237 | parser.parse_args(['--help']) |
225 | | - elif args.command in {'run', 'try-repo'}: |
226 | | - args.files = [ |
227 | | - os.path.relpath(os.path.abspath(filename), git.get_root()) |
228 | | - for filename in args.files |
229 | | - ] |
230 | 238 |
|
231 | 239 | with error_handler(): |
232 | 240 | add_logging_handler(args.color) |
233 | | - runner = Runner.create(args.config) |
| 241 | + |
| 242 | + _adjust_args_and_chdir(args) |
| 243 | + |
234 | 244 | store = Store() |
235 | 245 | git.check_for_cygwin_mismatch() |
236 | 246 |
|
237 | 247 | if args.command == 'install': |
238 | 248 | return install( |
239 | | - runner, store, |
| 249 | + args.config, store, |
240 | 250 | overwrite=args.overwrite, hooks=args.install_hooks, |
241 | 251 | hook_type=args.hook_type, |
242 | 252 | skip_on_missing_conf=args.allow_missing_config, |
243 | 253 | ) |
244 | 254 | elif args.command == 'install-hooks': |
245 | | - return install_hooks(runner, store) |
| 255 | + return install_hooks(args.config, store) |
246 | 256 | elif args.command == 'uninstall': |
247 | | - return uninstall(runner, hook_type=args.hook_type) |
| 257 | + return uninstall(hook_type=args.hook_type) |
248 | 258 | elif args.command == 'clean': |
249 | 259 | return clean(store) |
250 | 260 | elif args.command == 'autoupdate': |
251 | 261 | if args.tags_only: |
252 | 262 | logger.warning('--tags-only is the default') |
253 | 263 | return autoupdate( |
254 | | - runner, store, |
| 264 | + args.config, store, |
255 | 265 | tags_only=not args.bleeding_edge, |
256 | 266 | repos=args.repos, |
257 | 267 | ) |
258 | 268 | elif args.command == 'migrate-config': |
259 | | - return migrate_config(runner) |
| 269 | + return migrate_config(args.config) |
260 | 270 | elif args.command == 'run': |
261 | | - return run(runner, store, args) |
| 271 | + return run(args.config, store, args) |
262 | 272 | elif args.command == 'sample-config': |
263 | 273 | return sample_config() |
264 | 274 | elif args.command == 'try-repo': |
|
0 commit comments