Commit 3e631421 authored by Andrii Shyshkalov's avatar Andrii Shyshkalov Committed by Commit Bot

Gerrit git cl upload: abort early if change is submitted or abandoned.

BUG=689652
R=agable@chromium.org,martiniss@chromium.org

Change-Id: Ib9f5b08f5b31a1519a5f5916042885967a263d88
Reviewed-on: https://chromium-review.googlesource.com/443325Reviewed-by: 's avatarAaron Gable <agable@chromium.org>
Commit-Queue: Andrii Shyshkalov <tandrii@chromium.org>
parent 4dc0b2a3
...@@ -1503,10 +1503,11 @@ class Changelist(object): ...@@ -1503,10 +1503,11 @@ class Changelist(object):
base_branch = self.GetCommonAncestorWithUpstream() base_branch = self.GetCommonAncestorWithUpstream()
git_diff_args = [base_branch, 'HEAD'] git_diff_args = [base_branch, 'HEAD']
# Make sure authenticated to codereview before running potentially expensive # Fast best-effort checks to abort before running potentially
# hooks. It is a fast, best efforts check. Codereview still can reject the # expensive hooks if uploading is likely to fail anyway. Passing these
# authentication during the actual upload. # checks does not guarantee that uploading will not fail.
self._codereview_impl.EnsureAuthenticated(force=options.force) self._codereview_impl.EnsureAuthenticated(force=options.force)
self._codereview_impl.EnsureCanUploadPatchset()
# Apply watchlists on upload. # Apply watchlists on upload.
change = self.GetChange(base_branch, None) change = self.GetChange(base_branch, None)
...@@ -1757,6 +1758,15 @@ class _ChangelistCodereviewBase(object): ...@@ -1757,6 +1758,15 @@ class _ChangelistCodereviewBase(object):
""" """
raise NotImplementedError() raise NotImplementedError()
def EnsureCanUploadPatchset(self):
"""Best effort check that uploading isn't supposed to fail for predictable
reasons.
This method should raise informative exception if uploading shouldn't
proceed.
"""
pass
def CMDUploadChange(self, options, args, change): def CMDUploadChange(self, options, args, change):
"""Uploads a change to codereview.""" """Uploads a change to codereview."""
raise NotImplementedError() raise NotImplementedError()
...@@ -2310,6 +2320,26 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase): ...@@ -2310,6 +2320,26 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
cookie_auth.get_netrc_path(), cookie_auth.get_netrc_path(),
cookie_auth.get_new_password_message(git_host))) cookie_auth.get_new_password_message(git_host)))
def EnsureCanUploadPatchset(self):
"""Best effort check that uploading isn't supposed to fail for predictable
reasons.
This method should raise informative exception if uploading shouldn't
proceed.
"""
if not self.GetIssue():
return
# Warm change details cache now to avoid RPCs later, reducing latency for
# developers.
self.FetchDescription()
status = self._GetChangeDetail()['status']
if status in ('MERGED', 'ABANDONED'):
DieWithError('Change %s has been %s, new uploads are not allowed' %
(self.GetIssueURL(),
'submitted' if status == 'MERGED' else 'abandoned'))
def _PostUnsetIssueProperties(self): def _PostUnsetIssueProperties(self):
"""Which branch-specific properties to erase when unsetting issue.""" """Which branch-specific properties to erase when unsetting issue."""
return ['gerritsquashhash'] return ['gerritsquashhash']
......
...@@ -1152,18 +1152,7 @@ class TestGitCl(TestCase): ...@@ -1152,18 +1152,7 @@ class TestGitCl(TestCase):
'refs/remotes/origin/master'],), 'refs/remotes/origin/master'],),
'fake_ancestor_sha'), 'fake_ancestor_sha'),
# Calls to verify branch point is ancestor # Calls to verify branch point is ancestor
] + (cls._gerrit_ensure_auth_calls(issue=issue) + ] + cls._gerrit_ensure_auth_calls(issue=issue) + ([
cls._git_sanity_checks('fake_ancestor_sha', 'master',
get_remote_branch=False)) + [
((['git', 'rev-parse', '--show-cdup'],), ''),
((['git', 'rev-parse', 'HEAD'],), '12345'),
((['git',
'diff', '--name-status', '--no-renames', '-r',
'fake_ancestor_sha...', '.'],),
'M\t.gitignore\n'),
((['git', 'config', 'branch.master.gerritpatchset'],), CERR1),
] + ([
(('GetChangeDetail', 'chromium-review.googlesource.com', (('GetChangeDetail', 'chromium-review.googlesource.com',
'123456', ['CURRENT_REVISION', 'CURRENT_COMMIT']), '123456', ['CURRENT_REVISION', 'CURRENT_COMMIT']),
{ {
...@@ -1172,7 +1161,20 @@ class TestGitCl(TestCase): ...@@ -1172,7 +1161,20 @@ class TestGitCl(TestCase):
'revisions': { 'sha1_of_current_revision': { 'revisions': { 'sha1_of_current_revision': {
'commit': {'message': fetched_description}, 'commit': {'message': fetched_description},
}}, }},
'status': 'NEW',
}), }),
] if issue else [
]) + cls._git_sanity_checks('fake_ancestor_sha', 'master',
get_remote_branch=False) + [
((['git', 'rev-parse', '--show-cdup'],), ''),
((['git', 'rev-parse', 'HEAD'],), '12345'),
((['git',
'diff', '--name-status', '--no-renames', '-r',
'fake_ancestor_sha...', '.'],),
'M\t.gitignore\n'),
((['git', 'config', 'branch.master.gerritpatchset'],), CERR1),
] + ([
] if issue else [ ] if issue else [
((['git', ((['git',
'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment