From bef1d00ab121487e9574ddd87b468ecb44df2e09 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 24 Jul 2023 13:42:05 -0300 Subject: [PATCH] Refactor test_get_tracked_files_with_new_staged_file to use a GitTemporaryDirectory and add new assertions. --- tests/test_repo.py | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/tests/test_repo.py b/tests/test_repo.py index 67983a134..0290cf1e6 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -2,14 +2,14 @@ import os import tempfile import unittest from pathlib import Path -from unittest.mock import patch +from unittest.mock import patch, MagicMock import git from aider.dump import dump # noqa: F401 from aider.io import InputOutput from aider.repo import GitRepo - +from tests.utils import GitTemporaryDirectory class TestRepo(unittest.TestCase): @patch("aider.repo.simple_send_with_retries") @@ -80,3 +80,37 @@ class TestRepo(unittest.TestCase): # Assert that coder.get_tracked_files() returns the three filenames self.assertEqual(set(tracked_files), set(created_files)) + + def test_get_tracked_files_with_new_staged_file(self): + # Mock the IO object + mock_io = MagicMock() + + with GitTemporaryDirectory(): + # new repo + repo = git.Repo() + + # add it, but no commits at all in the repo yet + fname = Path("new.txt") + fname.touch() + repo.git.add(str(fname)) + + coder = GitRepo(InputOutput(), None) + + # better be there + fnames = coder.get_tracked_files() + self.assertIn(str(fname), fnames) + + # commit it, better still be there + repo.git.commit("-m", "new") + fnames = coder.get_tracked_files() + self.assertIn(str(fname), fnames) + + # new file, added but not committed + fname2 = Path("new2.txt") + fname2.touch() + repo.git.add(str(fname2)) + + # both should be there + fnames = coder.get_tracked_files() + self.assertIn(str(fname), fnames) + self.assertIn(str(fname2), fnames)