Skip to content

Commit

Permalink
fix bugs from rebase conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
PCSwingle committed Aug 26, 2023
1 parent ad0701f commit 91aa136
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions mentat/code_file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def get_code_message(self):

def _add_file(self, abs_path):
logging.info(f"Adding new file {abs_path} to context")
self.file_paths.append(abs_path)
self.file_paths.append(str(abs_path))
# create any missing directories in the path
abs_path.parent.mkdir(parents=True, exist_ok=True)

Expand Down Expand Up @@ -228,7 +228,6 @@ def _get_new_code_lines(self, rel_path, changes) -> Iterable[str]:
if not changes:
return []

rel_path = str(changes[0].file)
new_code_lines = self.file_lines[rel_path].copy()
if new_code_lines != self._read_file(rel_path):
logging.info(f"File '{rel_path}' changed while generating changes")
Expand Down Expand Up @@ -260,7 +259,7 @@ def write_changes_to_files(self, code_changes: list[CodeChange]) -> None:
for code_change in code_changes:
# here keys are str not path object
rel_path = str(code_change.file)
abs_path = os.path.join(self.git_root, rel_path)
abs_path = self.git_root / rel_path
match code_change.action:
case CodeChangeAction.CreateFile:
cprint(f"Creating new file {rel_path}", color="light_green")
Expand All @@ -270,23 +269,25 @@ def write_changes_to_files(self, code_changes: list[CodeChange]) -> None:
case CodeChangeAction.DeleteFile:
self._handle_delete(code_change)
case CodeChangeAction.RenameFile:
abs_new_path = os.path.join(self.git_root, code_change.name)
abs_new_path = self.git_root / code_change.name
self._add_file(abs_new_path)
code_lines = self.file_lines[abs_path]
code_lines = self.file_lines[rel_path]
with open(abs_new_path, "w") as f:
f.write("\n".join(code_lines))
self._delete_file(abs_path)
file_changes[str(code_change.name)] += file_changes[rel_path]
file_changes[rel_path] = []
self.file_lines[abs_new_path] = self._read_file(abs_new_path)
self.file_lines[str(code_change.name)] = self._read_file(
abs_new_path
)
case _:
file_changes[rel_path].append(code_change)

for rel_path, changes in file_changes.items():
abs_path = os.path.join(self.git_root, rel_path)
abs_path = self.git_root / rel_path
new_code_lines = self._get_new_code_lines(rel_path, changes)
if new_code_lines:
if abs_path not in self.file_paths:
if str(abs_path) not in self.file_paths:
raise MentatError(
f"Attempted to edit file {abs_path} not in context"
)
Expand Down

0 comments on commit 91aa136

Please sign in to comment.