summaryrefslogtreecommitdiffstats
path: root/subcmds/init.py
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds/init.py')
-rw-r--r--subcmds/init.py78
1 files changed, 56 insertions, 22 deletions
diff --git a/subcmds/init.py b/subcmds/init.py
index 75a58f11..cdbbfdf7 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -21,6 +21,9 @@ from command import InteractiveCommand, MirrorSafeCommand
21from error import ManifestParseError 21from error import ManifestParseError
22from project import SyncBuffer 22from project import SyncBuffer
23from git_command import git_require, MIN_GIT_VERSION 23from git_command import git_require, MIN_GIT_VERSION
24from manifest_submodule import SubmoduleManifest
25from manifest_xml import XmlManifest
26from subcmds.sync import _ReloadManifest
24 27
25class Init(InteractiveCommand, MirrorSafeCommand): 28class Init(InteractiveCommand, MirrorSafeCommand):
26 common = True 29 common = True
@@ -37,10 +40,6 @@ current working directory.
37The optional -b argument can be used to select the manifest branch 40The optional -b argument can be used to select the manifest branch
38to checkout and use. If no branch is specified, master is assumed. 41to checkout and use. If no branch is specified, master is assumed.
39 42
40The optional -m argument can be used to specify an alternate manifest
41to be used. If no manifest is specified, the manifest default.xml
42will be used.
43
44Switching Manifest Branches 43Switching Manifest Branches
45--------------------------- 44---------------------------
46 45
@@ -65,9 +64,15 @@ to update the working directory files.
65 g.add_option('-b', '--manifest-branch', 64 g.add_option('-b', '--manifest-branch',
66 dest='manifest_branch', 65 dest='manifest_branch',
67 help='manifest branch or revision', metavar='REVISION') 66 help='manifest branch or revision', metavar='REVISION')
68 g.add_option('-m', '--manifest-name', 67 g.add_option('-o', '--origin',
69 dest='manifest_name', default='default.xml', 68 dest='manifest_origin',
70 help='initial manifest file', metavar='NAME.xml') 69 help="use REMOTE instead of 'origin' to track upstream",
70 metavar='REMOTE')
71 if isinstance(self.manifest, XmlManifest) \
72 or not self.manifest.manifestProject.Exists:
73 g.add_option('-m', '--manifest-name',
74 dest='manifest_name', default='default.xml',
75 help='initial manifest file', metavar='NAME.xml')
71 g.add_option('--mirror', 76 g.add_option('--mirror',
72 dest='mirror', action='store_true', 77 dest='mirror', action='store_true',
73 help='mirror the forrest') 78 help='mirror the forrest')
@@ -85,30 +90,42 @@ to update the working directory files.
85 dest='no_repo_verify', action='store_true', 90 dest='no_repo_verify', action='store_true',
86 help='do not verify repo source code') 91 help='do not verify repo source code')
87 92
88 def _SyncManifest(self, opt): 93 def _ApplyOptions(self, opt, is_new):
89 m = self.manifest.manifestProject 94 m = self.manifest.manifestProject
90 is_new = not m.Exists
91 95
92 if is_new: 96 if is_new:
93 if not opt.manifest_url: 97 if opt.manifest_origin:
94 print >>sys.stderr, 'fatal: manifest url (-u) is required.' 98 m.remote.name = opt.manifest_origin
95 sys.exit(1)
96
97 if not opt.quiet:
98 print >>sys.stderr, 'Getting manifest ...'
99 print >>sys.stderr, ' from %s' % opt.manifest_url
100 m._InitGitDir()
101 99
102 if opt.manifest_branch: 100 if opt.manifest_branch:
103 m.revisionExpr = opt.manifest_branch 101 m.revisionExpr = opt.manifest_branch
104 else: 102 else:
105 m.revisionExpr = 'refs/heads/master' 103 m.revisionExpr = 'refs/heads/master'
106 else: 104 else:
105 if opt.manifest_origin:
106 print >>sys.stderr, 'fatal: cannot change origin name'
107 sys.exit(1)
108
107 if opt.manifest_branch: 109 if opt.manifest_branch:
108 m.revisionExpr = opt.manifest_branch 110 m.revisionExpr = opt.manifest_branch
109 else: 111 else:
110 m.PreSync() 112 m.PreSync()
111 113
114 def _SyncManifest(self, opt):
115 m = self.manifest.manifestProject
116 is_new = not m.Exists
117
118 if is_new:
119 if not opt.manifest_url:
120 print >>sys.stderr, 'fatal: manifest url (-u) is required.'
121 sys.exit(1)
122
123 if not opt.quiet:
124 print >>sys.stderr, 'Getting manifest ...'
125 print >>sys.stderr, ' from %s' % opt.manifest_url
126 m._InitGitDir()
127
128 self._ApplyOptions(opt, is_new)
112 if opt.manifest_url: 129 if opt.manifest_url:
113 r = m.GetRemote(m.remote.name) 130 r = m.GetRemote(m.remote.name)
114 r.url = opt.manifest_url 131 r.url = opt.manifest_url
@@ -118,6 +135,7 @@ to update the working directory files.
118 if opt.mirror: 135 if opt.mirror:
119 if is_new: 136 if is_new:
120 m.config.SetString('repo.mirror', 'true') 137 m.config.SetString('repo.mirror', 'true')
138 m.config.ClearCache()
121 else: 139 else:
122 print >>sys.stderr, 'fatal: --mirror not supported on existing client' 140 print >>sys.stderr, 'fatal: --mirror not supported on existing client'
123 sys.exit(1) 141 sys.exit(1)
@@ -127,14 +145,29 @@ to update the working directory files.
127 print >>sys.stderr, 'fatal: cannot obtain manifest %s' % r.url 145 print >>sys.stderr, 'fatal: cannot obtain manifest %s' % r.url
128 sys.exit(1) 146 sys.exit(1)
129 147
148 if is_new and SubmoduleManifest.IsBare(m):
149 new = self.GetManifest(reparse=True, type=SubmoduleManifest)
150 if m.gitdir != new.manifestProject.gitdir:
151 os.rename(m.gitdir, new.manifestProject.gitdir)
152 new = self.GetManifest(reparse=True, type=SubmoduleManifest)
153 m = new.manifestProject
154 self._ApplyOptions(opt, is_new)
155
156 if not is_new:
157 # Force the manifest to load if it exists, the old graph
158 # may be needed inside of _ReloadManifest().
159 #
160 self.manifest.projects
161
130 syncbuf = SyncBuffer(m.config) 162 syncbuf = SyncBuffer(m.config)
131 m.Sync_LocalHalf(syncbuf) 163 m.Sync_LocalHalf(syncbuf)
132 syncbuf.Finish() 164 syncbuf.Finish()
165 _ReloadManifest(self)
166 self._ApplyOptions(opt, is_new)
133 167
134 if is_new or m.CurrentBranch is None: 168 if not self.manifest.InitBranch():
135 if not m.StartBranch('default'): 169 print >>sys.stderr, 'fatal: cannot create branch in manifest'
136 print >>sys.stderr, 'fatal: cannot create default in manifest' 170 sys.exit(1)
137 sys.exit(1)
138 171
139 def _LinkManifest(self, name): 172 def _LinkManifest(self, name):
140 if not name: 173 if not name:
@@ -216,7 +249,8 @@ to update the working directory files.
216 def Execute(self, opt, args): 249 def Execute(self, opt, args):
217 git_require(MIN_GIT_VERSION, fail=True) 250 git_require(MIN_GIT_VERSION, fail=True)
218 self._SyncManifest(opt) 251 self._SyncManifest(opt)
219 self._LinkManifest(opt.manifest_name) 252 if isinstance(self.manifest, XmlManifest):
253 self._LinkManifest(opt.manifest_name)
220 254
221 if os.isatty(0) and os.isatty(1) and not self.manifest.IsMirror: 255 if os.isatty(0) and os.isatty(1) and not self.manifest.IsMirror:
222 self._ConfigureUser() 256 self._ConfigureUser()