test_main_git_ignore

This commit is contained in:
Paul Gauthier 2023-07-16 12:56:55 -03:00
parent 0f14947a4c
commit 180ca7c464
2 changed files with 17 additions and 1 deletions

View file

@ -38,6 +38,7 @@ def setup_git(git_root, io):
io.tool_output("Git repository created in the current working directory.") io.tool_output("Git repository created in the current working directory.")
git_root = str(Path.cwd().resolve()) git_root = str(Path.cwd().resolve())
check_gitignore(git_root, None)
return git_root return git_root
@ -55,7 +56,7 @@ def check_gitignore(git_root, io):
else: else:
content = "" 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 return
if content and not content.endswith("\n"): if content and not content.endswith("\n"):

View file

@ -80,6 +80,10 @@ class TestMain(TestCase):
self.assertTrue(git.Repo(self.tempdir)) 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): def test_check_gitignore(self):
make_repo() make_repo()
io = InputOutput(pretty=False, yes=True) io = InputOutput(pretty=False, yes=True)
@ -96,6 +100,17 @@ class TestMain(TestCase):
check_gitignore(cwd, io) check_gitignore(cwd, io)
self.assertEqual("one\ntwo\n.aider*\n", gitignore.read_text()) 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): def test_main_args(self):
with patch("aider.main.Coder.create") as MockCoder: with patch("aider.main.Coder.create") as MockCoder:
# --yes will just ok the git repo without blocking on input # --yes will just ok the git repo without blocking on input