mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-23 13:54:59 +00:00
Added a test case to fail if git posix paths are not turned into windows paths
This commit is contained in:
parent
b3d624b7cd
commit
c6696e7245
2 changed files with 20 additions and 9 deletions
|
@ -6,7 +6,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
from json.decoder import JSONDecodeError
|
from json.decoder import JSONDecodeError
|
||||||
from pathlib import Path
|
from pathlib import Path, PurePosixPath
|
||||||
|
|
||||||
import backoff
|
import backoff
|
||||||
import git
|
import git
|
||||||
|
@ -248,17 +248,10 @@ class Coder:
|
||||||
self.repo = git.Repo(repo_paths.pop(), odbt=git.GitDB)
|
self.repo = git.Repo(repo_paths.pop(), odbt=git.GitDB)
|
||||||
|
|
||||||
self.root = os.path.abspath(self.repo.working_tree_dir)
|
self.root = os.path.abspath(self.repo.working_tree_dir)
|
||||||
if self.verbose:
|
|
||||||
dump(self.repo)
|
|
||||||
dump(self.root)
|
|
||||||
dump(os.getcwd())
|
|
||||||
|
|
||||||
new_files = []
|
new_files = []
|
||||||
for fname in self.abs_fnames:
|
for fname in self.abs_fnames:
|
||||||
relative_fname = self.get_rel_fname(fname)
|
relative_fname = self.get_rel_fname(fname)
|
||||||
if self.verbose:
|
|
||||||
dump(fname)
|
|
||||||
dump(relative_fname)
|
|
||||||
|
|
||||||
tracked_files = set(self.get_tracked_files())
|
tracked_files = set(self.get_tracked_files())
|
||||||
if relative_fname not in tracked_files:
|
if relative_fname not in tracked_files:
|
||||||
|
@ -962,6 +955,7 @@ class Coder:
|
||||||
def get_tracked_files(self):
|
def get_tracked_files(self):
|
||||||
# convert to appropriate os.sep, since git always normalizes to /
|
# convert to appropriate os.sep, since git always normalizes to /
|
||||||
files = set(self.repo.git.ls_files().splitlines())
|
files = set(self.repo.git.ls_files().splitlines())
|
||||||
|
# return files
|
||||||
if os.sep == "/":
|
if os.sep == "/":
|
||||||
return files
|
return files
|
||||||
return set(path.replace("/", os.sep) for path in files)
|
return set(path.replace("/", os.sep) for path in files)
|
||||||
|
|
|
@ -2,6 +2,7 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
@ -37,9 +38,25 @@ class TestMain(TestCase):
|
||||||
subprocess.run(["git", "init"])
|
subprocess.run(["git", "init"])
|
||||||
subprocess.run(["git", "config", "user.email", "dummy@example.com"])
|
subprocess.run(["git", "config", "user.email", "dummy@example.com"])
|
||||||
subprocess.run(["git", "config", "user.name", "Dummy User"])
|
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"))
|
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):
|
def test_main_args(self):
|
||||||
with patch("aider.main.Coder.create") as MockCoder:
|
with patch("aider.main.Coder.create") as MockCoder:
|
||||||
main(["--no-auto-commits"], input=DummyInput())
|
main(["--no-auto-commits"], input=DummyInput())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue