From da40aaa6cab3578da8bcfffbefcaf041fb676084 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 11 May 2023 09:11:48 -0700 Subject: [PATCH] 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`. --- aider/coder.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/aider/coder.py b/aider/coder.py index b74f6ddd5..053e17f04 100755 --- a/aider/coder.py +++ b/aider/coder.py @@ -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