Ejemplo n.º 1
0
 def clone_from(cls,
                remote_repo_url,
                repo_path,
                proxy=None,
                *args,
                **kwargs):
     """
     Clone a repository from a remote URL into a local path.
     """
     LOG.info("Cloning repository from '%s' into '%s'" %
              (remote_repo_url, repo_path))
     try:
         if proxy:
             git_cmd = git.cmd.Git()
             git_cmd.execute([
                 'git', '-c', "http.proxy='{}'".format(proxy), 'clone',
                 remote_repo_url, repo_path
             ])
             return GitRepository(repo_path)
         else:
             return super(GitRepository,
                          cls).clone_from(remote_repo_url, repo_path, *args,
                                          **kwargs)
     except git.exc.GitCommandError:
         message = "Failed to clone repository"
         LOG.exception(message)
         raise exception.RepositoryError(message=message)
Ejemplo n.º 2
0
    def checkout(self, revision):
        """
        Check out a revision.
        """
        LOG.info("%(name)s: Updating svn repository" % dict(name=self.name))
        try:
            utils.run_command("svn update", cwd=self.working_copy_dir)
        except:
            LOG.debug("%(name)s: Failed to update svn repository" %
                      dict(name=self.name))
            pass
        else:
            LOG.info("%(name)s: Updated svn repository" % dict(name=self.name))

        LOG.info("%(name)s: Checking out revision %(revision)s" %
                 dict(name=self.name, revision=revision))
        try:
            utils.run_command("svn checkout %(repo_url)s@%(revision)s ." %
                              dict(repo_url=self.url, revision=revision),
                              cwd=self.working_copy_dir)
        except:
            message = ("Could not find revision %s at %s repository" %
                       (revision, self.name))
            LOG.exception(message)
            raise exception.RepositoryError(message=message)
Ejemplo n.º 3
0
    def checkout_from(cls, remote_repo_url, repo_path):
        """
        Checkout a repository from a remote URL into a local path.
        """
        LOG.info("Checking out repository from '%s' into '%s'" %
                 (remote_repo_url, repo_path))

        command = 'svn checkout '

        CONF = config.get_config().CONF
        proxy = CONF.get('common').get('http_proxy')

        if proxy:
            url = urlparse.urlparse(proxy)
            host = url.scheme + '://' + url.hostname
            port = url.port
            options = ("servers:global:http-proxy-host='%s'" % host,
                       "servers:global:http-proxy-port='%s'" % port)

            proxy_conf = ['--config-option ' + option for option in options]

            command += ' '.join(proxy_conf) + ' '

        command += '%(remote_repo_url)s %(local_target_path)s' % \
                   {'remote_repo_url': remote_repo_url,
                    'local_target_path': repo_path}
        try:
            utils.run_command(command)
            return SvnRepository(remote_repo_url, repo_path)
        except:
            message = "Failed to clone repository"
            LOG.exception(message)
            raise exception.RepositoryError(message=message)
Ejemplo n.º 4
0
    def checkout(self, ref_name):
        """
        Check out the reference name, resetting the index state.
        The reference may be a branch, tag or commit.
        """
        LOG.info("%(name)s: Fetching repository remotes" %
                 dict(name=self.name))
        for remote in self.remotes:
            try:
                remote.fetch()
            except git.exc.GitCommandError:
                LOG.debug("Failed to fetch %s remote for %s" %
                          (remote.name, self.name))
                pass
            else:
                LOG.info("Fetched changes for %s" % remote.name)

        LOG.info("%(name)s: Checking out reference %(ref)s" %
                 dict(name=self.name, ref=ref_name))
        self.head.reference = self._get_reference(ref_name)
        try:
            self.head.reset(index=True, working_tree=True)
        except git.exc.GitCommandError:
            message = ("Could not find reference %s at %s repository" %
                       (ref_name, self.name))
            LOG.exception(message)
            raise exception.RepositoryError(message=message)

        self._update_submodules()
Ejemplo n.º 5
0
 def _get_reference(self, ref_name):
     """
     Get repository commit based on a reference name (branch, tag,
     commit ID). Remote references have higher priority than local
     references.
     """
     refs_names = []
     for remote in self.remotes:
         refs_names.append(os.path.join(remote.name, ref_name))
     refs_names.append(ref_name)
     for ref_name in refs_names:
         try:
             return self.commit(ref_name)
         except gitdb.exc.BadName:
             pass
     else:
         raise exception.RepositoryError(
             message="Reference not found in repository")
    def checkout(self, ref_name, refspecs=None):
        """
        Check out the reference name, resetting the index state.
        The reference may be a branch, tag or commit.

        Args:
            ref_name (str): name of the reference. May be a branch, tag,
                commit ID, etc.
            refspecs ([str]): pattern mappings from remote references to
                local references. Refer to Git documentation at
                https://git-scm.com/book/id/v2/Git-Internals-The-Refspec
        """
        LOG.info("%(name)s: Fetching repository remote %(remote)s" %
                 dict(name=self.name, remote=MAIN_REMOTE_NAME))
        if refspecs is not None:
            LOG.debug("Using custom ref specs %s" % refspecs)
        main_remote = self.remote(MAIN_REMOTE_NAME)
        try:
            main_remote.fetch(refspecs)
        except git.exc.GitCommandError:
            LOG.error("Failed to fetch %s remote for %s" %
                      (MAIN_REMOTE_NAME, self.name))
            raise

        commit_id = self._get_reference(ref_name)
        LOG.info("%(name)s: Checking out reference %(ref)s pointing to commit "
                 "%(commit)s" %
                 dict(name=self.name, ref=ref_name, commit=commit_id))
        self.head.reference = commit_id
        try:
            self.head.reset(index=True, working_tree=True)
        except git.exc.GitCommandError:
            message = ("Could not find reference %s at %s repository" %
                       (ref_name, self.name))
            LOG.exception(message)
            raise exception.RepositoryError(message=message)

        self._update_submodules()