Commit 9b7fd71c authored by tandrii@chromium.org's avatar tandrii@chromium.org

git cl issue 0 should really clear issue.

It used to clear just issue number and patchset, but that's not
all state that associates a given branch with codereview site.

R=andybons@chromium.org
BUG=609295

Review-Url: https://codereview.chromium.org/2032433003

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@300683 0039d316-1c4b-4281-b951-d872f2087c98
parent 3b558a01
......@@ -1255,11 +1255,15 @@ class Changelist(object):
if codereview_server:
RunGit(['config', codereview_setting, codereview_server])
else:
current_issue = self.GetIssue()
if current_issue:
RunGit(['config', '--unset', issue_setting])
# Reset it regardless. It doesn't hurt.
config_settings = [issue_setting, self._codereview_impl.PatchsetSetting()]
for prop in (['last-upload-hash'] +
self._codereview_impl._PostUnsetIssueProperties()):
config_settings.append('branch.%s.%s' % (self.GetBranch(), prop))
for setting in config_settings:
RunGit(['config', '--unset', setting], error_ok=True)
self.issue = None
self.SetPatchset(None)
self.patchset = None
def GetChange(self, upstream_branch, author):
if not self.GitSanityChecks(upstream_branch):
......@@ -1497,6 +1501,10 @@ class _ChangelistCodereviewBase(object):
"""Returns name of git config setting which stores issue number."""
raise NotImplementedError()
def _PostUnsetIssueProperties(self):
"""Which branch-specific properties to erase when unsettin issue."""
raise NotImplementedError()
def GetRieveldObjForPresubmit(self):
# This is an unfortunate Rietveld-embeddedness in presubmit.
# For non-Rietveld codereviews, this probably should return a dummy object.
......@@ -1738,6 +1746,10 @@ class _RietveldChangelistImpl(_ChangelistCodereviewBase):
return 'branch.%s.rietveldserver' % branch
return None
def _PostUnsetIssueProperties(self):
"""Which branch-specific properties to erase when unsetting issue."""
return ['rietveldserver']
def GetRieveldObjForPresubmit(self):
return self.RpcServer()
......@@ -2094,6 +2106,13 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
return 'branch.%s.gerritserver' % branch
return None
def _PostUnsetIssueProperties(self):
"""Which branch-specific properties to erase when unsetting issue."""
return [
'gerritserver',
'gerritsquashhash',
]
def GetRieveldObjForPresubmit(self):
class ThisIsNotRietveldIssue(object):
def __nonzero__(self):
......
......@@ -1453,6 +1453,24 @@ class TestGitCl(TestCase):
self.assertEqual(0, git_cl.main(['description', '-n', '-']))
self.assertEqual('hi\n\t there\n\nman', ChangelistMock.desc)
def test_cmd_issue_erase_existing(self):
out = StringIO.StringIO()
self.mock(git_cl.sys, 'stdout', out)
self.calls = [
((['git', 'symbolic-ref', 'HEAD'],), 'feature'),
((['git', 'config', 'branch.feature.rietveldissue'],), ''),
((['git', 'config', 'branch.feature.gerritissue'],), '123'),
((['git', 'config', '--unset', 'branch.feature.gerritissue'],), ''),
((['git', 'config', '--unset', 'branch.feature.gerritpatchset'],), ''),
# Let this command raise exception (retcode=1) - it should be ignored.
((['git', 'config', '--unset', 'branch.feature.last-upload-hash'],),
'', subprocess2.CalledProcessError(1, '', '', '', '')),
((['git', 'config', '--unset', 'branch.feature.gerritserver'],), ''),
((['git', 'config', '--unset', 'branch.feature.gerritsquashhash'],),
''),
]
self.assertEqual(0, git_cl.main(['issue', '0']))
if __name__ == '__main__':
git_cl.logging.basicConfig(
......
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