Skip to content

Commit cf9a2a2

Browse files
committed
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 <[email protected]> Reviewed-by: Josip Sokcevic <[email protected]>
1 parent 5ae8292 commit cf9a2a2

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

docs/internal-fs-layout.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Instead, you should use standard Git workflows like [git worktree] or
141141
(e.g. a local mirror & a public review server) while avoiding duplicating
142142
the content. However, this can run into problems if different remotes use
143143
the same path on their respective servers. Best to avoid that.
144-
* `subprojects/`: Like `projects/`, but for git submodules.
144+
* `modules/`: Like `projects/`, but for git submodules.
145145
* `subproject-objects/`: Like `project-objects/`, but for git submodules.
146146
* `worktrees/`: Bare checkouts of every project synced by the manifest. The
147147
filesystem layout matches the `<project name=...` setting in the manifest

manifest_xml.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,12 @@ def GetSubprojectPaths(self, parent, name, path):
20562056
path = path.rstrip("/")
20572057
name = name.rstrip("/")
20582058
relpath = self._JoinRelpath(parent.relpath, path)
2059-
gitdir = os.path.join(parent.gitdir, "subprojects", "%s.git" % path)
2059+
subprojects = os.path.join(parent.gitdir, "subprojects", f"{path}.git")
2060+
modules = os.path.join(parent.gitdir, "modules", path)
2061+
if platform_utils.isdir(subprojects):
2062+
gitdir = subprojects
2063+
else:
2064+
gitdir = modules
20602065
objdir = os.path.join(
20612066
parent.gitdir, "subproject-objects", "%s.git" % name
20622067
)

project.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3415,6 +3415,11 @@ def _InitWorkTree(self, force_sync=False, submodules=False):
34153415
"""
34163416
dotgit = os.path.join(self.worktree, ".git")
34173417

3418+
# If bare checkout of the submodule is stored under the subproject dir,
3419+
# migrate it.
3420+
if self.parent:
3421+
self._MigrateOldSubmoduleDir()
3422+
34183423
# If using an old layout style (a directory), migrate it.
34193424
if not platform_utils.islink(dotgit) and platform_utils.isdir(dotgit):
34203425
self._MigrateOldWorkTreeGitDir(dotgit, project=self.name)
@@ -3548,6 +3553,28 @@ def _MigrateOldWorkTreeGitDir(cls, dotgit, project=None):
35483553
dotgit,
35493554
)
35503555

3556+
def _MigrateOldSubmoduleDir(self):
3557+
"""Move the old bare checkout in 'subprojects' to 'modules'
3558+
as bare checkouts of submodules are now in 'modules' dir.
3559+
"""
3560+
subprojects = os.path.join(self.parent.gitdir, "subprojects")
3561+
if not platform_utils.isdir(subprojects):
3562+
return
3563+
3564+
modules = os.path.join(self.parent.gitdir, "modules")
3565+
old = self.gitdir
3566+
new = os.path.splitext(self.gitdir.replace(subprojects, modules))[0]
3567+
3568+
if all(map(platform_utils.isdir, [old, new])):
3569+
platform_utils.rmtree(old, ignore_errors=True)
3570+
else:
3571+
os.makedirs(modules, exist_ok=True)
3572+
platform_utils.rename(old, new)
3573+
self.gitdir = new
3574+
self.UpdatePaths(self.relpath, self.worktree, self.gitdir, self.objdir)
3575+
if platform_utils.isdir(subprojects) and not os.listdir(subprojects):
3576+
platform_utils.rmtree(subprojects, ignore_errors=True)
3577+
35513578
def _get_symlink_error_message(self):
35523579
if platform_utils.isWindows():
35533580
return (

0 commit comments

Comments
 (0)