Пример #1
0
    def test_raises_version_control_error_when_git_checkout_fails(
            self, mock_repo):
        mock_repo.git.checkout.side_effect = git_utils.git.exc.GitCommandError(
            "git checkout", 255)

        with self.assertRaises(VersionControlError):
            git_utils.checkout(mock_repo, "bad")
Пример #2
0
 def checkout(self, force: bool) -> None:
     """Check out all resolved libs to revision specified in .lib files."""
     for lib in self.iter_resolved():
         repo = git_utils.init(lib.source_code_path)
         git_ref = lib.get_git_reference()
         if git_ref.ref:
             git_utils.checkout(repo, git_ref.ref, force=force)
Пример #3
0
    def checkout(self, force: bool) -> None:
        """Check out all resolved libs to revision specified in .lib files."""
        for lib in self.iter_resolved():
            repo = git_utils.get_repo(lib.source_code_path)
            git_ref = lib.get_git_reference()

            if not git_ref.ref:
                git_ref.ref = git_utils.get_default_branch(repo)

            git_utils.fetch(repo, git_ref.ref)
            git_utils.checkout(repo, "FETCH_HEAD", force=force)
Пример #4
0
    def fetch(self) -> None:
        """Recursively clone all dependencies defined in .lib files."""
        for lib in self.iter_unresolved():
            git_ref = lib.get_git_reference()
            logger.info(f"Resolving library reference {git_ref.repo_url}.")
            repo = git_utils.clone(git_ref.repo_url, lib.source_code_path)
            if git_ref.ref:
                logger.info(f"Checking out revision {git_ref.ref} for library {git_ref.repo_url}.")
                git_utils.checkout(repo, git_ref.ref)

        # Check if we find any new references after cloning dependencies.
        if list(self.iter_unresolved()):
            self.fetch()
Пример #5
0
    def checkout(self, force: bool) -> None:
        """Check out all resolved libs to revision specified in .lib files."""
        for lib in self.iter_resolved():
            repo = git_utils.get_repo(lib.source_code_path)
            git_ref = lib.get_git_reference()

            if not git_ref.ref:
                repo.git.fetch()
                git_ref.ref = git_utils.get_default_branch(repo)
            else:
                # Fetch only the requested ref
                repo.git.fetch("origin", git_ref.ref)

            git_utils.checkout(repo, git_ref.ref, force=force)
Пример #6
0
def _clone_at_ref(url: str, path: Path, ref: str) -> None:
    if ref:
        logger.info(f"Checking out revision {ref} for library {url}.")
        try:
            git_utils.clone(url, path, ref)
        except VersionControlError:
            # We weren't able to clone. Try again without the ref.
            repo = git_utils.clone(url, path)
            # We couldn't clone the ref and had to fall back to cloning
            # just the default branch. Fetch the ref before checkout, so
            # that we have it available locally.
            logger.warning(
                f"No tag or branch with name {ref}. Fetching full repository.")
            git_utils.fetch(repo, ref)
            git_utils.checkout(repo, "FETCH_HEAD")
    else:
        git_utils.clone(url, path)
Пример #7
0
    def test_git_lib_called_with_correct_command(self, mock_repo):
        git_utils.checkout(mock_repo, "master", force=True)

        mock_repo.git.checkout.assert_called_once_with("--force master")