mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 14:55:00 +00:00
/add and /drop should work on untracked files in a repo (without committing them)
This commit is contained in:
parent
f6aa09ca85
commit
95fe1be4c5
2 changed files with 27 additions and 36 deletions
|
@ -283,8 +283,6 @@ class Commands:
|
||||||
"Add files to the chat so GPT can edit them or review them in detail"
|
"Add files to the chat so GPT can edit them or review them in detail"
|
||||||
|
|
||||||
added_fnames = []
|
added_fnames = []
|
||||||
git_added = []
|
|
||||||
git_files = self.coder.repo.get_tracked_files() if self.coder.repo else []
|
|
||||||
|
|
||||||
all_matched_files = set()
|
all_matched_files = set()
|
||||||
|
|
||||||
|
@ -311,7 +309,6 @@ class Commands:
|
||||||
|
|
||||||
for matched_file in all_matched_files:
|
for matched_file in all_matched_files:
|
||||||
abs_file_path = self.coder.abs_root_path(matched_file)
|
abs_file_path = self.coder.abs_root_path(matched_file)
|
||||||
rel_path = self.coder.get_rel_fname(matched_file)
|
|
||||||
|
|
||||||
if not abs_file_path.startswith(self.coder.root):
|
if not abs_file_path.startswith(self.coder.root):
|
||||||
self.io.tool_error(
|
self.io.tool_error(
|
||||||
|
@ -319,14 +316,6 @@ class Commands:
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if self.coder.repo and rel_path not in git_files:
|
|
||||||
try:
|
|
||||||
self.coder.repo.repo.git.add(abs_file_path)
|
|
||||||
git_added.append(matched_file)
|
|
||||||
except git.exc.GitCommandError as e:
|
|
||||||
self.io.tool_error(f"Unable to add {matched_file}: {str(e)}")
|
|
||||||
continue
|
|
||||||
|
|
||||||
if abs_file_path in self.coder.abs_fnames:
|
if abs_file_path in self.coder.abs_fnames:
|
||||||
self.io.tool_error(f"{matched_file} is already in the chat")
|
self.io.tool_error(f"{matched_file} is already in the chat")
|
||||||
else:
|
else:
|
||||||
|
@ -338,11 +327,6 @@ class Commands:
|
||||||
self.io.tool_output(f"Added {matched_file} to the chat")
|
self.io.tool_output(f"Added {matched_file} to the chat")
|
||||||
added_fnames.append(matched_file)
|
added_fnames.append(matched_file)
|
||||||
|
|
||||||
if self.coder.repo and git_added and self.coder.auto_commits:
|
|
||||||
git_added = " ".join(git_added)
|
|
||||||
commit_message = f"aider: Added {git_added}"
|
|
||||||
self.coder.repo.commit(message=commit_message)
|
|
||||||
|
|
||||||
if not added_fnames:
|
if not added_fnames:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -372,7 +356,7 @@ class Commands:
|
||||||
matched_files = self.glob_filtered_to_repo(word)
|
matched_files = self.glob_filtered_to_repo(word)
|
||||||
|
|
||||||
if not matched_files:
|
if not matched_files:
|
||||||
self.io.tool_error(f"No files matched '{word}'")
|
matched_files.append(word)
|
||||||
|
|
||||||
for matched_file in matched_files:
|
for matched_file in matched_files:
|
||||||
abs_fname = self.coder.abs_root_path(matched_file)
|
abs_fname = self.coder.abs_root_path(matched_file)
|
||||||
|
|
|
@ -414,25 +414,6 @@ class TestCommands(TestCase):
|
||||||
|
|
||||||
self.assertIn(str(fname.resolve()), coder.abs_fnames)
|
self.assertIn(str(fname.resolve()), coder.abs_fnames)
|
||||||
|
|
||||||
def test_cmd_add_no_autocommit(self):
|
|
||||||
with GitTemporaryDirectory():
|
|
||||||
io = InputOutput(pretty=False, yes=True)
|
|
||||||
from aider.coders import Coder
|
|
||||||
|
|
||||||
coder = Coder.create(models.GPT35, None, io, auto_commits=False)
|
|
||||||
commands = Commands(io, coder)
|
|
||||||
|
|
||||||
commands.cmd_add("foo.txt")
|
|
||||||
|
|
||||||
# Check if both files have been created in the temporary directory
|
|
||||||
self.assertTrue(os.path.exists("foo.txt"))
|
|
||||||
|
|
||||||
repo = git.Repo()
|
|
||||||
|
|
||||||
# Assert that foo.txt has been `git add` but not `git commit`
|
|
||||||
added_files = repo.git.diff("--cached", "--name-only").split()
|
|
||||||
self.assertIn("foo.txt", added_files)
|
|
||||||
|
|
||||||
def test_cmd_add_existing_with_dirty_repo(self):
|
def test_cmd_add_existing_with_dirty_repo(self):
|
||||||
with GitTemporaryDirectory():
|
with GitTemporaryDirectory():
|
||||||
repo = git.Repo()
|
repo = git.Repo()
|
||||||
|
@ -485,3 +466,29 @@ class TestCommands(TestCase):
|
||||||
|
|
||||||
commands.cmd_add("file.txt")
|
commands.cmd_add("file.txt")
|
||||||
self.assertEqual(coder.abs_fnames, set())
|
self.assertEqual(coder.abs_fnames, set())
|
||||||
|
|
||||||
|
def test_cmd_add_drop_untracked_files(self):
|
||||||
|
with GitTemporaryDirectory():
|
||||||
|
repo = git.Repo()
|
||||||
|
|
||||||
|
io = InputOutput(pretty=False, yes=False)
|
||||||
|
from aider.coders import Coder
|
||||||
|
|
||||||
|
coder = Coder.create(models.GPT35, None, io)
|
||||||
|
commands = Commands(io, coder)
|
||||||
|
|
||||||
|
fname = Path("test.txt")
|
||||||
|
fname.touch()
|
||||||
|
|
||||||
|
self.assertEqual(len(coder.abs_fnames), 0)
|
||||||
|
|
||||||
|
commands.cmd_add(str(fname))
|
||||||
|
|
||||||
|
files_in_repo = repo.git.ls_files()
|
||||||
|
self.assertNotIn(str(fname), files_in_repo)
|
||||||
|
|
||||||
|
self.assertEqual(len(coder.abs_fnames), 1)
|
||||||
|
|
||||||
|
commands.cmd_drop(str(fname))
|
||||||
|
|
||||||
|
self.assertEqual(len(coder.abs_fnames), 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue