Provide nicer user message for missing remote ref

If the remote branch being targetted does not exist, any attempted
rebase will fail with an error that is largely unhelpful for users.

Assuming the preceding fetch succeeded properly, the most common reason
for the remote reference to not exist, is that the user wants the
changes to go to a new branch rather than the default. In this case
provide the user with a more helpful message indicating that if this is
the intention, to run git-review with the option to disable the rebase
in order to get the desired outcome of gerrit creating the branch
desired for the new reviews.

Change-Id: I4c92e901950abf2c879d00660daae3ccce7ddfc8
This commit is contained in:
Darragh Bailey 2014-06-04 11:50:15 +01:00
parent dfdeaa6a6b
commit c162732aa7
2 changed files with 16 additions and 0 deletions

View File

@ -618,6 +618,14 @@ def rebase_changes(branch, remote, interactive=True):
return False
_orig_head = output
cmd = "git show-ref --quiet --verify refs/%s" % remote_branch
(status, output) = run_command_status(cmd)
if status != 0:
printwrap("The branch '%s' does not exist on the given remote '%s'. "
"If these changes are intended to start a new branch, "
"re-run with the '-R' option enabled." % (branch, remote))
sys.exit(1)
if interactive:
cmd = "git rebase -p -i %s" % remote_branch
else:

View File

@ -120,6 +120,14 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase):
review_res = self._run_git_review('-y')
self.assertIn("Processing changes: new: 2", review_res)
def test_rebase_no_remote_branch_msg(self):
"""Test message displayed where no remote branch exists."""
self._run_git_review('-s')
self._run_git('checkout', '-b', 'new_branch')
exc = self.assertRaises(Exception, self._run_git_review, 'new_branch')
self.assertIn("The branch 'new_branch' does not exist on the given "
"remote 'gerrit'", exc.args[0])
def test_need_rebase_no_upload(self):
"""Test change needing a rebase does not upload."""
self._run_git_review('-s')