def _adjust_args_and_chdir(args): # `--config` was specified relative to the non-root working directory if os.path.exists(args.config): args.config = os.path.abspath(args.config) if args.command in {'run', 'try-repo'}: args.files = [os.path.abspath(filename) for filename in args.files] if args.command == 'try-repo' and os.path.exists(args.repo): args.repo = os.path.abspath(args.repo) try: toplevel = git.get_root() except CalledProcessError: raise FatalError( 'git failed. Is it installed, and are you in a Git repository ' 'directory?', ) else: if toplevel == '': # pragma: no cover (old git) raise FatalError( 'git toplevel unexpectedly empty! make sure you are not ' 'inside the `.git` directory of your repository.', ) else: os.chdir(toplevel) args.config = os.path.relpath(args.config) if args.command in {'run', 'try-repo'}: args.files = [os.path.relpath(filename) for filename in args.files] if args.command == 'try-repo' and os.path.exists(args.repo): args.repo = os.path.relpath(args.repo)
def _adjust_args_and_chdir(args: argparse.Namespace) -> None: # `--config` was specified relative to the non-root working directory if os.path.exists(args.config): args.config = os.path.abspath(args.config) if args.command in {"run", "try-repo"}: args.files = [os.path.abspath(filename) for filename in args.files] if args.command == "try-repo" and os.path.exists(args.repo): args.repo = os.path.abspath(args.repo) try: toplevel = git.get_root() except CalledProcessError: raise FatalError( "git failed. Is it installed, and are you in a Git repository " "directory?", ) else: if toplevel == "": # pragma: no cover (old git) raise FatalError( "git toplevel unexpectedly empty! make sure you are not " "inside the `.git` directory of your repository.", ) else: os.chdir(toplevel) args.config = os.path.relpath(args.config) if args.command in {"run", "try-repo"}: args.files = [os.path.relpath(filename) for filename in args.files] if args.command == "try-repo" and os.path.exists(args.repo): args.repo = os.path.relpath(args.repo)
def get_root(): try: return cmd_output('git', 'rev-parse', '--show-toplevel')[1].strip() except CalledProcessError: raise FatalError( 'git failed. Is it installed, and are you in a Git repository ' 'directory?', )
def _adjust_args_and_chdir(args): # `--config` was specified relative to the non-root working directory if os.path.exists(args.config): args.config = os.path.abspath(args.config) if args.command in {'run', 'try-repo'}: args.files = [os.path.abspath(filename) for filename in args.files] if args.command == 'try-repo' and os.path.exists(args.repo): args.repo = os.path.abspath(args.repo) try: os.chdir(git.get_root()) except CalledProcessError: raise FatalError( 'git failed. Is it installed, and are you in a Git repository ' 'directory?', ) args.config = os.path.relpath(args.config) if args.command in {'run', 'try-repo'}: args.files = [os.path.relpath(filename) for filename in args.files] if args.command == 'try-repo' and os.path.exists(args.repo): args.repo = os.path.relpath(args.repo)