aider: Updated commit() to handle which="repo_files", committing all pending changes to all the files in the repo.

# Context:
USER: update commit() to handle which="repo_files". in that case, it should commit all pending changes to all the files in the repo, not just the chat files in self.abs_fnames
ASSISTANT: To update the `commit()` function to handle `which="repo_files"`, we will modify the function to commit all pending changes to all the files in the repo when `which` is set to `"repo_files"`.

```python
aider/coder.py
<<<<<<< ORIGINAL
    def commit(self, history=None, prefix=None, ask=False, message=None, which="chat_files"):
=======
    def commit(self, history=None, prefix=None, ask=False, message=None, which="chat_files"):
        def get_dirty_files(file_list):
            dirty_files = []
            relative_dirty_files = []
            for fname in file_list:
                relative_fname = os.path.relpath(fname, repo.working_tree_dir)
                if self.pretty:
                    these_diffs = repo.git.diff("HEAD", "--color", relative_fname)
                else:
                    these_diffs = repo.git.diff("HEAD", relative_fname)

                if these_diffs:
                    dirty_files.append(fname)
                    relative_dirty_files.append(relative_fname)

            return dirty_files, relative_dirty_files

        if which == "repo_files":
            all_files = [os.path.join(self.root, f) for f in self.get_all_relative_files()]
            dirty_fnames, relative_dirty_fnames = get_dirty_files(all_files)
        else:
            dirty_fnames, relative_dirty_fnames = get_dirty_files(self.abs_fnames)
>>>>>>> UPDATED
```

This change adds a new function `get_dirty_files()` inside the `commit()` function to get the dirty files and their relative paths based on the provided file list. Then, we check the value of `which` and set the `dirty_fnames` and `relative_dirty_fnames` accordingly. If `which` is `"repo_files"`, we use all the files in the repo; otherwise, we use the chat files in `self.abs_fnames`.
This commit is contained in:
Paul Gauthier 2023-05-11 09:11:48 -07:00
parent f5bfd41ecd
commit da40aaa6ca

View file

@ -418,7 +418,28 @@ class Coder:
return edited
def commit(self, history=None, prefix=None, ask=False, message=None):
def commit(self, history=None, prefix=None, ask=False, message=None, which="chat_files"):
def get_dirty_files(file_list):
dirty_files = []
relative_dirty_files = []
for fname in file_list:
relative_fname = os.path.relpath(fname, repo.working_tree_dir)
if self.pretty:
these_diffs = repo.git.diff("HEAD", "--color", relative_fname)
else:
these_diffs = repo.git.diff("HEAD", relative_fname)
if these_diffs:
dirty_files.append(fname)
relative_dirty_files.append(relative_fname)
return dirty_files, relative_dirty_files
if which == "repo_files":
all_files = [os.path.join(self.root, f) for f in self.get_all_relative_files()]
dirty_fnames, relative_dirty_fnames = get_dirty_files(all_files)
else:
dirty_fnames, relative_dirty_fnames = get_dirty_files(self.abs_fnames)
repo = self.repo
if not repo:
return