diff options
-rw-r--r-- | docs/internal-fs-layout.md | 2 | ||||
-rw-r--r-- | manifest_xml.py | 7 | ||||
-rw-r--r-- | project.py | 27 |
3 files changed, 34 insertions, 2 deletions
diff --git a/docs/internal-fs-layout.md b/docs/internal-fs-layout.md index f63978f3..c0e44778 100644 --- a/docs/internal-fs-layout.md +++ b/docs/internal-fs-layout.md | |||
@@ -141,7 +141,7 @@ Instead, you should use standard Git workflows like [git worktree] or | |||
141 | (e.g. a local mirror & a public review server) while avoiding duplicating | 141 | (e.g. a local mirror & a public review server) while avoiding duplicating |
142 | the content. However, this can run into problems if different remotes use | 142 | the content. However, this can run into problems if different remotes use |
143 | the same path on their respective servers. Best to avoid that. | 143 | 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. |
145 | * `subproject-objects/`: Like `project-objects/`, but for git submodules. | 145 | * `subproject-objects/`: Like `project-objects/`, but for git submodules. |
146 | * `worktrees/`: Bare checkouts of every project synced by the manifest. The | 146 | * `worktrees/`: Bare checkouts of every project synced by the manifest. The |
147 | filesystem layout matches the `<project name=...` setting in the manifest | 147 | filesystem layout matches the `<project name=...` setting in the manifest |
diff --git a/manifest_xml.py b/manifest_xml.py index cdab31e6..347ae5ef 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
@@ -2056,7 +2056,12 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
2056 | path = path.rstrip("/") | 2056 | path = path.rstrip("/") |
2057 | name = name.rstrip("/") | 2057 | name = name.rstrip("/") |
2058 | relpath = self._JoinRelpath(parent.relpath, path) | 2058 | 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 | ||
2060 | objdir = os.path.join( | 2065 | objdir = os.path.join( |
2061 | parent.gitdir, "subproject-objects", "%s.git" % name | 2066 | parent.gitdir, "subproject-objects", "%s.git" % name |
2062 | ) | 2067 | ) |
@@ -3415,6 +3415,11 @@ class Project: | |||
3415 | """ | 3415 | """ |
3416 | dotgit = os.path.join(self.worktree, ".git") | 3416 | dotgit = os.path.join(self.worktree, ".git") |
3417 | 3417 | ||
3418 | # If bare checkout of the submodule is stored under the subproject dir, | ||
3419 | # migrate it. | ||
3420 | if self.parent: | ||
3421 | self._MigrateOldSubmoduleDir() | ||
3422 | |||
3418 | # If using an old layout style (a directory), migrate it. | 3423 | # If using an old layout style (a directory), migrate it. |
3419 | if not platform_utils.islink(dotgit) and platform_utils.isdir(dotgit): | 3424 | if not platform_utils.islink(dotgit) and platform_utils.isdir(dotgit): |
3420 | self._MigrateOldWorkTreeGitDir(dotgit, project=self.name) | 3425 | self._MigrateOldWorkTreeGitDir(dotgit, project=self.name) |
@@ -3548,6 +3553,28 @@ class Project: | |||
3548 | dotgit, | 3553 | dotgit, |
3549 | ) | 3554 | ) |
3550 | 3555 | ||
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 | |||
3551 | def _get_symlink_error_message(self): | 3578 | def _get_symlink_error_message(self): |
3552 | if platform_utils.isWindows(): | 3579 | if platform_utils.isWindows(): |
3553 | return ( | 3580 | return ( |