Commit graph

110 commits

Author SHA1 Message Date
Paul Gauthier
e2b5c6074f lint 2023-05-09 13:10:38 -07:00
Paul Gauthier
2391c2e49b lint 2023-05-09 13:09:05 -07:00
Paul Gauthier
540c0b10b9 Add --show-diffs parameter and only print diffs if it is set to True.
# Context:
USER: add a --show-diffs parameter  which defaults to false. allow an env var to override the default. pass this to Coder.__init__() and use it to set a self.show_diffs. only self.console.print(Text(diffs)) if it is true.
ASSISTANT: To add a `--show-diffs` parameter with a default value of `False` and allow an environment variable to override the default, we will make changes to `aider/main.py`. We will also pass this value to `Coder.__init__()` and use it to set `self.show_diffs`. Finally, we will only print the diffs if `self.show_diffs` is `True`.

Here are the changes:

```python
aider/main.py
<<<<<<< ORIGINAL
        default=bool(int(os.environ.get(f"{env_prefix}COMMIT_DIRTY", 0))),
    )
    args = parser.parse_args()
=======
        default=bool(int(os.environ.get(f"{env_prefix}COMMIT_DIRTY", 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))),
    )
    args = parser.parse_args()
>>>>>>> UPDATED
```

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

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

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

```python
aider/coder.py
<<<<<<< ORIGINAL
        self.console.print(Text(diffs))
=======
        if self.show_diffs:
            self.console.print(Text(diffs))
>>>>>>> UPDATED
```

These changes will add the `--show-diffs` parameter and only print the diffs if the parameter is set to `True`.
2023-05-09 13:04:43 -07:00
Paul Gauthier
0782e50f6d WIP: Refactor Coder class constructor to remove default value for history_file parameter. 2023-05-09 12:59:21 -07:00
Paul Gauthier
875d9f8c9b Added yes defaults 2023-05-09 12:48:50 -07:00
Paul Gauthier
8654a4201f WIP: Change output file name from "tmp.last-edit.md" to ".aider.last.md". 2023-05-09 12:42:27 -07:00
Paul Gauthier
97cf30b0f0 WIP: Fix GitPython issue with GitDB in coder.py. 2023-05-09 12:41:38 -07:00
Paul Gauthier
0cfbabb03b Handle InvalidGitRepositoryError by replacing list comprehension with for loop and try-except.
# Context:
USER: unroll the list comprehension so we can try/catch the exception below which is thrown for files not in any git repo

  File "/Users/gauthier/Projects/aider/aider/coder.py", line 68, in <genexpr>
    git.Repo(fname, search_parent_directories=True).git_dir
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gauthier/tmp/try-aider/.venv/lib/python3.11/site-packages/git/repo/base.py", line 265, in __init__
    raise InvalidGitRepositoryError(epath)
git.exc.InvalidGitRepositoryError: /Users/gauthier/tmp/try-aider/tmp.py

ASSISTANT: To unroll the list comprehension and handle the exception, we can replace it with a for loop and use try-except to catch the `InvalidGitRepositoryError`.

```python
aider/coder.py
<<<<<<< ORIGINAL
        repo_paths = list(
            git.Repo(fname, search_parent_directories=True).git_dir
            for fname in self.fnames
        )
=======
        repo_paths = []
        for fname in self.fnames:
            try:
                repo_path = git.Repo(fname, search_parent_directories=True).git_dir
                repo_paths.append(repo_path)
            except git.exc.InvalidGitRepositoryError:
                pass
>>>>>>> UPDATED
```

This change will catch the `InvalidGitRepositoryError` and continue processing the remaining files.
2023-05-09 11:31:52 -07:00
Paul Gauthier
132e0a687f WIP: Refactor imports and remove unused code in coder.py. 2023-05-09 11:30:34 -07:00
Paul Gauthier
984e2f78ce moved into subdir 2023-05-09 10:52:18 -07:00
Renamed from coder.py (Browse further)