(tmpdir: str, repo: str, ref: str | None)
| 19 | |
| 20 | |
| 21 | def _repo_ref(tmpdir: str, repo: str, ref: str | None) -> tuple[str, str]: |
| 22 | # if `ref` is explicitly passed, use it |
| 23 | if ref is not None: |
| 24 | return repo, ref |
| 25 | |
| 26 | ref = git.head_rev(repo) |
| 27 | # if it exists on disk, we'll try and clone it with the local changes |
| 28 | if os.path.exists(repo) and git.has_diff('HEAD', repo=repo): |
| 29 | logger.warning('Creating temporary repo with uncommitted changes...') |
| 30 | |
| 31 | shadow = os.path.join(tmpdir, 'shadow-repo') |
| 32 | cmd_output_b('git', 'clone', repo, shadow) |
| 33 | cmd_output_b('git', 'checkout', ref, '-b', '_pc_tmp', cwd=shadow) |
| 34 | |
| 35 | idx = git.git_path('index', repo=shadow) |
| 36 | objs = git.git_path('objects', repo=shadow) |
| 37 | env = dict(os.environ, GIT_INDEX_FILE=idx, GIT_OBJECT_DIRECTORY=objs) |
| 38 | |
| 39 | staged_files = git.get_staged_files(cwd=repo) |
| 40 | if staged_files: |
| 41 | xargs(('git', 'add', '--'), staged_files, cwd=repo, env=env) |
| 42 | |
| 43 | cmd_output_b('git', 'add', '-u', cwd=repo, env=env) |
| 44 | git.commit(repo=shadow) |
| 45 | |
| 46 | return shadow, git.head_rev(shadow) |
| 47 | else: |
| 48 | return repo, ref |
| 49 | |
| 50 | |
| 51 | def try_repo(args: argparse.Namespace) -> int: |
no test coverage detected