Skip to content

Commit 305210b

Browse files
committed
fix: resolve git root from module_root for worktree PR creation
git_root_dir() searches from CWD (original repo), but in worktree mode file paths have been remapped to the worktree. This caused relative_to() to raise ValueError when creating PRs. Search from module_root instead so root_dir is always in the same path space as the file paths.
1 parent 6a19b9d commit 305210b

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

codeflash/optimization/function_optimizer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from typing import TYPE_CHECKING, Callable
1414

1515
import libcst as cst
16+
from git import Repo as GitRepo
1617
from rich.console import Group
1718
from rich.panel import Panel
1819
from rich.syntax import Syntax
@@ -2222,11 +2223,11 @@ def process_review(
22222223
console.print(Panel(panel_content, title="Optimization Review", border_style=display_info[1]))
22232224

22242225
if raise_pr or staging_review:
2225-
data["root_dir"] = git_root_dir()
2226+
data["root_dir"] = git_root_dir(GitRepo(str(self.args.module_root), search_parent_directories=True))
22262227
if raise_pr and not staging_review and opt_review_result.review != "low":
22272228
# Ensure root_dir is set for PR creation (needed for async functions that skip opt_review)
22282229
if "root_dir" not in data:
2229-
data["root_dir"] = git_root_dir()
2230+
data["root_dir"] = git_root_dir(GitRepo(str(self.args.module_root), search_parent_directories=True))
22302231
data["git_remote"] = self.args.git_remote
22312232
# Remove language from data dict as check_create_pr doesn't accept it
22322233
pr_data = {k: v for k, v in data.items() if k != "language"}

0 commit comments

Comments
 (0)