Skip to content

Commit db111d3

Browse files
sokcevicGLUCI
authored andcommitted
sync: Recover from errors during read-tree
When repo is initializing a git repository, it calls `git read-tree`. During such operation, git is restoring workspace based on the current index. However, some things can go wrong: a user can run out of disk space, or, in case of partial clone, user may no longer reach the remote host. That will leave affected repository in a bad state with partially checked out workspace. The follow up repo sync won't try to fix such state. This change removes .git symlink, which will force the next `repo sync` to redo Git repository setup. Bug: b/363171216 Bug: b/390161127 Change-Id: I57db4b6cae0ef21826dc7cede4d3bf02cfc3d955 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/447801 Reviewed-by: Scott Lee <[email protected]> Tested-by: Josip Sokcevic <[email protected]> Commit-Queue: Josip Sokcevic <[email protected]>
1 parent 3405446 commit db111d3

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

project.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,11 +3443,18 @@ def _InitWorkTree(self, force_sync=False, submodules=False):
34433443

34443444
# Finish checking out the worktree.
34453445
cmd = ["read-tree", "--reset", "-u", "-v", HEAD]
3446-
if GitCommand(self, cmd).Wait() != 0:
3447-
raise GitError(
3448-
"Cannot initialize work tree for " + self.name,
3449-
project=self.name,
3450-
)
3446+
try:
3447+
if GitCommand(self, cmd).Wait() != 0:
3448+
raise GitError(
3449+
"Cannot initialize work tree for " + self.name,
3450+
project=self.name,
3451+
)
3452+
except Exception as e:
3453+
# Something went wrong with read-tree (perhaps fetching
3454+
# missing blobs), so remove .git to avoid half initialized
3455+
# workspace from which repo can't recover on its own.
3456+
platform_utils.remove(dotgit)
3457+
raise e
34513458

34523459
if submodules:
34533460
self._SyncSubmodules(quiet=True)

0 commit comments

Comments
 (0)