Ejemplo n.º 1
0
    def checkout(self, identifier=None):
        self.check_working_dir()

        # Clone or update repository
        if self.repo_exists():
            self.set_remote_url(self.repo_url)
            self.fetch()
        else:
            self.make_clean_working_dir()
            self.clone()

        # Find proper identifier
        if not identifier:
            identifier = self.default_branch or self.fallback_branch

        identifier = self.find_ref(identifier)

        # Checkout the correct identifier for this branch.
        code, out, err = self.checkout_revision(identifier)
        if code != 0:
            return code, out, err

        # Clean any remains of previous checkouts
        self.run('git', 'clean', '-d', '-f', '-f')

        # Update submodules, temporarily allow for skipping submodule checkout
        # step for projects need more submodule configuration.
        if self.are_submodules_available():
            if self.are_submodules_valid():
                self.checkout_submodules()
            else:
                raise RepositoryError(RepositoryError.INVALID_SUBMODULES)
        return code, out, err
Ejemplo n.º 2
0
 def update_submodules(self, config):
     if self.are_submodules_available(config):
         valid, submodules = self.validate_submodules(config)
         if valid:
             self.checkout_submodules(submodules, config)
         else:
             raise RepositoryError(RepositoryError.INVALID_SUBMODULES)
Ejemplo n.º 3
0
 def submodules(self):
     try:
         repo = git.Repo(self.working_dir)
         return list(repo.submodules)
     except InvalidGitRepositoryError:
         raise RepositoryError(
             RepositoryError.INVALID_SUBMODULES_PATH,
         )
Ejemplo n.º 4
0
 def checkout(self, identifier=None):
     super(Backend, self).checkout()
     if not identifier:
         return self.up()
     exit_code, stdout, stderr = self.run('bzr', 'switch', identifier)
     if exit_code != 0:
         raise RepositoryError(
             RepositoryError.FAILED_TO_CHECKOUT.format(identifier))
     return exit_code, stdout, stderr
Ejemplo n.º 5
0
    def checkout_revision(self, revision=None):
        if not revision:
            branch = self.default_branch or self.fallback_branch
            revision = 'origin/%s' % branch

        code, out, err = self.run('git', 'checkout', '--force', revision)
        if code != 0:
            raise RepositoryError(
                RepositoryError.FAILED_TO_CHECKOUT.format(revision), )
        return [code, out, err]
Ejemplo n.º 6
0
 def checkout(self, identifier=None):
     super(Backend, self).checkout()
     if not identifier:
         identifier = 'tip'
     exit_code, stdout, stderr = self.run('hg', 'update', '--clean',
                                          identifier)
     if exit_code != 0:
         raise RepositoryError(
             RepositoryError.FAILED_TO_CHECKOUT.format(identifier))
     return exit_code, stdout, stderr
Ejemplo n.º 7
0
    def checkout(self, identifier=None):
        super().checkout()

        if not identifier:
            return self.up()

        try:
            code, stdout, stderr = self.run('bzr', 'switch', identifier)
            return code, stdout, stderr
        except RepositoryError:
            raise RepositoryError(
                RepositoryError.FAILED_TO_CHECKOUT.format(identifier), )
Ejemplo n.º 8
0
    def run(self, *cmd, **kwargs):
        kwargs.update({
            'cwd': self.working_dir,
            'shell': False,
        })

        try:
            build_cmd = self.environment.run(*cmd, **kwargs)
        except BuildUserError as e:
            # Re raise as RepositoryError to handle it properly from outside
            raise RepositoryError(str(e))

        # Return a tuple to keep compatibility
        return (build_cmd.exit_code, build_cmd.output, build_cmd.error)
Ejemplo n.º 9
0
    def run(self, *cmd, **kwargs):
        kwargs.update({
            'cwd': self.working_dir,
            'shell': False,
        })

        try:
            build_cmd = self.environment.run(*cmd, **kwargs)
        except BuildEnvironmentWarning as e:
            # Re raise as RepositoryError,
            # so isn't logged as ERROR.
            raise RepositoryError(str(e))

        # Return a tuple to keep compatibility
        return (build_cmd.exit_code, build_cmd.output, build_cmd.error)
Ejemplo n.º 10
0
    def run(self, *cmd, **kwargs):
        kwargs.update({
            'cwd': self.working_dir,
            'shell': False,
        })

        try:
            build_cmd = self.environment.run(*cmd, **kwargs)
        except BuildCancelled:
            # Catch ``BuildCancelled`` here and re raise it. Otherwise, if we
            # raise a ``RepositoryError`` then the ``on_failure`` method from
            # Celery won't treat this problem as a ``BuildCancelled`` issue.
            raise BuildCancelled
        except BuildUserError as e:
            # Re raise as RepositoryError to handle it properly from outside
            raise RepositoryError(str(e))

        # Return a tuple to keep compatibility
        return (build_cmd.exit_code, build_cmd.output, build_cmd.error)