Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- revert_shortlog_regex = re.compile('^Revert\s\"[\S+\s*]*\"')
- headline_regex = re.compile(
- '^This reverts commit [0-9a-f]{40}')
- sha_regex = re.compile(r'\b[0-9a-f]{40}\b')
- if not allow_revert_commits and revert_shortlog_regex.match(shortlog):
- reverted_shortlog = shortlog.lstrip('Revert ')
- if len(body) != 0:
- body = body.strip('\n')
- blankline = body.find('\n\n')
- headline = body[:blankline] if blankline != -1 else body
- if headline_regex.match(headline):
- commit_sha = re.search(sha_regex, headline)
- commit_sha = commit_sha.group(0)
- command = 'git log -n 1 ' + str(commit_sha)
- rstdout, rstderr = run_shell_command(command)
- if rstderr:
- self.err('git:', repr(stderr))
- yield Result(self, 'Invalid revert commit.')
- rstdout = rstdout.rstrip('\n')
- rpos = rstdout.find('\n')
- old_shortlog = rstdout[:rpos] if rpos != -1 else rstdout
- if old_shortlog != reverted_shortlog:
- yield Result(self, 'Shortlog of revert commit does \
- not match the original commit.')
- reason = body[blankline+1:] if blankline != -1 else ''
- if len(reason) == 0:
- yield Result(self, 'Revert commit does not have a reason.')
- elif len(reason) > 50:
- yield Result(self, 'Reason of revert commit contains too \
- long lines.')
- else:
- yield Result(self, 'Revert commit does not have a reason.')
Add Comment
Please, Sign In to add comment