diff --git a/aider/main.py b/aider/main.py index a3bf80b1c..97efe8bd5 100644 --- a/aider/main.py +++ b/aider/main.py @@ -405,7 +405,7 @@ def main(argv=None, input=None, output=None, force_git_root=None): dry_run=args.dry_run, ) - fnames = args.files + fnames = [str(Path(fn).resolve()) for fn in args.files] if len(args.files) > 1: good = True for fname in args.files: @@ -422,11 +422,11 @@ def main(argv=None, input=None, output=None, force_git_root=None): if len(args.files) == 1: if Path(args.files[0]).is_dir(): if args.git: - git_dname = args.files[0] + git_dname = str(Path(args.files[0]).resolve()) fnames = [] else: io.tool_error(f"{args.files[0]} is a directory, but --no-git selected.") - return -1 + return 1 # We can't know the git repo for sure until after parsing the args. # If we guessed wrong, reparse because that changes things like @@ -506,7 +506,7 @@ def main(argv=None, input=None, output=None, force_git_root=None): ) except ValueError as err: io.tool_error(str(err)) - return + return 1 if args.show_repo_map: repo_map = coder.get_repo_map() diff --git a/tests/test_main.py b/tests/test_main.py index 6bda03c7f..e23268c4c 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -44,6 +44,33 @@ class TestMain(TestCase): main(["--yes", "foo.txt"], input=DummyInput(), output=DummyOutput()) self.assertTrue(os.path.exists("foo.txt")) + @patch("aider.repo.GitRepo.get_commit_message", return_value="mock commit message") + def test_main_with_empty_git_dir_new_files(self, _): + make_repo() + main(["--yes", "foo.txt", "bar.txt"], input=DummyInput(), output=DummyOutput()) + self.assertTrue(os.path.exists("foo.txt")) + self.assertTrue(os.path.exists("bar.txt")) + + def test_main_with_dname_and_fname(self): + subdir = Path("subdir") + subdir.mkdir() + make_repo(str(subdir)) + res = main(["subdir", "foo.txt"], input=DummyInput(), output=DummyOutput()) + self.assertNotEqual(res, None) + + @patch("aider.repo.GitRepo.get_commit_message", return_value="mock commit message") + def test_main_with_subdir_repo_fnames(self, _): + subdir = Path("subdir") + subdir.mkdir() + make_repo(str(subdir)) + main( + ["--yes", str(subdir / "foo.txt"), str(subdir / "bar.txt")], + input=DummyInput(), + output=DummyOutput(), + ) + self.assertTrue((subdir / "foo.txt").exists()) + self.assertTrue((subdir / "bar.txt").exists()) + def test_main_with_git_config_yml(self): make_repo() diff --git a/tests/utils.py b/tests/utils.py index 8ece2b4a4..32a2deaf5 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -42,7 +42,11 @@ class GitTemporaryDirectory(ChdirTemporaryDirectory): return res -def make_repo(): - repo = git.Repo.init() +def make_repo(path=None): + if not path: + path = "." + repo = git.Repo.init(path) repo.config_writer().set_value("user", "name", "Test User").release() repo.config_writer().set_value("user", "email", "testuser@example.com").release() + + return repo