From cf9a2a2a76b332c89fef40e47f7ddb4e8c817ab9 Mon Sep 17 00:00:00 2001 From: Kaushik Lingarkar Date: Tue, 17 Dec 2024 12:49:14 -0800 Subject: Update internal filesystem layout for submodules Change the bare checkout directory for submodules from 'subprojects' to 'modules'. Git expects bare submodule checkouts to be in the 'modules' directory. If old subproject directories are found, they will be migrated to the new modules directory. This change is the first step in ensuring Git can understand repo's submodules to some extent. Change-Id: I385029f1bb55d040616d970d6ffb4bb856692520 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/444881 Tested-by: Kaushik Lingarkar Reviewed-by: Josip Sokcevic --- project.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'project.py') diff --git a/project.py b/project.py index de1ab3c6..b58bd53b 100644 --- a/project.py +++ b/project.py @@ -3415,6 +3415,11 @@ class Project: """ dotgit = os.path.join(self.worktree, ".git") + # If bare checkout of the submodule is stored under the subproject dir, + # migrate it. + if self.parent: + self._MigrateOldSubmoduleDir() + # If using an old layout style (a directory), migrate it. if not platform_utils.islink(dotgit) and platform_utils.isdir(dotgit): self._MigrateOldWorkTreeGitDir(dotgit, project=self.name) @@ -3548,6 +3553,28 @@ class Project: dotgit, ) + def _MigrateOldSubmoduleDir(self): + """Move the old bare checkout in 'subprojects' to 'modules' + as bare checkouts of submodules are now in 'modules' dir. + """ + subprojects = os.path.join(self.parent.gitdir, "subprojects") + if not platform_utils.isdir(subprojects): + return + + modules = os.path.join(self.parent.gitdir, "modules") + old = self.gitdir + new = os.path.splitext(self.gitdir.replace(subprojects, modules))[0] + + if all(map(platform_utils.isdir, [old, new])): + platform_utils.rmtree(old, ignore_errors=True) + else: + os.makedirs(modules, exist_ok=True) + platform_utils.rename(old, new) + self.gitdir = new + self.UpdatePaths(self.relpath, self.worktree, self.gitdir, self.objdir) + if platform_utils.isdir(subprojects) and not os.listdir(subprojects): + platform_utils.rmtree(subprojects, ignore_errors=True) + def _get_symlink_error_message(self): if platform_utils.isWindows(): return ( -- cgit v1.2.3-54-g00ecf