mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 14:25:00 +00:00
Aider should fully ignore files in aiderignore #479
This commit is contained in:
parent
5e60417e5d
commit
a9fe4532c7
5 changed files with 83 additions and 14 deletions
|
@ -156,6 +156,22 @@ class Coder:
|
||||||
|
|
||||||
self.commands = Commands(self.io, self, voice_language)
|
self.commands = Commands(self.io, self, voice_language)
|
||||||
|
|
||||||
|
if use_git:
|
||||||
|
try:
|
||||||
|
self.repo = GitRepo(
|
||||||
|
self.io, fnames, git_dname, aider_ignore_file, client=self.client
|
||||||
|
)
|
||||||
|
self.root = self.repo.root
|
||||||
|
except FileNotFoundError:
|
||||||
|
self.repo = None
|
||||||
|
|
||||||
|
if self.repo:
|
||||||
|
filtered_fnames = self.repo.filter_ignored_files(fnames)
|
||||||
|
for fname in fnames:
|
||||||
|
if fname not in filtered_fnames:
|
||||||
|
self.io.tool_error(f"Skipping {fname} that matches aiderignore spec.")
|
||||||
|
fnames = filtered_fnames
|
||||||
|
|
||||||
for fname in fnames:
|
for fname in fnames:
|
||||||
fname = Path(fname)
|
fname = Path(fname)
|
||||||
if not fname.exists():
|
if not fname.exists():
|
||||||
|
@ -167,16 +183,6 @@ class Coder:
|
||||||
raise ValueError(f"{fname} is not a file")
|
raise ValueError(f"{fname} is not a file")
|
||||||
|
|
||||||
self.abs_fnames.add(str(fname.resolve()))
|
self.abs_fnames.add(str(fname.resolve()))
|
||||||
|
|
||||||
if use_git:
|
|
||||||
try:
|
|
||||||
self.repo = GitRepo(
|
|
||||||
self.io, fnames, git_dname, aider_ignore_file, client=self.client
|
|
||||||
)
|
|
||||||
self.root = self.repo.root
|
|
||||||
except FileNotFoundError:
|
|
||||||
self.repo = None
|
|
||||||
|
|
||||||
if self.repo:
|
if self.repo:
|
||||||
rel_repo_dir = self.repo.get_rel_repo_dir()
|
rel_repo_dir = self.repo.get_rel_repo_dir()
|
||||||
num_files = len(self.repo.get_tracked_files())
|
num_files = len(self.repo.get_tracked_files())
|
||||||
|
|
|
@ -342,6 +342,10 @@ class Commands:
|
||||||
else:
|
else:
|
||||||
fname = Path(self.coder.root) / word
|
fname = Path(self.coder.root) / word
|
||||||
|
|
||||||
|
if self.coder.repo and not self.coder.repo.filter_ignored_files([fname]):
|
||||||
|
self.io.tool_error(f"Skipping {fname} that matches aiderignore spec.")
|
||||||
|
continue
|
||||||
|
|
||||||
if fname.exists() and fname.is_file():
|
if fname.exists() and fname.is_file():
|
||||||
all_matched_files.add(str(fname))
|
all_matched_files.add(str(fname))
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -41,6 +41,8 @@ class GitRepo:
|
||||||
repo_paths.append(repo_path)
|
repo_paths.append(repo_path)
|
||||||
except git.exc.InvalidGitRepositoryError:
|
except git.exc.InvalidGitRepositoryError:
|
||||||
pass
|
pass
|
||||||
|
except git.exc.NoSuchPathError:
|
||||||
|
pass
|
||||||
|
|
||||||
num_repos = len(set(repo_paths))
|
num_repos = len(set(repo_paths))
|
||||||
|
|
||||||
|
@ -194,10 +196,7 @@ class GitRepo:
|
||||||
files.extend(staged_files)
|
files.extend(staged_files)
|
||||||
|
|
||||||
# convert to appropriate os.sep, since git always normalizes to /
|
# convert to appropriate os.sep, since git always normalizes to /
|
||||||
res = set(
|
res = set(self.normalize_path(path) for path in files)
|
||||||
self.normalize_path(path)
|
|
||||||
for path in files
|
|
||||||
)
|
|
||||||
|
|
||||||
return self.filter_ignored_files(res)
|
return self.filter_ignored_files(res)
|
||||||
|
|
||||||
|
|
|
@ -578,6 +578,34 @@ two
|
||||||
diff = saved_diffs[0]
|
diff = saved_diffs[0]
|
||||||
self.assertIn("file.txt", diff)
|
self.assertIn("file.txt", diff)
|
||||||
|
|
||||||
|
def test_skip_aiderignored_files(self):
|
||||||
|
with GitTemporaryDirectory():
|
||||||
|
repo = git.Repo()
|
||||||
|
|
||||||
|
fname1 = "ignoreme1.txt"
|
||||||
|
fname2 = "ignoreme2.txt"
|
||||||
|
fname3 = "dir/ignoreme3.txt"
|
||||||
|
|
||||||
|
Path(fname2).touch()
|
||||||
|
repo.git.add(str(fname2))
|
||||||
|
repo.git.commit("-m", "initial")
|
||||||
|
|
||||||
|
aignore = Path(".aiderignore")
|
||||||
|
aignore.write_text(f"{fname1}\n{fname2}\ndir\n")
|
||||||
|
|
||||||
|
io = InputOutput(yes=True)
|
||||||
|
coder = Coder.create(
|
||||||
|
models.GPT4,
|
||||||
|
None,
|
||||||
|
io,
|
||||||
|
fnames=[fname1, fname2, fname3],
|
||||||
|
aider_ignore_file=str(aignore),
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertNotIn(fname1, str(coder.abs_fnames))
|
||||||
|
self.assertNotIn(fname2, str(coder.abs_fnames))
|
||||||
|
self.assertNotIn(fname3, str(coder.abs_fnames))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -6,6 +6,7 @@ import tempfile
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import git
|
import git
|
||||||
|
|
||||||
|
@ -23,6 +24,10 @@ class TestCommands(TestCase):
|
||||||
self.tempdir = tempfile.mkdtemp()
|
self.tempdir = tempfile.mkdtemp()
|
||||||
os.chdir(self.tempdir)
|
os.chdir(self.tempdir)
|
||||||
|
|
||||||
|
self.patcher = patch("aider.coders.base_coder.check_model_availability")
|
||||||
|
self.mock_check = self.patcher.start()
|
||||||
|
self.mock_check.return_value = True
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
os.chdir(self.original_cwd)
|
os.chdir(self.original_cwd)
|
||||||
shutil.rmtree(self.tempdir, ignore_errors=True)
|
shutil.rmtree(self.tempdir, ignore_errors=True)
|
||||||
|
@ -537,3 +542,30 @@ class TestCommands(TestCase):
|
||||||
del coder
|
del coder
|
||||||
del commands
|
del commands
|
||||||
del repo
|
del repo
|
||||||
|
|
||||||
|
def test_cmd_add_aiderignored_file(self):
|
||||||
|
with GitTemporaryDirectory():
|
||||||
|
repo = git.Repo()
|
||||||
|
|
||||||
|
fname1 = "ignoreme1.txt"
|
||||||
|
fname2 = "ignoreme2.txt"
|
||||||
|
fname3 = "dir/ignoreme3.txt"
|
||||||
|
|
||||||
|
Path(fname2).touch()
|
||||||
|
repo.git.add(str(fname2))
|
||||||
|
repo.git.commit("-m", "initial")
|
||||||
|
|
||||||
|
aignore = Path(".aiderignore")
|
||||||
|
aignore.write_text(f"{fname1}\n{fname2}\ndir\n")
|
||||||
|
|
||||||
|
io = InputOutput(yes=True)
|
||||||
|
coder = Coder.create(
|
||||||
|
models.GPT4, None, io, fnames=[fname1, fname2], aider_ignore_file=str(aignore)
|
||||||
|
)
|
||||||
|
commands = Commands(io, coder)
|
||||||
|
|
||||||
|
commands.cmd_add(f"{fname1} {fname2} {fname3}")
|
||||||
|
|
||||||
|
self.assertNotIn(fname1, str(coder.abs_fnames))
|
||||||
|
self.assertNotIn(fname2, str(coder.abs_fnames))
|
||||||
|
self.assertNotIn(fname3, str(coder.abs_fnames))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue