فهرست منبع

download: add a --branch option

This allows people to quickly create new branches when pulling down
changes rather than having to juggle the git calls themselves.

Bug: https://crbug.com/gerrit/11609
Change-Id: Ie6a4d05e9f4e9347fe7f7119c768e6446563ae65
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/259855
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
Mike Frysinger 5 سال پیش
والد
کامیت
78964472ad
1فایلهای تغییر یافته به همراه11 افزوده شده و 1 حذف شده
  1. 11 1
      subcmds/download.py

+ 11 - 1
subcmds/download.py

@@ -37,6 +37,8 @@ If no project is specified try to use current directory as a project.
 """
 
   def _Options(self, p):
+    p.add_option('-b', '--branch',
+                 help='create a new branch first')
     p.add_option('-c', '--cherry-pick',
                  dest='cherrypick', action='store_true',
                  help="cherry-pick instead of checkout")
@@ -119,6 +121,11 @@ If no project is specified try to use current directory as a project.
       else:
         mode = 'checkout'
 
+      # We'll combine the branch+checkout operation, but all the rest need a
+      # dedicated branch start.
+      if opt.branch and mode != 'checkout':
+        project.StartBranch(opt.branch)
+
       try:
         if opt.cherrypick:
           project._CherryPick(dl.commit, ffonly=opt.ffonly,
@@ -128,7 +135,10 @@ If no project is specified try to use current directory as a project.
         elif opt.ffonly:
           project._FastForward(dl.commit, ffonly=True)
         else:
-          project._Checkout(dl.commit)
+          if opt.branch:
+            project.StartBranch(opt.branch, revision=dl.commit)
+          else:
+            project._Checkout(dl.commit)
 
       except GitError:
         print('[%s] Could not complete the %s of %s'