From 56b20241a199f2f8bbbb6bc415e6bc7871b8dbda Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Wed, 14 Aug 2024 11:18:19 -0600 Subject: [PATCH 1/2] fix for git worktree issue --- git_fleximod/submodule.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/git_fleximod/submodule.py b/git_fleximod/submodule.py index 70a3018..da4d74a 100644 --- a/git_fleximod/submodule.py +++ b/git_fleximod/submodule.py @@ -219,7 +219,15 @@ def sparse_checkout(self): gitroot = superroot.strip() else: gitroot = self.root_dir.strip() - assert os.path.isdir(os.path.join(gitroot, ".git")) + # Now need to move the .git dir to the submodule location + rootdotgit = os.path.join(self.root_dir, ".git") + while os.path.isfile(rootdotgit): + with open(rootdotgit) as f: + line = f.readline() + if line.startswith("gitdir: "): + rootdotgit = os.path.abspath(os.path.join(self.root_dir,line[8:].rstrip())) + print(f"rootdotgit is {rootdotgit}") + assert os.path.isdir(rootdotgit) # first create the module directory if not os.path.isdir(os.path.join(self.root_dir, self.path)): os.makedirs(os.path.join(self.root_dir, self.path)) @@ -256,35 +264,33 @@ def sparse_checkout(self): os.path.join(self.root_dir, f.read().split()[1]), start=os.path.join(self.root_dir, self.path), ) - topgit = os.path.join(gitpath, "modules") + rootdotgit = os.path.join(gitpath, "modules", self.name) else: - topgit = os.path.relpath( - os.path.join(self.root_dir, ".git", "modules"), + rootdotgit = os.path.relpath( + os.path.join(self.root_dir, ".git", "modules", self.name), start=os.path.join(self.root_dir, self.path), ) - with utils.pushd(sprep_repo): - if not os.path.isdir(topgit): - os.makedirs(topgit) - topgit += os.sep + self.name - if os.path.isdir(os.path.join(self.root_dir, self.path, ".git")): with utils.pushd(sprep_repo): - if os.path.isdir(os.path.join(topgit,".git")): - shutil.rmtree(os.path.join(topgit,".git")) - shutil.move(".git", topgit) + if os.path.isdir(os.path.join(rootdotgit,".git")): + shutil.rmtree(os.path.join(rootdotgit,".git")) + shutil.move(".git", rootdotgit) with open(".git", "w") as f: - f.write("gitdir: " + os.path.relpath(topgit)) - # assert(os.path.isdir(os.path.relpath(topgit, start=sprep_repo))) - gitsparse = os.path.abspath(os.path.join(topgit, "info", "sparse-checkout")) + f.write("gitdir: " + os.path.relpath(rootdotgit)) + infodir = os.path.join(rootdotgit, "info") + if not os.path.isdir(infodir): + os.makedirs(infodir) + gitsparse = os.path.abspath(os.path.join(infodir, "sparse-checkout")) if os.path.isfile(gitsparse): self.logger.warning( - "submodule {} is already initialized {}".format(self.name, topgit) + "submodule {} is already initialized {}".format(self.name, rootdotgit) ) return with utils.pushd(sprep_repo): if os.path.isfile(self.fxsparse): + shutil.copy(self.fxsparse, gitsparse) From 4749ece44614abb543007e20552351169c02a7d6 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Wed, 14 Aug 2024 11:26:36 -0600 Subject: [PATCH 2/2] remove debug print statement --- git_fleximod/submodule.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git_fleximod/submodule.py b/git_fleximod/submodule.py index da4d74a..f8e235d 100644 --- a/git_fleximod/submodule.py +++ b/git_fleximod/submodule.py @@ -226,7 +226,7 @@ def sparse_checkout(self): line = f.readline() if line.startswith("gitdir: "): rootdotgit = os.path.abspath(os.path.join(self.root_dir,line[8:].rstrip())) - print(f"rootdotgit is {rootdotgit}") + assert os.path.isdir(rootdotgit) # first create the module directory if not os.path.isdir(os.path.join(self.root_dir, self.path)):