diff --git a/aider/main.py b/aider/main.py index 775e49762..23c2b2a9a 100644 --- a/aider/main.py +++ b/aider/main.py @@ -38,6 +38,7 @@ def setup_git(git_root, io): io.tool_output("Git repository created in the current working directory.") git_root = str(Path.cwd().resolve()) + check_gitignore(git_root, None) return git_root @@ -55,7 +56,7 @@ def check_gitignore(git_root, io): else: content = "" - if not io.confirm_ask(f"Add {pat} to .gitignore (recommended)?"): + if io and not io.confirm_ask(f"Add {pat} to .gitignore (recommended)?"): return if content and not content.endswith("\n"): diff --git a/tests/test_main.py b/tests/test_main.py index ed818cc84..e85c8439d 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -80,6 +80,10 @@ class TestMain(TestCase): self.assertTrue(git.Repo(self.tempdir)) + gitignore = Path.cwd() / ".gitignore" + self.assertTrue(gitignore.exists()) + self.assertEqual(".aider*", gitignore.read_text().splitlines()[0]) + def test_check_gitignore(self): make_repo() io = InputOutput(pretty=False, yes=True) @@ -96,6 +100,17 @@ class TestMain(TestCase): check_gitignore(cwd, io) self.assertEqual("one\ntwo\n.aider*\n", gitignore.read_text()) + def test_main_git_ignore(self): + cwd = Path().cwd() + self.assertFalse((cwd / ".git").exists()) + self.assertFalse((cwd / ".gitignore").exists()) + + with patch("aider.main.Coder.create"): + main(["--yes"], input=DummyInput()) + + self.assertTrue((cwd / ".git").exists()) + self.assertTrue((cwd / ".gitignore").exists()) + def test_main_args(self): with patch("aider.main.Coder.create") as MockCoder: # --yes will just ok the git repo without blocking on input