fix committing in git worktree

fixes https://git.clan.lol/clan/clan-core/issues/2636
This commit is contained in:
Jörg Thalheim
2024-12-25 22:50:30 +01:00
parent 55a88e43b5
commit e0b18c1579

View File

@@ -57,7 +57,17 @@ def _commit_file_to_git(
:param commit_message: The commit message. :param commit_message: The commit message.
:raises ClanError: If the file is not in the git repository. :raises ClanError: If the file is not in the git repository.
""" """
with locked_open(repo_dir / ".git" / "clan.lock", "w+"): dotgit = repo_dir / ".git"
real_git_dir = repo_dir / ".git"
# resolve worktree
if dotgit.is_file():
actual_git_dir = dotgit.read_text().strip()
if not actual_git_dir.startswith("gitdir: "):
msg = f"Invalid .git file: {actual_git_dir}"
raise ClanError(msg)
real_git_dir = repo_dir / actual_git_dir[len("gitdir: ") :]
with locked_open(real_git_dir / "clan.lock", "w+"):
for file_path in file_paths: for file_path in file_paths:
cmd = run_cmd( cmd = run_cmd(
["git"], ["git"],