From 915fda130efa14b9314b500d122f9af707518508 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sun, 22 Mar 2020 12:15:20 -0400 Subject: [PATCH] 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 Tested-by: Mike Frysinger --- project.py | 4 +++- subcmds/download.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/project.py b/project.py index a58af4ff..d35ad52d 100644 --- a/project.py +++ b/project.py @@ -2681,10 +2681,12 @@ class Project(object): 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 12d99526..db9595a2 100644 --- a/subcmds/download.py +++ b/subcmds/download.py @@ -40,6 +40,8 @@ If no project is specified try to use current directory as a project. 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 @@ If no project is specified try to use current directory as a project. 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 @@ If no project is specified try to use current directory as a project. 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)