diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 36e3b4d60..3c756f0da 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -6,7 +6,7 @@ import os import sys import traceback from json.decoder import JSONDecodeError -from pathlib import Path +from pathlib import Path, PurePosixPath import backoff import git @@ -248,17 +248,10 @@ class Coder: self.repo = git.Repo(repo_paths.pop(), odbt=git.GitDB) self.root = os.path.abspath(self.repo.working_tree_dir) - if self.verbose: - dump(self.repo) - dump(self.root) - dump(os.getcwd()) new_files = [] for fname in self.abs_fnames: relative_fname = self.get_rel_fname(fname) - if self.verbose: - dump(fname) - dump(relative_fname) tracked_files = set(self.get_tracked_files()) if relative_fname not in tracked_files: @@ -962,6 +955,7 @@ class Coder: def get_tracked_files(self): # convert to appropriate os.sep, since git always normalizes to / files = set(self.repo.git.ls_files().splitlines()) + # return files if os.sep == "/": return files return set(path.replace("/", os.sep) for path in files) diff --git a/tests/test_main.py b/tests/test_main.py index 2ab5d132d..248e61bca 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -2,6 +2,7 @@ import os import shutil import subprocess import tempfile +from pathlib import Path from unittest import TestCase from unittest.mock import patch @@ -37,9 +38,25 @@ class TestMain(TestCase): subprocess.run(["git", "init"]) subprocess.run(["git", "config", "user.email", "dummy@example.com"]) subprocess.run(["git", "config", "user.name", "Dummy User"]) - main(["--verbose", "--yes", "foo.txt"], input=DummyInput(), output=DummyOutput()) + main(["--yes", "foo.txt"], input=DummyInput(), output=DummyOutput()) self.assertTrue(os.path.exists("foo.txt")) + def test_main_with_empty_git_dir_new_subdir_file(self): + subprocess.run(["git", "init"]) + subprocess.run(["git", "config", "user.email", "dummy@example.com"]) + subprocess.run(["git", "config", "user.name", "Dummy User"]) + subdir = Path("subdir") + subdir.mkdir() + fname = subdir / "foo.txt" + fname.touch() + subprocess.run(["git", "add", str(subdir)]) + subprocess.run(["git", "commit", "-m", "added"]) + + # This will throw a git error on windows if get_tracked_files doesn't + # properly convert git/posix/paths to git\posix\paths. + # Because aider will try and `git add` a file that's already in the repo. + main(["--yes", "--verbose", str(fname)], input=DummyInput(), output=DummyOutput()) + def test_main_args(self): with patch("aider.main.Coder.create") as MockCoder: main(["--no-auto-commits"], input=DummyInput())