Skip to content

Commit

Permalink
Merge pull request #60 from ESMCI/fix/worktree
Browse files Browse the repository at this point in the history
fix for git worktree issue
  • Loading branch information
jedwards4b authored Aug 14, 2024
2 parents 8f78adc + 4749ece commit 5d2093a
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions git_fleximod/submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))

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))
Expand Down Expand Up @@ -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)


Expand Down

0 comments on commit 5d2093a

Please sign in to comment.