Lazily clones the `git` repository denoted by `clone_url` into the `target_dir` or pulls latest changes if the `target_dir` exists (naively assumes that a working clone exists there) and optionally checks out a revision `revision` after cloning or in the existing clone if `revision` is n
(clone_url: str, target_dir: str, revision: Union[str, None] = None)
| 599 | |
| 600 | |
| 601 | def git_clone_or_pull_repository(clone_url: str, target_dir: str, revision: Union[str, None] = None) -> None: |
| 602 | """Lazily clones the `git` repository denoted by `clone_url` into |
| 603 | the `target_dir` or pulls latest changes if the `target_dir` exists (naively assumes |
| 604 | that a working clone exists there) and optionally checks out a revision |
| 605 | `revision` after cloning or in the existing clone if `revision` is not |
| 606 | `None`.""" |
| 607 | if not os.path.exists(target_dir): |
| 608 | logger.info(f"cloning '{clone_url}' into '{target_dir}'") |
| 609 | run([git, "clone", "--recursive", clone_url, target_dir]) |
| 610 | else: |
| 611 | logger.info(f"directory '{target_dir}' already cloned. Pulling latest changes.") |
| 612 | run([git, "-C", target_dir, "fetch", "--all", "--tags", "--force"]) |
| 613 | |
| 614 | # detect whether we are on a branch and pull |
| 615 | if run([git, "rev-parse", "--abbrev-ref", "HEAD"], cwd=target_dir) != "HEAD": |
| 616 | run([git, "pull", clone_url], cwd=target_dir) |
| 617 | |
| 618 | if revision != None: |
| 619 | run([git, "reset", "--hard"], cwd=target_dir) |
| 620 | run([git, "fetch", "--all"], cwd=target_dir) |
| 621 | run([git, "checkout", revision], cwd=target_dir) |
| 622 | |
| 623 | |
| 624 | def build_dependency( |
no test coverage detected