Просмотр исходного кода

init: add -o, --origin to name manifest remote

The -o option permits the user to control the name of the manifest's
remote, which normally is hardcoded to be 'origin', but can differ
because we derive it at runtime from the configuration file.

Signed-off-by: Shawn O. Pearce <sop@google.com>
Shawn O. Pearce 16 лет назад
Родитель
Сommit
5f947bba69
4 измененных файлов с 40 добавлено и 15 удалено
  1. 4 1
      manifest_xml.py
  2. 5 3
      project.py
  3. 5 1
      repo
  4. 26 10
      subcmds/init.py

+ 4 - 1
manifest_xml.py

@@ -189,7 +189,10 @@ class XmlManifest(Manifest):
   def _Load(self):
   def _Load(self):
     if not self._loaded:
     if not self._loaded:
       m = self.manifestProject
       m = self.manifestProject
-      b = m.GetBranch(m.CurrentBranch).merge
+      b = m.GetBranch(m.CurrentBranch)
+      if b.remote and b.remote.name:
+        m.remote.name = b.remote.name
+      b = b.merge
       if b is not None and b.startswith(R_HEADS):
       if b is not None and b.startswith(R_HEADS):
         b = b[len(R_HEADS):]
         b = b[len(R_HEADS):]
       self.branch = b
       self.branch = b

+ 5 - 3
project.py

@@ -1442,10 +1442,12 @@ class MetaProject(Project):
     if self.Exists:
     if self.Exists:
       cb = self.CurrentBranch
       cb = self.CurrentBranch
       if cb:
       if cb:
-        base = self.GetBranch(cb).merge
-        if base:
-          self.revisionExpr = base
+        cb = self.GetBranch(cb)
+        if cb.merge:
+          self.revisionExpr = cb.merge
           self.revisionId = None
           self.revisionId = None
+        if cb.remote and cb.remote.name:
+          self.remote.name = cb.remote.name
 
 
   @property
   @property
   def LastFetch(self):
   def LastFetch(self):

+ 5 - 1
repo

@@ -28,7 +28,7 @@ if __name__ == '__main__':
 del magic
 del magic
 
 
 # increment this whenever we make important changes to this script
 # increment this whenever we make important changes to this script
-VERSION = (1, 8)
+VERSION = (1, 9)
 
 
 # increment this if the MAINTAINER_KEYS block is modified
 # increment this if the MAINTAINER_KEYS block is modified
 KEYRING_VERSION = (1,0)
 KEYRING_VERSION = (1,0)
@@ -109,6 +109,10 @@ group = init_optparse.add_option_group('Manifest options')
 group.add_option('-u', '--manifest-url',
 group.add_option('-u', '--manifest-url',
                  dest='manifest_url',
                  dest='manifest_url',
                  help='manifest repository location', metavar='URL')
                  help='manifest repository location', metavar='URL')
+group.add_option('-o', '--origin',
+                 dest='manifest_origin',
+                 help="use REMOTE instead of 'origin' to track upstream",
+                 metavar='REMOTE')
 group.add_option('-b', '--manifest-branch',
 group.add_option('-b', '--manifest-branch',
                  dest='manifest_branch',
                  dest='manifest_branch',
                  help='manifest branch or revision', metavar='REVISION')
                  help='manifest branch or revision', metavar='REVISION')

+ 26 - 10
subcmds/init.py

@@ -62,6 +62,10 @@ to update the working directory files.
     g.add_option('-b', '--manifest-branch',
     g.add_option('-b', '--manifest-branch',
                  dest='manifest_branch',
                  dest='manifest_branch',
                  help='manifest branch or revision', metavar='REVISION')
                  help='manifest branch or revision', metavar='REVISION')
+    g.add_option('-o', '--origin',
+                 dest='manifest_origin',
+                 help="use REMOTE instead of 'origin' to track upstream",
+                 metavar='REMOTE')
     if isinstance(self.manifest, XmlManifest) \
     if isinstance(self.manifest, XmlManifest) \
     or not self.manifest.manifestProject.Exists:
     or not self.manifest.manifestProject.Exists:
       g.add_option('-m', '--manifest-name',
       g.add_option('-m', '--manifest-name',
@@ -84,30 +88,42 @@ to update the working directory files.
                  dest='no_repo_verify', action='store_true',
                  dest='no_repo_verify', action='store_true',
                  help='do not verify repo source code')
                  help='do not verify repo source code')
 
 
-  def _SyncManifest(self, opt):
+  def _ApplyOptions(self, opt, is_new):
     m = self.manifest.manifestProject
     m = self.manifest.manifestProject
-    is_new = not m.Exists
 
 
     if is_new:
     if is_new:
-      if not opt.manifest_url:
-        print >>sys.stderr, 'fatal: manifest url (-u) is required.'
-        sys.exit(1)
-
-      if not opt.quiet:
-        print >>sys.stderr, 'Getting manifest ...'
-        print >>sys.stderr, '   from %s' % opt.manifest_url
-      m._InitGitDir()
+      if opt.manifest_origin:
+        m.remote.name = opt.manifest_origin
 
 
       if opt.manifest_branch:
       if opt.manifest_branch:
         m.revisionExpr = opt.manifest_branch
         m.revisionExpr = opt.manifest_branch
       else:
       else:
         m.revisionExpr = 'refs/heads/master'
         m.revisionExpr = 'refs/heads/master'
     else:
     else:
+      if opt.manifest_origin:
+        print >>sys.stderr, 'fatal: cannot change origin name'
+        sys.exit(1)
+
       if opt.manifest_branch:
       if opt.manifest_branch:
         m.revisionExpr = opt.manifest_branch
         m.revisionExpr = opt.manifest_branch
       else:
       else:
         m.PreSync()
         m.PreSync()
 
 
+  def _SyncManifest(self, opt):
+    m = self.manifest.manifestProject
+    is_new = not m.Exists
+
+    if is_new:
+      if not opt.manifest_url:
+        print >>sys.stderr, 'fatal: manifest url (-u) is required.'
+        sys.exit(1)
+
+      if not opt.quiet:
+        print >>sys.stderr, 'Getting manifest ...'
+        print >>sys.stderr, '   from %s' % opt.manifest_url
+      m._InitGitDir()
+
+    self._ApplyOptions(opt, is_new)
     if opt.manifest_url:
     if opt.manifest_url:
       r = m.GetRemote(m.remote.name)
       r = m.GetRemote(m.remote.name)
       r.url = opt.manifest_url
       r.url = opt.manifest_url