mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
Merge "InitGitDir: Clean up created directories"
This commit is contained in:
commit
7cccfb2cf0
12
project.py
12
project.py
@ -2167,6 +2167,7 @@ class Project(object):
|
||||
def _InitGitDir(self, mirror_git=None):
|
||||
init_git_dir = not os.path.exists(self.gitdir)
|
||||
init_obj_dir = not os.path.exists(self.objdir)
|
||||
try:
|
||||
# Initialize the bare repository, which contains all of the objects.
|
||||
if init_obj_dir:
|
||||
os.makedirs(self.objdir)
|
||||
@ -2215,6 +2216,12 @@ class Project(object):
|
||||
self.config.SetString('core.bare', 'true')
|
||||
else:
|
||||
self.config.SetString('core.bare', None)
|
||||
except Exception:
|
||||
if init_obj_dir and os.path.exists(self.objdir):
|
||||
shutil.rmtree(self.objdir)
|
||||
if init_git_dir and os.path.exists(self.gitdir):
|
||||
shutil.rmtree(self.gitdir)
|
||||
raise
|
||||
|
||||
def _UpdateHooks(self):
|
||||
if os.path.exists(self.gitdir):
|
||||
@ -2361,6 +2368,7 @@ class Project(object):
|
||||
def _InitWorkTree(self):
|
||||
dotgit = os.path.join(self.worktree, '.git')
|
||||
init_dotgit = not os.path.exists(dotgit)
|
||||
try:
|
||||
if init_dotgit:
|
||||
os.makedirs(dotgit)
|
||||
self._ReferenceGitDir(self.gitdir, dotgit, share_refs=True,
|
||||
@ -2378,6 +2386,10 @@ class Project(object):
|
||||
raise GitError("cannot initialize work tree")
|
||||
|
||||
self._CopyAndLinkFiles()
|
||||
except Exception:
|
||||
if init_dotgit:
|
||||
shutil.rmtree(dotgit)
|
||||
raise
|
||||
|
||||
def _gitdir_path(self, path):
|
||||
return os.path.realpath(os.path.join(self.gitdir, path))
|
||||
|
Loading…
Reference in New Issue
Block a user