mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-20 12:24:59 +00:00
refactor: Move resolve_aiderignore_path to top level and add tests
This commit is contained in:
parent
ffe89362ab
commit
1ec257278e
2 changed files with 31 additions and 9 deletions
|
@ -18,6 +18,15 @@ from aider.deprecated import add_deprecated_model_args
|
||||||
from .dump import dump # noqa: F401
|
from .dump import dump # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_aiderignore_path(path_str, git_root=None):
|
||||||
|
path = Path(path_str)
|
||||||
|
if path.is_absolute():
|
||||||
|
return str(path)
|
||||||
|
elif git_root:
|
||||||
|
return str(Path(git_root) / path)
|
||||||
|
return str(path)
|
||||||
|
|
||||||
|
|
||||||
def default_env_file(git_root):
|
def default_env_file(git_root):
|
||||||
return os.path.join(git_root, ".env") if git_root else ".env"
|
return os.path.join(git_root, ".env") if git_root else ".env"
|
||||||
|
|
||||||
|
@ -390,18 +399,10 @@ def get_parser(default_config_files, git_root):
|
||||||
os.path.join(git_root, ".aiderignore") if git_root else ".aiderignore"
|
os.path.join(git_root, ".aiderignore") if git_root else ".aiderignore"
|
||||||
)
|
)
|
||||||
|
|
||||||
def resolve_aiderignore_path(path_str):
|
|
||||||
path = Path(path_str)
|
|
||||||
if path.is_absolute():
|
|
||||||
return str(path)
|
|
||||||
elif git_root:
|
|
||||||
return str(Path(git_root) / path)
|
|
||||||
return str(path)
|
|
||||||
|
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"--aiderignore",
|
"--aiderignore",
|
||||||
metavar="AIDERIGNORE",
|
metavar="AIDERIGNORE",
|
||||||
type=resolve_aiderignore_path,
|
type=lambda path_str: resolve_aiderignore_path(path_str, git_root),
|
||||||
default=default_aiderignore_file,
|
default=default_aiderignore_file,
|
||||||
help="Specify the aider ignore file (default: .aiderignore in git root)",
|
help="Specify the aider ignore file (default: .aiderignore in git root)",
|
||||||
)
|
)
|
||||||
|
|
|
@ -927,6 +927,27 @@ class TestMain(TestCase):
|
||||||
repo = git.Repo(git_dir) # Re-open repo to ensure we get fresh config
|
repo = git.Repo(git_dir) # Re-open repo to ensure we get fresh config
|
||||||
self.assertEqual(repo.git.config("user.name"), "Directive User")
|
self.assertEqual(repo.git.config("user.name"), "Directive User")
|
||||||
self.assertEqual(repo.git.config("user.email"), "directive@example.com")
|
self.assertEqual(repo.git.config("user.email"), "directive@example.com")
|
||||||
|
|
||||||
|
def test_resolve_aiderignore_path(self):
|
||||||
|
# Import the function directly to test it
|
||||||
|
from aider.args import resolve_aiderignore_path
|
||||||
|
|
||||||
|
# Test with absolute path
|
||||||
|
abs_path = os.path.abspath("/tmp/test/.aiderignore")
|
||||||
|
self.assertEqual(resolve_aiderignore_path(abs_path), abs_path)
|
||||||
|
|
||||||
|
# Test with relative path and git root
|
||||||
|
git_root = "/path/to/git/root"
|
||||||
|
rel_path = ".aiderignore"
|
||||||
|
expected = os.path.join(git_root, rel_path)
|
||||||
|
self.assertEqual(
|
||||||
|
resolve_aiderignore_path(rel_path, git_root),
|
||||||
|
str(Path(git_root) / rel_path)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Test with relative path and no git root
|
||||||
|
rel_path = ".aiderignore"
|
||||||
|
self.assertEqual(resolve_aiderignore_path(rel_path), rel_path)
|
||||||
|
|
||||||
def test_invalid_edit_format(self):
|
def test_invalid_edit_format(self):
|
||||||
with GitTemporaryDirectory():
|
with GitTemporaryDirectory():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue