From 60fdc5cad126fb5664ee957b91edd1c304bfc513 Mon Sep 17 00:00:00 2001 From: Theodore Dubois Date: Tue, 30 Jul 2019 12:14:25 -0700 Subject: [PATCH] Add repo start option to create the branch based off HEAD This makes it way easier to recover from forgetting to run repo start before committing: just run `repo start -b new-branch`, instead of all that tedious mucking around with reflogs. Change-Id: I56d49dce5d027e28fbba0507ac10cd763ccfc36d Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/232712 Reviewed-by: Mike Frysinger Reviewed-by: David Pursehouse Tested-by: Mike Frysinger --- project.py | 8 ++++++-- subcmds/start.py | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/project.py b/project.py index 8212e0c0..4076bc5d 100755 --- a/project.py +++ b/project.py @@ -1697,7 +1697,7 @@ class Project(object): # Branch Management ## - def StartBranch(self, name, branch_merge=''): + def StartBranch(self, name, branch_merge='', revision=None): """Create a new branch off the manifest's revision. """ if not branch_merge: @@ -1718,7 +1718,11 @@ class Project(object): branch.merge = branch_merge if not branch.merge.startswith('refs/') and not ID_RE.match(branch_merge): branch.merge = R_HEADS + branch_merge - revid = self.GetRevisionId(all_refs) + + if revision is None: + revid = self.GetRevisionId(all_refs) + else: + revid = self.work_git.rev_parse(revision) if head.startswith(R_HEADS): try: diff --git a/subcmds/start.py b/subcmds/start.py index 5d4c9c01..6ec0b2ce 100644 --- a/subcmds/start.py +++ b/subcmds/start.py @@ -40,6 +40,10 @@ revision specified in the manifest. p.add_option('--all', dest='all', action='store_true', help='begin branch in all projects') + p.add_option('-r', '--rev', '--revision', dest='revision', + help='point branch at this revision instead of upstream') + p.add_option('--head', dest='revision', action='store_const', const='HEAD', + help='abbreviation for --rev HEAD') def ValidateOptions(self, opt, args): if not args: @@ -108,7 +112,8 @@ revision specified in the manifest. else: branch_merge = self.manifest.default.revisionExpr - if not project.StartBranch(nb, branch_merge=branch_merge): + if not project.StartBranch( + nb, branch_merge=branch_merge, revision=opt.revision): err.append(project) pm.end()