mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 14:25:00 +00:00
tests and bugfix
This commit is contained in:
parent
957f59c011
commit
c8f1c0609d
3 changed files with 37 additions and 6 deletions
|
@ -405,7 +405,7 @@ def main(argv=None, input=None, output=None, force_git_root=None):
|
||||||
dry_run=args.dry_run,
|
dry_run=args.dry_run,
|
||||||
)
|
)
|
||||||
|
|
||||||
fnames = args.files
|
fnames = [str(Path(fn).resolve()) for fn in args.files]
|
||||||
if len(args.files) > 1:
|
if len(args.files) > 1:
|
||||||
good = True
|
good = True
|
||||||
for fname in args.files:
|
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 len(args.files) == 1:
|
||||||
if Path(args.files[0]).is_dir():
|
if Path(args.files[0]).is_dir():
|
||||||
if args.git:
|
if args.git:
|
||||||
git_dname = args.files[0]
|
git_dname = str(Path(args.files[0]).resolve())
|
||||||
fnames = []
|
fnames = []
|
||||||
else:
|
else:
|
||||||
io.tool_error(f"{args.files[0]} is a directory, but --no-git selected.")
|
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.
|
# We can't know the git repo for sure until after parsing the args.
|
||||||
# If we guessed wrong, reparse because that changes things like
|
# 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:
|
except ValueError as err:
|
||||||
io.tool_error(str(err))
|
io.tool_error(str(err))
|
||||||
return
|
return 1
|
||||||
|
|
||||||
if args.show_repo_map:
|
if args.show_repo_map:
|
||||||
repo_map = coder.get_repo_map()
|
repo_map = coder.get_repo_map()
|
||||||
|
|
|
@ -44,6 +44,33 @@ class TestMain(TestCase):
|
||||||
main(["--yes", "foo.txt"], input=DummyInput(), output=DummyOutput())
|
main(["--yes", "foo.txt"], input=DummyInput(), output=DummyOutput())
|
||||||
self.assertTrue(os.path.exists("foo.txt"))
|
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):
|
def test_main_with_git_config_yml(self):
|
||||||
make_repo()
|
make_repo()
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,11 @@ class GitTemporaryDirectory(ChdirTemporaryDirectory):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def make_repo():
|
def make_repo(path=None):
|
||||||
repo = git.Repo.init()
|
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", "name", "Test User").release()
|
||||||
repo.config_writer().set_value("user", "email", "testuser@example.com").release()
|
repo.config_writer().set_value("user", "email", "testuser@example.com").release()
|
||||||
|
|
||||||
|
return repo
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue