summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--project.py114
1 files changed, 63 insertions, 51 deletions
diff --git a/project.py b/project.py
index d0d3b6eb..1e3ab6b9 100644
--- a/project.py
+++ b/project.py
@@ -2169,54 +2169,61 @@ class Project(object):
2169 def _InitGitDir(self, mirror_git=None): 2169 def _InitGitDir(self, mirror_git=None):
2170 init_git_dir = not os.path.exists(self.gitdir) 2170 init_git_dir = not os.path.exists(self.gitdir)
2171 init_obj_dir = not os.path.exists(self.objdir) 2171 init_obj_dir = not os.path.exists(self.objdir)
2172 # Initialize the bare repository, which contains all of the objects. 2172 try:
2173 if init_obj_dir: 2173 # Initialize the bare repository, which contains all of the objects.
2174 os.makedirs(self.objdir) 2174 if init_obj_dir:
2175 self.bare_objdir.init() 2175 os.makedirs(self.objdir)
2176 self.bare_objdir.init()
2176 2177
2177 # If we have a separate directory to hold refs, initialize it as well. 2178 # If we have a separate directory to hold refs, initialize it as well.
2178 if self.objdir != self.gitdir: 2179 if self.objdir != self.gitdir:
2179 if init_git_dir: 2180 if init_git_dir:
2180 os.makedirs(self.gitdir) 2181 os.makedirs(self.gitdir)
2181 2182
2182 if init_obj_dir or init_git_dir: 2183 if init_obj_dir or init_git_dir:
2183 self._ReferenceGitDir(self.objdir, self.gitdir, share_refs=False, 2184 self._ReferenceGitDir(self.objdir, self.gitdir, share_refs=False,
2184 copy_all=True) 2185 copy_all=True)
2185 self._CheckDirReference(self.objdir, self.gitdir, share_refs=False) 2186 self._CheckDirReference(self.objdir, self.gitdir, share_refs=False)
2186 2187
2187 if init_git_dir: 2188 if init_git_dir:
2188 mp = self.manifest.manifestProject 2189 mp = self.manifest.manifestProject
2189 ref_dir = mp.config.GetString('repo.reference') or '' 2190 ref_dir = mp.config.GetString('repo.reference') or ''
2190 2191
2191 if ref_dir or mirror_git: 2192 if ref_dir or mirror_git:
2192 if not mirror_git: 2193 if not mirror_git:
2193 mirror_git = os.path.join(ref_dir, self.name + '.git') 2194 mirror_git = os.path.join(ref_dir, self.name + '.git')
2194 repo_git = os.path.join(ref_dir, '.repo', 'projects', 2195 repo_git = os.path.join(ref_dir, '.repo', 'projects',
2195 self.relpath + '.git') 2196 self.relpath + '.git')
2196 2197
2197 if os.path.exists(mirror_git): 2198 if os.path.exists(mirror_git):
2198 ref_dir = mirror_git 2199 ref_dir = mirror_git
2199 2200
2200 elif os.path.exists(repo_git): 2201 elif os.path.exists(repo_git):
2201 ref_dir = repo_git 2202 ref_dir = repo_git
2202 2203
2203 else: 2204 else:
2204 ref_dir = None 2205 ref_dir = None
2205 2206
2206 if ref_dir: 2207 if ref_dir:
2207 _lwrite(os.path.join(self.gitdir, 'objects/info/alternates'), 2208 _lwrite(os.path.join(self.gitdir, 'objects/info/alternates'),
2208 os.path.join(ref_dir, 'objects') + '\n') 2209 os.path.join(ref_dir, 'objects') + '\n')
2209 2210
2210 self._UpdateHooks() 2211 self._UpdateHooks()
2211 2212
2212 m = self.manifest.manifestProject.config 2213 m = self.manifest.manifestProject.config
2213 for key in ['user.name', 'user.email']: 2214 for key in ['user.name', 'user.email']:
2214 if m.Has(key, include_defaults=False): 2215 if m.Has(key, include_defaults=False):
2215 self.config.SetString(key, m.GetString(key)) 2216 self.config.SetString(key, m.GetString(key))
2216 if self.manifest.IsMirror: 2217 if self.manifest.IsMirror:
2217 self.config.SetString('core.bare', 'true') 2218 self.config.SetString('core.bare', 'true')
2218 else: 2219 else:
2219 self.config.SetString('core.bare', None) 2220 self.config.SetString('core.bare', None)
2221 except Exception:
2222 if init_obj_dir and os.path.exists(self.objdir):
2223 shutil.rmtree(self.objdir)
2224 if init_git_dir and os.path.exists(self.gitdir):
2225 shutil.rmtree(self.gitdir)
2226 raise
2220 2227
2221 def _UpdateHooks(self): 2228 def _UpdateHooks(self):
2222 if os.path.exists(self.gitdir): 2229 if os.path.exists(self.gitdir):
@@ -2363,23 +2370,28 @@ class Project(object):
2363 def _InitWorkTree(self): 2370 def _InitWorkTree(self):
2364 dotgit = os.path.join(self.worktree, '.git') 2371 dotgit = os.path.join(self.worktree, '.git')
2365 init_dotgit = not os.path.exists(dotgit) 2372 init_dotgit = not os.path.exists(dotgit)
2366 if init_dotgit: 2373 try:
2367 os.makedirs(dotgit) 2374 if init_dotgit:
2368 self._ReferenceGitDir(self.gitdir, dotgit, share_refs=True, 2375 os.makedirs(dotgit)
2369 copy_all=False) 2376 self._ReferenceGitDir(self.gitdir, dotgit, share_refs=True,
2377 copy_all=False)
2370 2378
2371 self._CheckDirReference(self.gitdir, dotgit, share_refs=True) 2379 self._CheckDirReference(self.gitdir, dotgit, share_refs=True)
2372 2380
2373 if init_dotgit: 2381 if init_dotgit:
2374 _lwrite(os.path.join(dotgit, HEAD), '%s\n' % self.GetRevisionId()) 2382 _lwrite(os.path.join(dotgit, HEAD), '%s\n' % self.GetRevisionId())
2375 2383
2376 cmd = ['read-tree', '--reset', '-u'] 2384 cmd = ['read-tree', '--reset', '-u']
2377 cmd.append('-v') 2385 cmd.append('-v')
2378 cmd.append(HEAD) 2386 cmd.append(HEAD)
2379 if GitCommand(self, cmd).Wait() != 0: 2387 if GitCommand(self, cmd).Wait() != 0:
2380 raise GitError("cannot initialize work tree") 2388 raise GitError("cannot initialize work tree")
2381 2389
2382 self._CopyAndLinkFiles() 2390 self._CopyAndLinkFiles()
2391 except Exception:
2392 if init_dotgit:
2393 shutil.rmtree(dotgit)
2394 raise
2383 2395
2384 def _gitdir_path(self, path): 2396 def _gitdir_path(self, path):
2385 return os.path.realpath(os.path.join(self.gitdir, path)) 2397 return os.path.realpath(os.path.join(self.gitdir, path))