Ejemplo n.º 1
0
def _git(*command_parts, **kwargs):
    """ Convenience function for running git commands. Automatically deals with exceptions and unicode. """
    git_kwargs = {'_tty_out': False}
    git_kwargs.update(kwargs)
    try:
        LOG.debug(sstr(command_parts))
        result = sh.git(*command_parts, **git_kwargs)  # pylint: disable=unexpected-keyword-arg
        # If we reach this point and the result has an exit_code that is larger than 0, this means that we didn't
        # get an exception (which is the default sh behavior for non-zero exit codes) and so the user is expecting
        # a non-zero exit code -> just return the entire result
        if hasattr(result, 'exit_code') and result.exit_code > 0:
            return result
        return ustr(result)
    except CommandNotFound:
        raise GitNotInstalledError()
    except ErrorReturnCode as e:  # Something went wrong while executing the git command
        error_msg = e.stderr.strip()
        error_msg_lower = error_msg.lower()
        if '_cwd' in git_kwargs and b"not a git repository" in error_msg_lower:
            error_msg = u"{0} is not a git repository.".format(
                git_kwargs['_cwd'])
            raise GitContextError(error_msg)

        if (b"does not have any commits yet" in error_msg_lower
                or b"ambiguous argument 'head': unknown revision"
                in error_msg_lower):
            raise GitContextError(
                u"Current branch has no commits. Gitlint requires at least one commit to function."
            )

        raise GitExitCodeError(e.full_cmd, error_msg)
Ejemplo n.º 2
0
 def __unicode__(self):
     format_str = (u"--- Commit Message ----\n%s\n"
                   u"--- Meta info ---------\n"
                   u"Author: %s <%s>\nDate:   %s\n"
                   u"is-merge-commit:  %s\nis-fixup-commit:  %s\n"
                   u"is-squash-commit: %s\nis-revert-commit: %s\n"
                   u"Branches: %s\n"
                   u"Changed Files: %s\n"
                   u"-----------------------")  # pragma: no cover
     date_str = arrow.get(
         self.date).format(GIT_TIMEFORMAT) if self.date else None
     return format_str % (
         ustr(self.message), self.author_name, self.author_email, date_str,
         self.is_merge_commit, self.is_fixup_commit, self.is_squash_commit,
         self.is_revert_commit, sstr(self.branches), sstr(
             self.changed_files))  # pragma: no cover
Ejemplo n.º 3
0
    def validate(self, commit):
        violations = [
            RuleViolation(self.id, u"GitCommit.branches: {0}".format(sstr(commit.branches)), line_nr=1),
            RuleViolation(self.id, u"GitCommit.custom_prop: {0}".format(commit.custom_prop), line_nr=1),
        ]

        return violations
Ejemplo n.º 4
0
    def validate(self, _):
        violations = [
            RuleViolation(self.id, u"int-öption: {0}".format(self.options[u'int-öption'].value), line_nr=1),
            RuleViolation(self.id, u"str-öption: {0}".format(self.options[u'str-öption'].value), line_nr=1),
            RuleViolation(self.id, u"list-öption: {0}".format(sstr(self.options[u'list-öption'].value)), line_nr=1),
        ]

        return violations
Ejemplo n.º 5
0
    def validate(self, commit):
        violations = []
        allowed_branch_prefixes = self.options['branch-prefixes'].value
        for branch in commit.branches:
            valid_branch_name = False

            for allowed_prefix in allowed_branch_prefixes:
                if branch.startswith(allowed_prefix):
                    valid_branch_name = True
                    break

            if not valid_branch_name:
                msg = "Branch name '{0}' does not start with one of {1}".format(
                    branch, utils.sstr(allowed_branch_prefixes))
                violations.append(RuleViolation(self.id, msg, line_nr=1))

        return violations
Ejemplo n.º 6
0
    def validate(self, commit):
        self.log.debug(
            "BranchNamingConventions: This line will be visible when running `gitlint --debug`"
        )

        violations = []
        allowed_branch_prefixes = self.options['branch-prefixes'].value
        for branch in commit.branches:
            valid_branch_name = False

            for allowed_prefix in allowed_branch_prefixes:
                if branch.startswith(allowed_prefix):
                    valid_branch_name = True
                    break

            if not valid_branch_name:
                msg = "Branch name '{0}' does not start with one of {1}".format(
                    branch, utils.sstr(allowed_branch_prefixes))
                violations.append(RuleViolation(self.id, msg, line_nr=1))

        return violations
Ejemplo n.º 7
0
 def __str__(self):
     return sstr(self.__unicode__())  # pragma: no cover
Ejemplo n.º 8
0
 def __str__(self):
     return sstr(self)  # pragma: no cover