Fix git-review -d behavior with branches
- Fix fetch_review to use the information from the correct branch. - Improve the unit test for git review -d to exercice the backport workflow using branches. Change-Id: I47c2e0149648a1f4f558e7f1ad6204f7f551865a Closes-Bug: #2000294
This commit is contained in:
parent
aaa416e697
commit
47cbee9687
@ -1104,7 +1104,16 @@ def fetch_review(review, masterbranch, remote):
|
||||
|
||||
if not len(review_infos):
|
||||
raise ReviewInformationNotFound(review)
|
||||
review_info = review_infos[0]
|
||||
for info in review_infos:
|
||||
if 'branch' in info and info['branch'] == masterbranch:
|
||||
if VERBOSE:
|
||||
print('Using review info from branch %s' % info['branch'])
|
||||
review_info = info
|
||||
break
|
||||
else:
|
||||
review_info = review_infos[0]
|
||||
if VERBOSE and 'branch' in review_info:
|
||||
print('Using default branch %s' % review_info['branch'])
|
||||
|
||||
try:
|
||||
if patchset_number is None:
|
||||
|
@ -198,6 +198,15 @@ class BaseGitReviewTestCase(testtools.TestCase, GerritHelpers):
|
||||
self._run_git('add', '--all')
|
||||
self._run_git('commit', '-m', 'Test file and .gitreview added.')
|
||||
self._run_git('push', 'origin', 'master')
|
||||
# push a branch to gerrit
|
||||
self._run_git('checkout', '-b', 'testbranch')
|
||||
utils.write_to_file(self._dir('test', 'test_file.txt'),
|
||||
'test file branched'.encode())
|
||||
self._create_gitreview_file(defaultbranch='testbranch')
|
||||
self._run_git('add', '--all')
|
||||
self._run_git('commit', '-m', 'Branched.')
|
||||
self._run_git('push', 'origin', 'testbranch')
|
||||
# cleanup
|
||||
shutil.rmtree(self.test_dir)
|
||||
|
||||
# go to the just cloned test Git repository
|
||||
|
@ -118,7 +118,20 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase):
|
||||
self._run_git_review('-d', change_id)
|
||||
self.assertIn('test commit message', self._run_git('log', '-1'))
|
||||
|
||||
# second download should also work correct
|
||||
# test backport branch
|
||||
self._run_git('checkout', '-b', 'mybackport',
|
||||
self._remote + '/' + 'testbranch')
|
||||
self._simple_change('test file modified in branch',
|
||||
'test branch commit message\n\nChange-Id: %s' %
|
||||
change_id)
|
||||
self._run_git_review('testbranch')
|
||||
self._run_git('checkout', 'master')
|
||||
self._run_git_review('-d', change_id, 'testbranch')
|
||||
self.assertIn('test branch commit message',
|
||||
self._run_git('log', '-1'))
|
||||
|
||||
# second download should also work correctly
|
||||
self._run_git('checkout', 'master')
|
||||
self._run_git_review('-d', change_id)
|
||||
self.assertIn('test commit message', self._run_git('show', 'HEAD'))
|
||||
self.assertNotIn('test commit message',
|
||||
|
Loading…
x
Reference in New Issue
Block a user