Commit graph

473 commits

Author SHA1 Message Date
Paul Gauthier
0dd35cdaee aider: Added a new argument --yes to always say yes to every confirmation and passed it to the Coder class.
# Context:
USER: add a new arg --yes without env. pass it to Coder and store in self.yes. "Always say yes to every confirmation"
ASSISTANT: To add a new argument `--yes` and pass it to the `Coder` class, we need to make changes in `aider/main.py` and `aider/coder.py`.

In `aider/main.py`, add the new argument `--yes` to the argument parser and pass it to the `Coder` class.

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--show-diffs",
        action="store_true",
        help=f"Show diffs when committing changes (default: False, ${env_prefix}SHOW_DIFFS)",
        default=bool(int(os.environ.get(f"{env_prefix}SHOW_DIFFS", 0))),
    )
=======
    parser.add_argument(
        "--show-diffs",
        action="store_true",
        help=f"Show diffs when committing changes (default: False, ${env_prefix}SHOW_DIFFS)",
        default=bool(int(os.environ.get(f"{env_prefix}SHOW_DIFFS", 0))),
    )
    parser.add_argument(
        "--yes",
        action="store_true",
        help="Always say yes to every confirmation",
    )
>>>>>>> UPDATED
```

```python
aider/main.py
<<<<<<< ORIGINAL
    coder = Coder(args.model, fnames, pretty, args.history_file, args.show_diffs, args.auto_commits)
=======
    coder = Coder(args.model, fnames, pretty, args.history_file, args.show_diffs, args.auto_commits, args.yes)
>>>>>>> UPDATED
```

In `aider/coder.py`, add the `yes` parameter to the `Coder` class and store it in `self.yes`.

```python
aider/coder.py
<<<<<<< ORIGINAL
    def __init__(self, main_model, fnames, pretty, history_file, show_diffs, auto_commits):
=======
    def __init__(self, main_model, fnames, pretty, history_file, show_diffs, auto_commits, yes):
>>>>>>> UPDATED
```

```python
aider/coder.py
<<<<<<< ORIGINAL
        self.show_diffs = show_diffs
=======
        self.show_diffs = show_diffs
        self.yes = yes
>>>>>>> UPDATED
```

Now, the `--yes` argument is added and passed to the `Coder` class. You can use `self.yes` in the `Coder` class to determine if the user wants to always say yes to every confirmation.
2023-05-11 17:41:23 -07:00
Paul Gauthier
09fbbc0dae wip: Added import subprocess to test_main.py. 2023-05-11 17:39:15 -07:00
Paul Gauthier
fa2f76c107 aider: Added subprocess module to run git init in the temporary directory before calling main in test_main_with_empty_git_dir_new_file.
# Context:
USER: in test_main_with_empty_git_dir_new_file, run git init in the new dir before calling main
ASSISTANT: To run `git init` in the new directory before calling `main`, you can use the `subprocess` module to execute the command. Here's the change you need to make in the `test_main_with_empty_git_dir_new_file` function:

```python
tests/test_main.py
<<<<<<< ORIGINAL
    def test_main_with_empty_git_dir_new_file(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            with open(os.devnull, 'r') as dev_null:
                save_stdin = sys.stdin
                sys.stdin = dev_null
                main(['foo.txt'])
                sys.stdin = save_stdin
=======
    import subprocess

    def test_main_with_empty_git_dir_new_file(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            subprocess.run(["git", "init"])
            with open(os.devnull, 'r') as dev_null:
                save_stdin = sys.stdin
                sys.stdin = dev_null
                main(['foo.txt'])
                sys.stdin = save_stdin
>>>>>>> UPDATED
```

This change imports the `subprocess` module and adds the `subprocess.run(["git", "init"])` line to run `git init` in the temporary directory before calling `main`.
2023-05-11 17:36:33 -07:00
Paul Gauthier
7a29a2911a aider: Added assertion to confirm that foo.txt exists after main exits in test_main_with_empty_dir_new_file.
# Context:
USER: in test_main_with_empty_dir_new_file, confirm that foo.txt exists after main exists
ASSISTANT: To confirm that `foo.txt` exists after `main` exits, you can add an assertion in the `test_main_with_empty_dir_new_file` test case. Here's the change:

```python
tests/test_main.py
<<<<<<< ORIGINAL
                main(['foo.txt'])
                sys.stdin = save_stdin
=======
                main(['foo.txt'])
                sys.stdin = save_stdin
                self.assertTrue(os.path.exists('foo.txt'))
>>>>>>> UPDATED
```
2023-05-11 17:34:35 -07:00
Paul Gauthier
e500f8e37f wip: Refactor main function to include tests for empty directory with no files and new file creation. 2023-05-11 17:33:59 -07:00
Paul Gauthier
490a6999fb allow main() w/o args 2023-05-11 17:28:03 -07:00
Paul Gauthier
00b0369282 aider: Replaced usage of redirect_stdin with closing stdin before calling main.
# Context:
USER: ImportError: cannot import name 'redirect_stdin' from 'contextlib'. Maybe just close stdin before calling main?
ASSISTANT: To fix the ImportError, we can replace the usage of `redirect_stdin` with closing stdin before calling `main`. Here's the change:

```python
tests/test_main.py
<<<<<<< ORIGINAL
from contextlib import redirect_stdin
=======
>>>>>>> UPDATED
```

```python
tests/test_main.py
<<<<<<< ORIGINAL
    with open(os.devnull, 'r') as dev_null:
        with redirect_stdin(dev_null):
                    main()
=======
    with open(os.devnull, 'r') as dev_null:
        sys.stdin.close()
        main()
>>>>>>> UPDATED
```
2023-05-11 17:26:48 -07:00
Paul Gauthier
ac8376c5bc wip: Changed import from redirect_stdout to redirect_stdin in test_main.py. 2023-05-11 17:25:32 -07:00
Paul Gauthier
fe5e313a75 aider: Replaced redirect_stdout with redirect_stdin and opened os.devnull in read mode ('r') instead of write mode ('w').
# Context:
USER: stdin not stdout
ASSISTANT: I apologize for the confusion. To redirect stdin instead of stdout, we need to use `contextlib.redirect_stdin` instead of `contextlib.redirect_stdout`. Here's the updated code change for tests/test_main.py:

```python
tests/test_main.py
<<<<<<< ORIGINAL
    with open(os.devnull, 'w') as dev_null:
        with redirect_stdout(dev_null):
=======
    with open(os.devnull, 'r') as dev_null:
        with redirect_stdin(dev_null):
>>>>>>> UPDATED
            main()
```

This code change replaces `redirect_stdout` with `redirect_stdin` and opens os.devnull in read mode ('r') instead of write mode ('w').
2023-05-11 17:24:57 -07:00
Paul Gauthier
4928450ccf aider: Added a test case for main which creates a temporary directory, changes the current working directory, and invokes the main function with /dev/null piped to stdout.
# Context:
USER: add a test case for main which makes a new empty dir, makes it the cwd and invokes main() with /dev/null piped to stdin.
ASSISTANT: To add a test case for main, we need to import the necessary modules, create a temporary directory, change the current working directory, and invoke the main function with /dev/null piped to stdin. Here's the code change for tests/test_main.py:

```python
tests/test_main.py
<<<<<<< ORIGINAL

=======
import os
import sys
import tempfile
from contextlib import redirect_stdout
from unittest import TestCase
from aider.main import main

class TestMain(TestCase):
    def test_main_with_dev_null(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            with open(os.devnull, 'w') as dev_null:
                with redirect_stdout(dev_null):
                    main()
>>>>>>> UPDATED
```

This code change imports the necessary modules, creates a new test class `TestMain`, and adds a test method `test_main_with_dev_null`. The test method creates a temporary directory, changes the current working directory to the temporary directory, and invokes the `main` function with /dev/null piped to stdout.
2023-05-11 17:24:29 -07:00
Paul Gauthier
88b48bd04b noop 2023-05-11 17:22:58 -07:00
Paul Gauthier
db7aa7cdf1 aider: Created and added tests/test_main.py to git. 2023-05-11 17:17:50 -07:00
Paul Gauthier
7c50fd654a aider: Passed argv to main() and parse_args().
# Context:
USER: have __main__ pass argv to main(). then pass that into parse_args
ASSISTANT: To pass `argv` to `main()` and then pass it to `parse_args`, you need to modify the `main()` function definition to accept an argument and pass `sys.argv[1:]` to it. Then, pass the argument to `parse_args()`.

Here's the change:

```python
aider/main.py
<<<<<<< ORIGINAL
def main():
=======
def main(argv):
>>>>>>> UPDATED

aider/main.py
<<<<<<< ORIGINAL
    args = parser.parse_args()
=======
    args = parser.parse_args(argv)
>>>>>>> UPDATED

aider/main.py
<<<<<<< ORIGINAL
    status = main()
=======
    status = main(sys.argv[1:])
>>>>>>> UPDATED
```
2023-05-11 17:16:40 -07:00
Paul Gauthier
6133eb61c1 fix tests and bug 2023-05-11 17:15:19 -07:00
Paul Gauthier
fe4a2836b7 aider: Added empty __init__.py file to tests directory to fix ModuleNotFoundError when running tests.
# Context:
USER: when I run pytests i get this error

======================================== ERRORS =========================================
_________________________ ERROR collecting tests/test_utils.py __________________________
ImportError while importing test module '/Users/gauthier/Projects/aider/tests/test_utils.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_utils.py:2: in <module>
    from aider.utils import replace_most_similar_chunk, strip_quoted_wrapping
E   ModuleNotFoundError: No module named 'aider'

ASSISTANT: It seems like the `aider` module is not being recognized when running the tests. To fix this issue, you can add an empty `__init__.py` file in the `tests` directory to make it a package. This will help Python recognize the `aider` module when running the tests.

Create a new empty file `tests/__init__.py`:

```python
tests/__init__.py
<<<<<<< ORIGINAL
=======
>>>>>>> UPDATED
```

After creating the empty `__init__.py` file in the `tests` directory, try running the tests again.
2023-05-11 17:12:42 -07:00
Paul Gauthier
6dd586c753 init testing 2023-05-11 17:11:22 -07:00
Paul Gauthier
ea05c00bd1 wip: Added a check to skip auto commits if auto_commits is False. 2023-05-11 17:09:06 -07:00
Paul Gauthier
0213c4344a Added a try-except block to handle GitCommandError and added a check to skip if current_branch_commit_count is None. 2023-05-11 17:02:37 -07:00
Paul Gauthier
a66cbe216e aider: Refactored aider/coder.py to check if there are any commits on the current branch before running the git diff command.
# Context:
USER: can we check if there are any commits on the current branch? rather than any commits in the entire repo?
ASSISTANT: Sure, we can check if there are any commits on the current branch by comparing the current branch's commit count to zero. Here's the change:

```python
aider/coder.py
<<<<<<< ORIGINAL
    if len(repo.heads) > 0:
        these_diffs = repo.git.diff("HEAD", "--color", "--", relative_fname)
    else:
        these_diffs = ""
=======
    current_branch_commit_count = len(list(repo.iter_commits(repo.active_branch)))
    if current_branch_commit_count > 0:
        these_diffs = repo.git.diff("HEAD", "--color", "--", relative_fname)
    else:
        these_diffs = ""
>>>>>>> UPDATED
```

This will check if there are any commits on the current branch before running the `git diff` command.
2023-05-11 16:58:59 -07:00
Paul Gauthier
0cd5f5b812 aider: Checked if there were any commits in the repo before trying to diff.
# Context:
USER: have get_dirty_files_and_diffs check if there are any commits in the repo before trying to diff
ASSISTANT: To check if there are any commits in the repo before trying to diff, we can use `len(repo.heads)` to get the number of branches in the repo. If there are no branches, it means there are no commits. Here's the change:

```python
aider/coder.py
<<<<<<< ORIGINAL
    these_diffs = repo.git.diff("HEAD", "--color", "--", relative_fname)
=======
    if len(repo.heads) > 0:
        these_diffs = repo.git.diff("HEAD", "--color", "--", relative_fname)
    else:
        these_diffs = ""
>>>>>>> UPDATED
```

This will prevent the `git diff` command from running if there are no commits in the repo.
2023-05-11 16:57:49 -07:00
Paul Gauthier
e6f88394f5 Fixed a bug in coder.py where the git diff command was not properly executed. 2023-05-11 16:57:21 -07:00
Paul Gauthier
8e06300495 aider: Fixed GitCommandError by separating paths from revisions using '--' in get_dirty_files_and_diffs function.
# Context:
USER: Traceback (most recent call last):
  File "/Users/gauthier/tmp/try-aider/.venv/bin/aider", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/gauthier/Projects/aider/aider/main.py", line 77, in main
    coder.run()
  File "/Users/gauthier/Projects/aider/aider/coder.py", line 178, in run
    new_user_message = self.run_loop()
                       ^^^^^^^^^^^^^^^
  File "/Users/gauthier/Projects/aider/aider/coder.py", line 219, in run_loop
    return self.send_new_user_message(inp)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gauthier/Projects/aider/aider/coder.py", line 264, in send_new_user_message
    res = self.commit(history=self.cur_messages, prefix="aider: ")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gauthier/Projects/aider/aider/coder.py", line 482, in commit
    relative_dirty_fnames,diffs = get_dirty_files_and_diffs(self.abs_fnames)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gauthier/Projects/aider/aider/coder.py", line 468, in get_dirty_files_and_diffs
    these_diffs = repo.git.diff("HEAD", "--color", relative_fname)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gauthier/tmp/try-aider/.venv/lib/python3.11/site-packages/git/cmd.py", line 741, in <lambda>
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gauthier/tmp/try-aider/.venv/lib/python3.11/site-packages/git/cmd.py", line 1315, in _call_process
    return self.execute(call, **exec_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gauthier/tmp/try-aider/.venv/lib/python3.11/site-packages/git/cmd.py", line 1109, in execute
    raise GitCommandError(redacted_command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
  cmdline: git diff HEAD --color hello.py
  stderr: 'fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]''

ASSISTANT: It seems like there is an issue with the `git diff` command in the `get_dirty_files_and_diffs` function. The error occurs because the 'HEAD' argument is ambiguous. To fix this issue, we can separate the paths from the revisions using '--'. Here's the change:

```python
aider/coder.py
<<<<<<< ORIGINAL
    these_diffs = repo.git.diff("HEAD", "--color", relative_fname)
=======
    these_diffs = repo.git.diff("HEAD", "--color", "--", relative_fname)
>>>>>>> UPDATED
```

This should resolve the `GitCommandError` you encountered.
2023-05-11 16:56:28 -07:00
Paul Gauthier
173a91a8c2 Fixed a bug in Coder class where the common root directory was not being set correctly. 2023-05-11 16:54:10 -07:00
Paul Gauthier
46cd8362b6 aider: Replaced "_" with the current working directory in find_common_root.
# Context:
USER: in find_common_root replace _ with the cwd
ASSISTANT: ```python
aider/coder.py
<<<<<<< ORIGINAL
        if not self.abs_fnames:
            self.root = _
=======
        if not self.abs_fnames:
            self.root = os.getcwd()
>>>>>>> UPDATED
```
2023-05-11 16:53:19 -07:00
Paul Gauthier
be882158e4 Added auto_commits parameter to Coder class constructor. 2023-05-11 15:46:02 -07:00
Paul Gauthier
b018eade37 aider: Added auto_commits as a new argument to the Coder() class and updated main() function to pass the argument.
# Context:
USER: add auto_commits as a new arg to Coder(). assign it to self.auto_commit
ASSISTANT: To add `auto_commits` as a new argument to the `Coder()` class and assign it to `self.auto_commit`, you need to update the `__init__` method in the `aider/coder.py` file:

```python
aider/coder.py
<<<<<<< ORIGINAL
    def __init__(self, main_model, fnames, pretty, history_file, show_diffs):
=======
    def __init__(self, main_model, fnames, pretty, history_file, show_diffs, auto_commits):
>>>>>>> UPDATED
        self.history_file = history_file

        # ... (rest of the code remains unchanged)

        self.show_diffs = show_diffs
<<<<<<< ORIGINAL
=======
        self.auto_commit = auto_commits
>>>>>>> UPDATED
```

Then, update the `main()` function in the `aider/main.py` file to pass the `auto_commits` argument when creating a new `Coder` instance:

```python
aider/main.py
<<<<<<< ORIGINAL
    coder = Coder(args.model, fnames, pretty, args.history_file, args.show_diffs)
=======
    coder = Coder(args.model, fnames, pretty, args.history_file, args.show_diffs, args.auto_commits)
>>>>>>> UPDATED
    coder.commit(ask=True, prefix="wip: ", which="repo_files")

    # ... (rest of the code remains unchanged)
```
2023-05-11 15:45:31 -07:00
Paul Gauthier
8bcbc5b0de Changed help text for disabling auto commit of changes. 2023-05-11 15:43:57 -07:00
Paul Gauthier
37741bed2a aider: Reversed the logic of the --no-auto-commits variable, storing to an "auto_commits" var with default value of True, and updated the environment variable to AUTO_COMMITS in aider/main.py.
# Context:
USER: reverse the logic of the --no-aut-commits variable, so it's storing to an "auto_commits" var. default is true. env is AUTO_COMMITS. but keep the switch as --no-auto-commits
ASSISTANT: To reverse the logic of the `--no-auto-commits` variable, we need to change the variable name to `auto_commits`, set its default value to `True`, and update the environment variable to `AUTO_COMMITS`. Please provide the contents of the file where this variable is defined, so I can suggest the necessary changes.
USER: Please note that I shared content of these additional files: aider/main.py
ASSISTANT: I apologize for the oversight. Here are the changes to reverse the logic of the `--no-auto-commits` variable in the `aider/main.py` file:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--no-auto-commits",
        action="store_true",
        help=f"Do not automatically commit changes (default: False, ${env_prefix}NO_AUTO_COMMITS)",
        default=bool(int(os.environ.get(f"{env_prefix}NO_AUTO_COMMITS", 0))),
    )
=======
    parser.add_argument(
        "--no-auto-commits",
        action="store_false",
        dest="auto_commits",
        help=f"Do not automatically commit changes (default: True, ${env_prefix}AUTO_COMMITS)",
        default=bool(int(os.environ.get(f"{env_prefix}AUTO_COMMITS", 1))),
    )
>>>>>>> UPDATED
```

This change will store the value of the `--no-auto-commits` flag in the `auto_commits` variable, with a default value of `True`. The environment variable is also updated to `AUTO_COMMITS`.
2023-05-11 15:43:18 -07:00
Paul Gauthier
a6d9581e5f aider: Added a --no-auto-commits argument and an environment variable.
# Context:
USER: add a --no-auto-commits arg and env var "Do not automatically commit changes"
ASSISTANT: To add a `--no-auto-commits` argument and an environment variable, we will update the `aider/main.py` file. We will add a new argument to the `argparse.ArgumentParser` and use the environment variable to set its default value.

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--show-diffs",
        action="store_true",
        help=f"Show diffs when committing changes (default: False, ${env_prefix}SHOW_DIFFS)",
        default=bool(int(os.environ.get(f"{env_prefix}SHOW_DIFFS", 0))),
    )
=======
    parser.add_argument(
        "--no-auto-commits",
        action="store_true",
        help=f"Do not automatically commit changes (default: False, ${env_prefix}NO_AUTO_COMMITS)",
        default=bool(int(os.environ.get(f"{env_prefix}NO_AUTO_COMMITS", 0))),
    )
    parser.add_argument(
        "--show-diffs",
        action="store_true",
        help=f"Show diffs when committing changes (default: False, ${env_prefix}SHOW_DIFFS)",
        default=bool(int(os.environ.get(f"{env_prefix}SHOW_DIFFS", 0))),
    )
>>>>>>> UPDATED
```

Now, you can use the `--no-auto-commits` argument when running the script, and it will also read the `AIDER_NO_AUTO_COMMITS` environment variable to set its default value.
2023-05-11 15:41:09 -07:00
Paul Gauthier
b83ef2f30f updated readme 2023-05-11 09:43:05 -07:00
Paul Gauthier
e5abb97eaa wip: Changed get_dirty_files to get_dirty_files_and_diffs to also return diffs. 2023-05-11 09:39:01 -07:00
Paul Gauthier
42a4df139c Removed unused import and function call in cmd_commit. 2023-05-11 09:37:36 -07:00
Paul Gauthier
fe0f8928a2 honor the user provided /commit message 2023-05-11 09:37:20 -07:00
Paul Gauthier
db2e062634 wip: Added methods to get context from history and commit message. 2023-05-11 09:36:34 -07:00
Paul Gauthier
adbdbbcb74 Added import of dump function from aider.dump module to cmd_commit function in commands.py. 2023-05-11 09:30:17 -07:00
Paul Gauthier
c9ff2ed7e9 Added a dump statement to cmd_commit function. 2023-05-11 09:29:51 -07:00
Paul Gauthier
1f4a54cf01 Fixed a bug where the commit command was not being executed when the repo was dirty. 2023-05-11 09:29:11 -07:00
Paul Gauthier
34fac7b4b9 Fixed a bug where the commit command was being triggered when the repo was dirty. 2023-05-11 09:28:36 -07:00
Paul Gauthier
0434f71c9f wip: Refactor console message for uncommitted changes in coder.py. 2023-05-11 09:26:55 -07:00
Paul Gauthier
23a0339a15 Removed dump function call from coder.py. 2023-05-11 09:25:09 -07:00
Paul Gauthier
4d263eda10 Removed get_last_modified method and replaced last_modified check with repo.is_dirty. 2023-05-11 09:24:32 -07:00
Paul Gauthier
14b45f40f6 finishing support for which=repo_files 2023-05-11 09:22:51 -07:00
Paul Gauthier
6e68562cd0 fixed reference to repo var 2023-05-11 09:15:12 -07:00
Paul Gauthier
cee1dfd3b9 aider: Added an elif clause for which == "chat_files" and a final else clause to raise a ValueError if the value of which is not valid.
# Context:
USER: nice! in the change the else: to elseif which==chat_files and throw a valueerror as a final else clause
ASSISTANT: To update the `commit()` function with the requested changes, we will modify the `if` statement to include an `elif` clause for `which == "chat_files"` and add a final `else` clause to raise a `ValueError`.

```python
aider/coder.py
<<<<<<< ORIGINAL
        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)
=======
        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)
        elif which == "chat_files":
            dirty_fnames, relative_dirty_fnames = get_dirty_files(self.abs_fnames)
        else:
            raise ValueError(f"Invalid value for 'which': {which}")
>>>>>>> UPDATED
```

This change adds an `elif` clause for `which == "chat_files"` and a final `else` clause to raise a `ValueError` if the value of `which` is not valid.
2023-05-11 09:13:25 -07:00
Paul Gauthier
da40aaa6ca 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`.
2023-05-11 09:11:48 -07:00
Paul Gauthier
f5bfd41ecd updated readme 2023-05-11 06:20:29 -07:00
Paul Gauthier
05cbb79069 fixed merge conflict 2023-05-11 06:17:53 -07:00
Paul Gauthier
0a7c5d1a78 wip: Removed unnecessary lines of code in coder.py. 2023-05-11 06:03:11 -07:00
Paul Gauthier
e875d0ca7f Refactor loop to use class attribute instead of parameter. 2023-05-11 06:02:21 -07:00
Paul Gauthier
a614179209 fix logic when there is no git repo 2023-05-11 06:01:37 -07:00