download: support -x when cherry-picking
This is a pretty common option for people to want too use, so include
it as a pass-thru option when cherry-picking.
Bug: https://crbug.com/gerrit/9418
Change-Id: I2a24c1ed7544541719caa4d3c0574347a151a1b0
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/259853
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
diff --git a/project.py b/project.py
index a58af4f..d35ad52 100644
--- a/project.py
+++ b/project.py
@@ -2681,10 +2681,12 @@
if self._allrefs:
raise GitError('%s checkout %s ' % (self.name, rev))
- def _CherryPick(self, rev, ffonly=False):
+ def _CherryPick(self, rev, ffonly=False, record_origin=False):
cmd = ['cherry-pick']
if ffonly:
cmd.append('--ff')
+ if record_origin:
+ cmd.append('-x')
cmd.append(rev)
cmd.append('--')
if GitCommand(self, cmd).Wait() != 0:
diff --git a/subcmds/download.py b/subcmds/download.py
index 12d9952..db9595a 100644
--- a/subcmds/download.py
+++ b/subcmds/download.py
@@ -40,6 +40,8 @@
p.add_option('-c', '--cherry-pick',
dest='cherrypick', action='store_true',
help="cherry-pick instead of checkout")
+ p.add_option('-x', '--record-origin', action='store_true',
+ help='pass -x when cherry-picking')
p.add_option('-r', '--revert',
dest='revert', action='store_true',
help="revert instead of checkout")
@@ -78,6 +80,14 @@
project = self.GetProjects([a])[0]
return to_get
+ def ValidateOptions(self, opt, args):
+ if opt.record_origin:
+ if not opt.cherrypick:
+ self.OptionParser.error('-x only makes sense with --cherry-pick')
+
+ if opt.ffonly:
+ self.OptionParser.error('-x and --ff are mutually exclusive options')
+
def Execute(self, opt, args):
for project, change_id, ps_id in self._ParseChangeIds(args):
dl = project.DownloadPatchSet(change_id, ps_id)
@@ -101,7 +111,8 @@
print(' %s' % (c), file=sys.stderr)
if opt.cherrypick:
try:
- project._CherryPick(dl.commit, ffonly=opt.ffonly)
+ project._CherryPick(dl.commit, ffonly=opt.ffonly,
+ record_origin=opt.record_origin)
except GitError:
print('[%s] Could not complete the cherry-pick of %s'
% (project.name, dl.commit), file=sys.stderr)