Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for git worktree issue #60

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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