Commit d08043c7 authored by Stefan Zager's avatar Stefan Zager Committed by Commit Bot

Allow 'git cl patch' when not on a branch.

R=agable@chromium.org,tandrii@chromium.org

Bug:
Change-Id: I83c285c333a21f2ed0138723a1cd5347e65f41ae
Reviewed-on: https://chromium-review.googlesource.com/710742
Commit-Queue: Stefan Zager <szager@chromium.org>
Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
Reviewed-by: 's avatarAaron Gable <agable@chromium.org>
parent b40a4514
......@@ -2828,11 +2828,19 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
'uploading changes based on top of this branch difficult.\n'
'If you want to do that, use "git cl patch --force" instead.')
self.SetIssue(parsed_issue_arg.issue)
self.SetPatchset(patchset)
fetched_hash = RunGit(['rev-parse', 'FETCH_HEAD']).strip()
self._GitSetBranchConfigValue('last-upload-hash', fetched_hash)
self._GitSetBranchConfigValue('gerritsquashhash', fetched_hash)
if self.GetBranch():
self.SetIssue(parsed_issue_arg.issue)
self.SetPatchset(patchset)
fetched_hash = RunGit(['rev-parse', 'FETCH_HEAD']).strip()
self._GitSetBranchConfigValue('last-upload-hash', fetched_hash)
self._GitSetBranchConfigValue('gerritsquashhash', fetched_hash)
else:
print('WARNING: You are in detached HEAD state.\n'
'The patch has been applied to your checkout, but you will not be '
'able to upload a new patch set to the gerrit issue.\n'
'Try using the \'-b\' option if you would like to work on a '
'branch and/or upload a new patch set.')
return 0
@staticmethod
......@@ -5402,8 +5410,6 @@ def CMDpatch(parser, args):
RunGit(['branch', '-D', options.newbranch],
stderr=subprocess2.PIPE, error_ok=True)
RunGit(['new-branch', options.newbranch])
elif not GetCurrentBranch():
DieWithError('A branch is required to apply patch. Hint: use -b option.')
cl = Changelist(**cl_kwargs)
......
......@@ -2068,8 +2068,6 @@ class TestGitCl(TestCase):
if new_branch:
self.calls = [((['git', 'new-branch', 'master'],), ''),]
else:
self.calls = [((['git', 'symbolic-ref', 'HEAD'],), 'master')]
if default_codereview:
if not force_codereview:
......@@ -2267,7 +2265,6 @@ class TestGitCl(TestCase):
self.mock(git_cl.gerrit_util, 'GetChangeDetail', notExists)
self.calls = [
((['git', 'symbolic-ref', 'HEAD'],), 'master'),
((['git', 'symbolic-ref', 'HEAD'],), 'master'),
((['git', 'config', 'branch.master.rietveldissue'],), CERR1),
((['git', 'config', 'branch.master.gerritissue'],), CERR1),
......
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