mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
InitGitDir: Clean up created directories
If _InitGitDir fails, it leaves any progress it had made on the file system. This can cause subsequent calls to repo sync to behave differently. This is especially evident when _CheckDirReference() fails, since it will not be invoked when sync is retried because both the source and destination directories already exist. To address this, have _InitGitDir() clean up any directories it has created if it catches an exception. Also behave the same way for _InitWorkTree(). Change-Id: Ic16bb3feea649e115b59bd44be294e89e3692aeb
This commit is contained in:
parent
b3d6e67196
commit
b1a07b8276
12
project.py
12
project.py
@ -2169,6 +2169,7 @@ class Project(object):
|
|||||||
def _InitGitDir(self, mirror_git=None):
|
def _InitGitDir(self, mirror_git=None):
|
||||||
init_git_dir = not os.path.exists(self.gitdir)
|
init_git_dir = not os.path.exists(self.gitdir)
|
||||||
init_obj_dir = not os.path.exists(self.objdir)
|
init_obj_dir = not os.path.exists(self.objdir)
|
||||||
|
try:
|
||||||
# Initialize the bare repository, which contains all of the objects.
|
# Initialize the bare repository, which contains all of the objects.
|
||||||
if init_obj_dir:
|
if init_obj_dir:
|
||||||
os.makedirs(self.objdir)
|
os.makedirs(self.objdir)
|
||||||
@ -2217,6 +2218,12 @@ class Project(object):
|
|||||||
self.config.SetString('core.bare', 'true')
|
self.config.SetString('core.bare', 'true')
|
||||||
else:
|
else:
|
||||||
self.config.SetString('core.bare', None)
|
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):
|
def _UpdateHooks(self):
|
||||||
if os.path.exists(self.gitdir):
|
if os.path.exists(self.gitdir):
|
||||||
@ -2363,6 +2370,7 @@ class Project(object):
|
|||||||
def _InitWorkTree(self):
|
def _InitWorkTree(self):
|
||||||
dotgit = os.path.join(self.worktree, '.git')
|
dotgit = os.path.join(self.worktree, '.git')
|
||||||
init_dotgit = not os.path.exists(dotgit)
|
init_dotgit = not os.path.exists(dotgit)
|
||||||
|
try:
|
||||||
if init_dotgit:
|
if init_dotgit:
|
||||||
os.makedirs(dotgit)
|
os.makedirs(dotgit)
|
||||||
self._ReferenceGitDir(self.gitdir, dotgit, share_refs=True,
|
self._ReferenceGitDir(self.gitdir, dotgit, share_refs=True,
|
||||||
@ -2380,6 +2388,10 @@ class Project(object):
|
|||||||
raise GitError("cannot initialize work tree")
|
raise GitError("cannot initialize work tree")
|
||||||
|
|
||||||
self._CopyAndLinkFiles()
|
self._CopyAndLinkFiles()
|
||||||
|
except Exception:
|
||||||
|
if init_dotgit:
|
||||||
|
shutil.rmtree(dotgit)
|
||||||
|
raise
|
||||||
|
|
||||||
def _gitdir_path(self, path):
|
def _gitdir_path(self, path):
|
||||||
return os.path.realpath(os.path.join(self.gitdir, path))
|
return os.path.realpath(os.path.join(self.gitdir, path))
|
||||||
|
Loading…
Reference in New Issue
Block a user