summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorKaushik Lingarkar <kaushikl@qti.qualcomm.com>2024-12-17 12:49:14 -0800
committerKaushik Lingarkar <kaushikl@qti.qualcomm.com>2025-02-04 08:07:49 -0800
commitcf9a2a2a76b332c89fef40e47f7ddb4e8c817ab9 (patch)
treecfecbcec1354e04b5846706eb9b148ddc22c45dd /project.py
parent5ae8292fea94bc26aa8c7345f5230899d3d45a63 (diff)
downloadgit-repo-cf9a2a2a76b332c89fef40e47f7ddb4e8c817ab9.tar.gz
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 <kaushikl@qti.qualcomm.com> Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Diffstat (limited to 'project.py')
-rw-r--r--project.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/project.py b/project.py
index de1ab3c6..b58bd53b 100644
--- a/project.py
+++ b/project.py
@@ -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 (