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