Skip to content

Commit 515469a

Browse files
committed
updated process_patch to receive absolute root path
1 parent 030318c commit 515469a

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

codetide/mcp/tools/patch_code/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .parser import Parser, patch_to_commit
44
# from ....core.common import writeFile
55

6-
from typing import Dict, Tuple, List, Callable
6+
from typing import Dict, Optional, Tuple, List, Callable, Union
77
import pathlib
88
import os
99

@@ -108,18 +108,24 @@ def process_patch(
108108
open_fn: Callable[[str], str],
109109
write_fn: Callable[[str, str], None],
110110
remove_fn: Callable[[str], None],
111-
exists_fn: Callable[[str], bool]
111+
exists_fn: Callable[[str], bool],
112+
root_path: Optional[Union[str, pathlib.Path]]=None
112113
) -> List[str]:
113114
"""The main entrypoint function to process a patch from text to filesystem."""
114115
if not os.path.exists(patch_path):
115116
raise DiffError("Patch path {patch_path} does not exist.")
116117

118+
if root_path is not None:
119+
root_path = pathlib.Path(root_path)
120+
117121
# Normalize line endings before processing
118122
text = open_fn(patch_path)
119123

120124
# FIX: Check for existence of files to be added before parsing.
121125
paths_to_add = identify_files_added(text)
122126
for p in paths_to_add:
127+
if root_path is not None:
128+
p = str(root_path / p)
123129
if exists_fn(p):
124130
raise DiffError(f"Add File Error - file already exists: {p}")
125131

@@ -128,6 +134,8 @@ def process_patch(
128134
# Load files with normalized line endings
129135
orig_files = {}
130136
for path in paths_needed:
137+
if root_path is not None:
138+
path = str(root_path / path)
131139
orig_files[path] = open_fn(path)
132140

133141
patch, _fuzz = text_to_patch(text, orig_files)

0 commit comments

Comments
 (0)