mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 00:35:00 +00:00
test_check_gitignore
This commit is contained in:
parent
1e0443cc86
commit
0f14947a4c
2 changed files with 21 additions and 5 deletions
|
@ -42,9 +42,11 @@ def setup_git(git_root, io):
|
|||
|
||||
|
||||
def check_gitignore(git_root, io):
|
||||
if not git_root:
|
||||
return
|
||||
|
||||
pat = ".aider*"
|
||||
|
||||
updated_ignore = None
|
||||
gitignore_file = Path(git_root) / ".gitignore"
|
||||
if gitignore_file.exists():
|
||||
content = gitignore_file.read_text(encoding="utf-8")
|
||||
|
@ -56,7 +58,7 @@ def check_gitignore(git_root, io):
|
|||
if not io.confirm_ask(f"Add {pat} to .gitignore (recommended)?"):
|
||||
return
|
||||
|
||||
if not content.endswith("\n"):
|
||||
if content and not content.endswith("\n"):
|
||||
content += "\n"
|
||||
content += pat + "\n"
|
||||
gitignore_file.write_text(content, encoding="utf-8")
|
||||
|
@ -366,8 +368,6 @@ def main(args=None, input=None, output=None):
|
|||
|
||||
if args.git:
|
||||
git_root = setup_git(git_root, io)
|
||||
|
||||
if git_root:
|
||||
check_gitignore(git_root, io)
|
||||
|
||||
def scrub_sensitive_info(text):
|
||||
|
|
|
@ -12,7 +12,7 @@ from prompt_toolkit.output import DummyOutput
|
|||
|
||||
from aider.dump import dump # noqa: F401
|
||||
from aider.io import InputOutput
|
||||
from aider.main import main, setup_git
|
||||
from aider.main import check_gitignore, main, setup_git
|
||||
from tests.utils import make_repo
|
||||
|
||||
|
||||
|
@ -80,6 +80,22 @@ class TestMain(TestCase):
|
|||
|
||||
self.assertTrue(git.Repo(self.tempdir))
|
||||
|
||||
def test_check_gitignore(self):
|
||||
make_repo()
|
||||
io = InputOutput(pretty=False, yes=True)
|
||||
cwd = Path.cwd()
|
||||
gitignore = cwd / ".gitignore"
|
||||
|
||||
self.assertFalse(gitignore.exists())
|
||||
check_gitignore(cwd, io)
|
||||
self.assertTrue(gitignore.exists())
|
||||
|
||||
self.assertEqual(".aider*", gitignore.read_text().splitlines()[0])
|
||||
|
||||
gitignore.write_text("one\ntwo\n")
|
||||
check_gitignore(cwd, io)
|
||||
self.assertEqual("one\ntwo\n.aider*\n", gitignore.read_text())
|
||||
|
||||
def test_main_args(self):
|
||||
with patch("aider.main.Coder.create") as MockCoder:
|
||||
# --yes will just ok the git repo without blocking on input
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue