mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 06:15:00 +00:00
aider: Implemented find_common_root
method to set self.root
to the most specific directory that all the file paths in self.fnames
have in common.
# Context: USER: thanks, i used that. ASSISTANT: You're welcome! If you have any more questions or need further assistance, feel free to ask. USER: implement the find_common_root method. it should set self.root to be the most specific directory which all the self.fnames have in common ASSISTANT: To implement the `find_common_root` method, you can use the `os.path.commonprefix` function to find the common directory for all the file paths in `self.fnames`. Here's the implementation: ```python aider/coder.py <<<<<<< ORIGINAL def find_common_root(self): pass ======= def find_common_root(self): import os common_prefix = os.path.commonprefix(list(self.fnames)) self.root = os.path.dirname(common_prefix) self.console.print(f"[red]Common root directory: {self.root}") >>>>>>> UPDATED ``` This will set `self.root` to the most specific directory that all the file paths in `self.fnames` have in common.
This commit is contained in:
parent
9ab1a0d513
commit
70d01f5434
1 changed files with 4 additions and 1 deletions
|
@ -75,14 +75,17 @@ class Coder:
|
||||||
|
|
||||||
if num_repos == 0:
|
if num_repos == 0:
|
||||||
self.console.print("[red bold]Files are not in a git repo.")
|
self.console.print("[red bold]Files are not in a git repo.")
|
||||||
return
|
|
||||||
if num_repos > 1:
|
if num_repos > 1:
|
||||||
self.console.print("[red bold]Files are in different git repos.")
|
self.console.print("[red bold]Files are in different git repos.")
|
||||||
|
if num_repos != 1:
|
||||||
|
self.find_common_root()
|
||||||
return
|
return
|
||||||
|
|
||||||
# https://github.com/gitpython-developers/GitPython/issues/427
|
# https://github.com/gitpython-developers/GitPython/issues/427
|
||||||
repo = git.Repo(repo_paths.pop(), odbt=git.GitDB)
|
repo = git.Repo(repo_paths.pop(), odbt=git.GitDB)
|
||||||
|
|
||||||
|
self.root = repo.working_tree_dir
|
||||||
|
|
||||||
new_files = []
|
new_files = []
|
||||||
for fname in self.fnames:
|
for fname in self.fnames:
|
||||||
relative_fname = os.path.relpath(fname, repo.working_tree_dir)
|
relative_fname = os.path.relpath(fname, repo.working_tree_dir)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue