| 173 | |
| 174 | |
| 175 | def _adjust_args_and_chdir(args: argparse.Namespace) -> None: |
| 176 | # `--config` was specified relative to the non-root working directory |
| 177 | if os.path.exists(args.config): |
| 178 | args.config = os.path.abspath(args.config) |
| 179 | if args.command in {'run', 'try-repo'}: |
| 180 | args.files = [os.path.abspath(filename) for filename in args.files] |
| 181 | if args.commit_msg_filename is not None: |
| 182 | args.commit_msg_filename = os.path.abspath( |
| 183 | args.commit_msg_filename, |
| 184 | ) |
| 185 | if args.command == 'try-repo' and os.path.exists(args.repo): |
| 186 | args.repo = os.path.abspath(args.repo) |
| 187 | |
| 188 | toplevel = git.get_root() |
| 189 | os.chdir(toplevel) |
| 190 | |
| 191 | args.config = os.path.relpath(args.config) |
| 192 | if args.command in {'run', 'try-repo'}: |
| 193 | args.files = [os.path.relpath(filename) for filename in args.files] |
| 194 | if args.commit_msg_filename is not None: |
| 195 | args.commit_msg_filename = os.path.relpath( |
| 196 | args.commit_msg_filename, |
| 197 | ) |
| 198 | if args.command == 'try-repo' and os.path.exists(args.repo): |
| 199 | args.repo = os.path.relpath(args.repo) |
| 200 | |
| 201 | |
| 202 | def main(argv: Sequence[str] | None = None) -> int: |