From e0b18c1579bea88faf8d583ffecf7c3c561c0046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 25 Dec 2024 22:50:30 +0100 Subject: [PATCH] fix committing in git worktree fixes https://git.clan.lol/clan/clan-core/issues/2636 --- pkgs/clan-cli/clan_cli/git.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_cli/git.py b/pkgs/clan-cli/clan_cli/git.py index d893edf2e..e0a12c90c 100644 --- a/pkgs/clan-cli/clan_cli/git.py +++ b/pkgs/clan-cli/clan_cli/git.py @@ -57,7 +57,17 @@ def _commit_file_to_git( :param commit_message: The commit message. :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: cmd = run_cmd( ["git"],