Commit graph

159 commits

Author SHA1 Message Date
Paul Gauthier
abbe5416a1 Refactored GitRepo class to use consistent quotation marks for git commands. 2024-05-18 18:30:50 -07:00
Paul Gauthier
5d8ed278aa aider: Add get_dirty_files() method to return all dirty files staged or in the working directory.
# Aider chat conversation:

USER: add a get_dirty_files() method which returns all the files which are dirty (not committed) either staged or in the working dir.

ASSISTANT: To add the `get_dirty_files()` method, we need to:

1. Define the new method in the `GitRepo` class.
2. Implement the logic to return all dirty files, both staged and in the working directory.

Here is the *SEARCH/REPLACE* block:

aider/repo.py
```python
<<<<<<< SEARCH
    def is_dirty(self, path=None):
=======
    def get_dirty_files(self):
        """
        Returns a list of all files which are dirty (not committed), either staged or in the working directory.
        """
        dirty_files = set()

        # Get staged files
        staged_files = self.repo.git.diff('--name-only', '--cached').splitlines()
        dirty_files.update(staged_files)

        # Get unstaged files
        unstaged_files = self.repo.git.diff('--name-only').splitlines()
        dirty_files.update(unstaged_files)

        return list(dirty_files)

>>>>>>> REPLACE
```

aider/repo.py
```python
<<<<<<< SEARCH
        return self.repo.is_dirty(path=path)
=======
        return self.repo.is_dirty(path=path)
>>>>>>> REPLACE
```
2024-05-18 18:13:08 -07:00
Paul Gauthier
b882d5db4c Do not require gpt-3.5 in GitRepo 2024-04-20 09:47:43 -07:00
Paul Gauthier
4e50f0d095 Support weak_model=False 2024-04-19 14:05:58 -07:00
Paul Gauthier
f81b62dfea Added --require-model-info 2024-04-19 14:01:02 -07:00
Paul Gauthier
f0f0c330d7 cleanup 2024-04-19 12:14:58 -07:00
Paul Gauthier
733c09d30f fixed test_repo 2024-04-18 14:55:56 -07:00
Paul Gauthier
c770fc4380 cleaned up client refs 2024-04-17 15:47:07 -07:00
Paul Gauthier
f1a31d3944 pass in commit models to gitrepo 2024-04-17 15:41:30 -07:00
Paul Gauthier
a84b4f8144 Add the ability to add images that are located outside the git repo #519 2024-04-12 08:26:49 -07:00
Paul Gauthier
c2b8b2355d Handle diffs on a detached head #520 2024-04-12 08:26:49 -07:00
Paul Gauthier
6dd5ae69e3 Normalize paths before checking aiderignore #479 2024-02-25 15:54:57 -08:00
Paul Gauthier
a9fe4532c7 Aider should fully ignore files in aiderignore #479 2024-02-24 09:39:33 -08:00
Christopher Toth
ba87510db1 Fix issue with path normalization that was causing files to be marked dirty on Windows when they were not 2023-12-29 13:04:46 -05:00
Paul Gauthier
57ab2cc9da Revert "implement deployment id"
This reverts commit b107db98fa.
2023-12-06 09:20:53 -08:00
Paul Gauthier
b107db98fa implement deployment id 2023-12-05 11:31:17 -08:00
Paul Gauthier
2ed0c8fb66 fixed test_repo 2023-12-05 10:58:44 -08:00
Paul Gauthier
fb07b784f6 move to gpt-3.5-turbo-1106 2023-12-05 10:28:27 -08:00
Paul Gauthier
6ebc142377 roughed in openai 1.x 2023-12-05 07:37:05 -08:00
Paul Gauthier
5756812938 Adopt subprocess.run(shell=True) for /git 2023-10-18 12:37:39 -07:00
Paul Gauthier
1085549548 Give up testing aiderignore caching in github actions 2023-10-18 12:28:24 -07:00
Paul Gauthier
df27007c00 wtf 2023-10-18 12:22:01 -07:00
Paul Gauthier
1a2370f9ae sleep in the test 2023-10-18 12:15:11 -07:00
Paul Gauthier
b87c9f14fb put back caching, add debug output 2023-10-18 12:11:07 -07:00
Paul Gauthier
d1cd0f9860 do not cache aiderignore 2023-10-18 12:06:47 -07:00
Paul Gauthier
cf00037442 st_mtime_ns? 2023-10-18 12:04:09 -07:00
Paul Gauthier
a1cb6e4e7a More paranoid mtime check 2023-10-18 11:55:04 -07:00
Paul Gauthier
2e6c785c3b cache aiderignore 2023-10-18 10:39:07 -07:00
Paul Gauthier
583c3285ec added tests, fixed bug 2023-10-18 10:31:45 -07:00
Paul Gauthier
9725b236a3 roughed in .aiderignore 2023-10-18 10:26:43 -07:00
Paul Gauthier
f8e30ad7a0 aider: Added import for pathspec library and implemented filter_ignored_files method to filter filenames according to gitignore type specifications in self.aider_ignore_file.
# Aider chat conversation:

ASSISTANT: To implement the `filter_ignored_files` method, we need to use the `pathspec` library to filter the filenames according to the gitignore type specifications in `self.aider_ignore_file`.

The `pathspec` library is not currently imported in the `repo.py` file, so we need to add that import.

We also need to read the `aider_ignore_file` and use its contents to create a `pathspec` that we can use to filter the filenames.

Here are the changes:

```python
aider/repo.py
<<<<<<< HEAD
import os
from pathlib import Path, PurePosixPath

import git

from aider import models, prompts, utils
from aider.sendchat import simple_send_with_retries

from .dump import dump  # noqa: F401
=======
import os
import pathspec
from pathlib import Path, PurePosixPath

import git

from aider import models, prompts, utils
from aider.sendchat import simple_send_with_retries

from .dump import dump  # noqa: F401
>>>>>>> updated
```

```python
aider/repo.py
<<<<<<< HEAD
    def filter_ignored_files(self, fnames):
        if not self.aider_ignore_file:
            return

        # todo: use pathspec to filter fnames according to the gitignore type specs in self.aider_ignore_file
=======
    def filter_ignored_files(self, fnames):
        if not self.aider_ignore_file:
            return fnames

        with open(self.aider_ignore_file, 'r') as f:
            ignore_spec = pathspec.PathSpec.from_lines('gitwildmatch', f)

        return [fname for fname in fnames if not ignore_spec.match_file(fname)]
>>>>>>> updated
```

Please note that these changes assume that `self.aider_ignore_file` is a path to a file containing gitignore-style patterns, one per line. If `self.aider_ignore_file` is not in this format, the code may need to be adjusted.
2023-10-18 10:24:54 -07:00
Paul Gauthier
10f2e114c5 Added a new parameter aider_ignore_file to the __init__ method of GitRepo class and added a new method filter_ignored_files to filter files based on gitignore type specs. 2023-10-18 10:24:52 -07:00
Paul Gauthier
6d5827643f don't try and commit unless there are changes #264 2023-09-25 14:55:00 -07:00
JV
041f3a4a38 initial code for working with openrouter 2023-08-23 14:39:12 +12:00
Paul Gauthier
ae8d04a95f Handle diff of file not yet part of repo 2023-08-18 13:20:27 -07:00
Paul Gauthier
285536105e Properly handle all diff cases 2023-08-18 10:07:47 -07:00
Paul Gauthier
752e47a886 better tests, small cleanups 2023-08-18 09:43:40 -07:00
Paul Gauthier
e608a351f0 standardize on abs_root_path(), simplify get/apply_edit 2023-08-18 07:20:15 -07:00
Paul Gauthier
8f26c27921 just diff the named files on commit 2023-08-18 07:09:16 -07:00
Paul Gauthier
389bf9310c commit just the edited files, treat named files outside git as dirty 2023-08-18 07:05:48 -07:00
Paul Gauthier
d89316147a do not add new files to git 2023-08-17 16:31:21 -07:00
Paul Gauthier
d981de5f5f do the commit before applying edits 2023-08-17 10:40:01 -07:00
Paul Gauthier
6e9fbdcb6a fixed spurious "Adding to git" messages when running aider in subdir of repo 2023-08-17 08:32:44 -07:00
Paul Gauthier
a1da6cab24 ensure we diff properly in all cases, with tests #191 2023-08-10 15:33:53 -03:00
Paul Gauthier
589e7eefea We always want diffs of working-dir + index versus repo #184 2023-08-08 09:00:19 -03:00
Paul Gauthier
64c50bab48 Accept either a git dname or a list of fnames 2023-07-24 17:31:00 -03:00
Paul Gauthier
66da82094d use index.entries 2023-07-24 13:47:33 -03:00
Paul Gauthier
df096272bc aider: Refactored get_tracked_files method to use index.entries instead of index.diff to enumerate staged files.
# Aider chat conversation:

USER: is there any way to enumerate the staged files using the index besides index.diff

ASSISTANT: Yes, you can enumerate the staged files using the `index.entries` property of the `IndexFile` object. This property returns a dictionary-like object where the keys are the file paths and the values are `IndexEntry` objects.

Here's how you can modify the `get_tracked_files` method in the `GitRepo` class to use `index.entries` instead of `index.diff`:

```python
aider/repo.py
<<<<<<< ORIGINAL
    def get_tracked_files(self):
        if not self.repo:
            return []

        try:
            commit = self.repo.head.commit
        except ValueError:
            commit = None

        files = []
        if commit:
            for blob in commit.tree.traverse():
                if blob.type == "blob":  # blob is a file
                    files.append(blob.path)

        # Add staged files
        index = self.repo.index
        staged_files = [item.a_path for item in index.diff(None)]
        dump(staged_files)
        files.extend(staged_files)

        # convert to appropriate os.sep, since git always normalizes to /
        res = set(str(Path(PurePosixPath(path))) for path in files)

        return res
=======
    def get_tracked_files(self):
        if not self.repo:
            return []

        try:
            commit = self.repo.head.commit
        except ValueError:
            commit = None

        files = []
        if commit:
            for blob in commit.tree.traverse():
                if blob.type == "blob":  # blob is a file
                    files.append(blob.path)

        # Add staged files
        index = self.repo.index
        staged_files = [str(Path(PurePosixPath(path))) for path in index.entries.keys()]
        dump(staged_files)
        files.extend(staged_files)

        # convert to appropriate os.sep, since git always normalizes to /
        res = set(str(Path(PurePosixPath(path))) for path in files)

        return res
>>>>>>> UPDATED
```

This change will make the `get_tracked_files` method return all files in the index, not just the ones that have been modified. If you only want to get the files that have been modified, you should stick with using `index.diff`.
2023-07-24 13:45:10 -03:00
Paul Gauthier
f87ec8c38b Refactor getting staged files to handle ValueError. 2023-07-24 13:44:22 -03:00
Paul Gauthier
89542d2139 aider: Handle the case where the repository has never had any commits by using index.diff(None) to get the staged files.
# Aider chat conversation:

USER: index.diff("HEAD") fails when the repo has never had any commits

ASSISTANT: To handle the case where the repository has never had any commits, we can add a try-except block around the `index.diff("HEAD")` call in the `get_tracked_files` method of the `GitRepo` class in the `aider/repo.py` file. If a `git.exc.BadName` exception is raised, we can assume that there are no commits and return an empty list for the staged files.

Here is the proposed change:

```python
aider/repo.py
<<<<<<< ORIGINAL
        # Add staged files
        index = self.repo.index
        staged_files = [item.a_path for item in index.diff("HEAD")]
        files.extend(staged_files)
=======
        # Add staged files

^C KeyboardInterrupt

USER: there can be staged files when there are not commits

ASSISTANT: You're correct. If there are no commits, `index.diff("HEAD")` will fail, but there can still be staged files. We can use `index.diff(None)` to get the staged files in this case. Here's the proposed change:

```python
aider/repo.py
<<<<<<< ORIGINAL
        # Add staged files
        index = self.repo.index
        staged_files = [item.a_path for item in index.diff("HEAD")]
        files.extend(staged_files)
=======
        # Add staged files
        index = self.repo.index
        try:
            staged_files = [item.a_path for item in index.diff("HEAD")]
        except git.exc.BadName:
            staged_files = [item.a_path for item in index.diff(None)]
        files.extend(staged_files)
>>>>>>> UPDATED
```
2023-07-24 13:43:05 -03:00