コード例 #1
0
    def clone(cls, url, path, depth=None, branch=None, single_branch=False):
        """
        clone repository provided as url to specific path

        :param url: str
        :param path: str
        :param depth: str
        :param branch: str
        :return: instance of Git()
        """
        orig_url = url
        cls.config()
        # git clone doesn't understand urls starting with: git+ssh, git+http, git+https
        url = url2git_repo(url)
        cmd = ["git", "clone", url, path]
        if depth is not None:
            cmd.extend(["--depth", depth])
        if branch is not None:
            cmd.extend(["--branch", branch])
        if single_branch:
            cmd.extend(["--single-branch"])
        try:
            TimedCommand.get_command_output(cmd, graceful=False)
        except TaskError as exc:
            raise TaskError("Unable to clone: %s" % orig_url) from exc
        return cls(path=path)
コード例 #2
0
    def clone(cls,
              url,
              path,
              timeout=300,
              depth=None,
              branch=None,
              single_branch=False):
        """Clone repository provided as url to specific path.

        :param url: str
        :param path: str
        :param timeout: int
        :param depth: str
        :param branch: str
        :param single_branch: bool, only checkout single branch
        :return: instance of Git()
        """
        orig_url = url
        # git clone doesn't understand urls starting with: git+ssh, git+http, git+https
        url = url2git_repo(url)

        orig_path = path
        path = Path(path)
        mode = 0
        if path.is_dir():
            mode = path.stat().st_mode

        cmd = ["git", "clone", url, orig_path]
        if depth is not None:
            cmd.extend(["--depth", depth])
        if branch is not None:
            cmd.extend(["--branch", branch])
        if single_branch:
            cmd.extend(["--single-branch"])
        try:
            cls.config()
            TimedCommand.get_command_output(cmd,
                                            graceful=False,
                                            timeout=timeout)
        except TaskError as exc:
            if not path.is_dir() and mode:
                # 'git clone repo dir/' deletes (no way to turn this off) dir/ if cloning fails.
                # This might confuse caller of this method, so we recreate the dir on error here.
                try:
                    path.mkdir(mode)
                except OSError:
                    logger.error("Unable to re-create dir: %s", str(path))
            raise TaskError("Unable to clone: %s" % orig_url) from exc
        return cls(path=orig_path)
コード例 #3
0
 def test_url2git_repo_ok(self, url, expected_result):
     """Test url2git_repo()."""
     assert url2git_repo(url) == expected_result
コード例 #4
0
 def test_url2git_repo_nok(self, url):
     """Test url2git_repo()."""
     with pytest.raises(ValueError):
         url2git_repo(url)
コード例 #5
0
 def test_url2git_repo_nok(self, url):
     with pytest.raises(ValueError):
         url2git_repo(url)