Merge "Ignore newline in bp/bug search in commit message"
This commit is contained in:
commit
dfdeaa6a6b
@ -732,7 +732,14 @@ def get_topic(target_branch):
|
||||
"/".join(branch_parts[2:]))
|
||||
|
||||
log_output = run_command("git log HEAD^1..HEAD")
|
||||
bug_re = r'\b([Bb]ug|[Ll][Pp])\s*[:]?\s*[#]?\s*(\d+)'
|
||||
bug_re = r'''(?x) # verbose regexp
|
||||
\b([Bb]ug|[Ll][Pp]) # bug or lp
|
||||
[ \t\f\v]* # don't want to match newline
|
||||
[:]? # separator if needed
|
||||
[ \t\f\v]* # don't want to match newline
|
||||
[#]? # if needed
|
||||
[ \t\f\v]* # don't want to match newline
|
||||
(\d+) # bug number'''
|
||||
|
||||
match = re.search(bug_re, log_output)
|
||||
if match is not None:
|
||||
@ -740,7 +747,12 @@ def get_topic(target_branch):
|
||||
"for the topic of the change submitted",
|
||||
"bug/%s" % match.group(2))
|
||||
|
||||
bp_re = r'\b([Bb]lue[Pp]rint|[Bb][Pp])\s*[#:]?\s*([0-9a-zA-Z-_]+)'
|
||||
bp_re = r'''(?x) # verbose regexp
|
||||
\b([Bb]lue[Pp]rint|[Bb][Pp]) # a blueprint or bp
|
||||
[ \t\f\v]* # don't want to match newline
|
||||
[#:]? # separator if needed
|
||||
[ \t\f\v]* # don't want to match newline
|
||||
([0-9a-zA-Z-_]+) # any identifier or number'''
|
||||
match = re.search(bp_re, log_output)
|
||||
if match is not None:
|
||||
return use_topic("Using blueprint number %s "
|
||||
|
@ -176,6 +176,14 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase):
|
||||
self.assertIn('rebase', review_res)
|
||||
self.assertEqual(self._run_git('rev-parse', 'HEAD^1'), head)
|
||||
|
||||
def _assert_branch_would_be(self, branch):
|
||||
output = self._run_git_review('-n')
|
||||
# last non-empty line should be:
|
||||
# git push gerrit HEAD:refs/publish/master
|
||||
last_line = output.strip().split('\n')[-1]
|
||||
branch_was = last_line.rsplit(' ', 1)[-1].split('/', 2)[-1]
|
||||
self.assertEqual(branch, branch_was)
|
||||
|
||||
def test_detached_head(self):
|
||||
"""Test on a detached state: we shouldn't have '(detached' as topic."""
|
||||
self._run_git_review('-s')
|
||||
@ -187,12 +195,30 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase):
|
||||
# switch to French, 'git branch' should return '(détaché du HEAD)'
|
||||
lang_env = os.getenv('LANG', 'C')
|
||||
os.environ.update(LANG='fr_FR.UTF-8')
|
||||
review = self._run_git_review('-n')
|
||||
os.environ.update(LANG=lang_env)
|
||||
# reattach
|
||||
self._run_git('checkout', curr_branch)
|
||||
# we should push to '(...)/master', not '(...)/(detached'
|
||||
self.assertTrue(review.strip().split('\n')[-1].endswith(curr_branch))
|
||||
try:
|
||||
self._assert_branch_would_be(curr_branch)
|
||||
finally:
|
||||
os.environ.update(LANG=lang_env)
|
||||
|
||||
def test_bug_topic(self):
|
||||
self._run_git_review('-s')
|
||||
self._simple_change('a change', 'new change for bug 123')
|
||||
self._assert_branch_would_be('master/bug/123')
|
||||
|
||||
def test_bug_topic_newline(self):
|
||||
self._run_git_review('-s')
|
||||
self._simple_change('a change', 'new change not for bug\n123')
|
||||
self._assert_branch_would_be('master')
|
||||
|
||||
def test_bp_topic(self):
|
||||
self._run_git_review('-s')
|
||||
self._simple_change('a change', 'new change for blueprint asdf')
|
||||
self._assert_branch_would_be('master/bp/asdf')
|
||||
|
||||
def test_bp_topic_newline(self):
|
||||
self._run_git_review('-s')
|
||||
self._simple_change('a change', 'new change not for bluepring\nasdf')
|
||||
self._assert_branch_would_be('master')
|
||||
|
||||
def test_git_review_l(self):
|
||||
self._run_git_review('-s')
|
||||
|
Loading…
x
Reference in New Issue
Block a user