diff --git a/aider/args.py b/aider/args.py index 60e189706..6df19778b 100644 --- a/aider/args.py +++ b/aider/args.py @@ -18,6 +18,15 @@ from aider.deprecated import add_deprecated_model_args 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): 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" ) - 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( "--aiderignore", metavar="AIDERIGNORE", - type=resolve_aiderignore_path, + type=lambda path_str: resolve_aiderignore_path(path_str, git_root), default=default_aiderignore_file, help="Specify the aider ignore file (default: .aiderignore in git root)", ) diff --git a/tests/basic/test_main.py b/tests/basic/test_main.py index f5d147c0e..10861abfa 100644 --- a/tests/basic/test_main.py +++ b/tests/basic/test_main.py @@ -927,6 +927,27 @@ class TestMain(TestCase): 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.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): with GitTemporaryDirectory():