paul-gauthier / aider

aider is AI pair programming in your terminal
https://aider.chat/
Apache License 2.0
17.64k stars 1.65k forks source link

Aider uses GitPython, which doesn't work with index-version 3 git repos #211

Open daniel-nimptsch opened 1 year ago

daniel-nimptsch commented 1 year ago

When executing aider in an existing repo with R, Python, and Bash scripts, I get this error. When executing aider in a much smaller repo of only Python files, it works without problems. Thank you very much.

Error

aider

Aider v0.12.0
Add .aider* to .gitignore (recommended)? y
Added .aider* to .gitignore
Model: gpt-4
Git repo: .git
Repo-map: universal-ctags using 1024 tokens
Added src/blastn/blastout_to_table/blastout_to_table.R to the chat.
Traceback (most recent call last):
  File "/var/home/soye/.mambaforge/envs/aider-chat/bin/aider", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/aider/main.py", line 479, in main
    coder = Coder.create(
            ^^^^^^^^^^^^^
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/aider/coders/base_coder.py", line 84, in create
    return EditBlockCoder(main_model, io, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/aider/coders/editblock_coder.py", line 14, in __init__
    super().__init__(*args, **kwargs)
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/aider/coders/base_coder.py", line 206, in __init__
    self.repo.add_new_files(fname for fname in fnames if not Path(fname).is_dir())
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/aider/repo.py", line 53, in add_new_files
    cur_files = [Path(fn).resolve() for fn in self.get_tracked_files()]
                                              ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/aider/repo.py", line 181, in get_tracked_files
    staged_files = [path for path, _ in index.entries.keys()]
                                        ^^^^^^^^^^^^^
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/gitdb/util.py", line 253, in __getattr__
    self._set_cache_(attr)
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/git/index/base.py", line 149, in _set_cache_
    self._deserialize(stream)
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/git/index/base.py", line 177, in _deserialize
    self.version, self.entries, self._extension_data, _conten_sha = read_cache(stream)
                                                                    ^^^^^^^^^^^^^^^^^^
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/git/index/fun.py", line 245, in read_cache
    version, num_entries = read_header(stream)
                           ^^^^^^^^^^^^^^^^^^^
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/git/index/fun.py", line 212, in read_header
    assert version in (1, 2)
           ^^^^^^^^^^^^^^^^^
AssertionError

Details

aider --version

aider 0.12.0

ctags --version

Universal Ctags 6.0.0, Copyright (C) 2015-2022 Universal Ctags Team
Universal Ctags is derived from Exuberant Ctags.
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Aug 13 2023, 02:54:31
  URL: https://ctags.io/
  Output version: 0.0
  Optional compiled features: +wildcards, +regex, +gnulib_regex, +iconv, +option-directory, +xpath, +json, +interactive, +sandbox, +yaml, +packcc, +optscript
paul-gauthier commented 1 year ago

Thanks for trying aider and reporting this issue.

It looks like your git repo may be using a newer index format, which might not be supported by GitPython.

This GitPython issue has some more info and workarounds. You might want to try git update-index --no-skip-worktree based on that issue.

daniel-nimptsch commented 1 year ago

I tried git update-index --no-skip-worktree and unfortunately it did not solve the issue. I was able to launch aider in my project by copying it and then removing .git. However, after trying to add a file, it breaks again:

Aider v0.12.0
Model: gpt-4
Git repo: .git
Repo-map: universal-ctags using 1024 tokens
Added pipeline_scripts_dn.R to the chat.
Adding /var/home/soye/Projects/pipeline_scripts_dn_aider/pipeline_scripts_dn.R to git
Use /help to see in-chat commands, run with --help to see cmd line args
Git repo has uncommitted changes.
diff --git a/pipeline_scripts_dn.R b/pipeline_scripts_dn.R
new file mode 100644
index 0000000..e69de29
Traceback (most recent call last):
  File "/var/home/soye/.mambaforge/envs/aider-chat/bin/aider", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/aider/main.py", line 518, in main
    coder.dirty_commit()
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/aider/coders/base_coder.py", line 880, in dirty_commit
    self.last_asked_for_commit_time = self.get_last_modified()
                                      ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/aider/coders/base_coder.py", line 722, in get_last_modified
    files = [Path(fn) for fn in self.get_all_abs_files() if Path(fn).exists()]
                                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/aider/coders/base_coder.py", line 717, in get_all_abs_files
    files = self.get_all_relative_files()
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/aider/coders/base_coder.py", line 710, in get_all_relative_files
    files = self.repo.get_tracked_files()
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/aider/repo.py", line 181, in get_tracked_files
    staged_files = [path for path, _ in index.entries.keys()]
                                        ^^^^^^^^^^^^^
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/gitdb/util.py", line 253, in __getattr__
    self._set_cache_(attr)
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/git/index/base.py", line 149, in _set_cache_
    self._deserialize(stream)
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/git/index/base.py", line 177, in _deserialize
    self.version, self.entries, self._extension_data, _conten_sha = read_cache(stream)
                                                                    ^^^^^^^^^^^^^^^^^^
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/git/index/fun.py", line 245, in read_cache
    version, num_entries = read_header(stream)
                           ^^^^^^^^^^^^^^^^^^^
  File "/var/home/soye/.mambaforge/envs/aider-chat/lib/python3.11/site-packages/git/index/fun.py", line 212, in read_header
    assert version in (1, 2)
           ^^^^^^^^^^^^^^^^^
AssertionError
paul-gauthier commented 1 year ago

Ok, I am glad to hear you found a good workaround for your git repo.

mi-skam commented 9 months ago

He actually, didn't found a workaround :-) Besides I have the same issue

yqrashawn commented 9 months ago

Same issue here, @paul-gauthier you might be able to reproduce on your side, the repo is https://github.com/status-im/status-mobile, it's a large repo

Aider v0.18.0

datashaman commented 8 months ago

This works for me:

git update-index --index-version=2
dwaltrip commented 4 months ago

I'm also hitting this issue (see below), but unfortunately none of the workarounds worked for me. Curiously, I don't seem to be getting it in my other repo.

Workarounds tried:

Error:

$ aider --openai-api-key sk-xxx-...-zzz
Aider v0.30.1
Models: gpt-4-1106-preview with udiff edit format, weak model gpt-3.5-turbo
Traceback (most recent call last):
  File "/Users/danielwaltrip/.local/bin/aider", line 8, in <module>
    sys.exit(main())
             ^^^^^^

  ... (more stack info)

  File "/Users/danielwaltrip/.local/pipx/venvs/aider-chat/lib/python3.12/site-packages/git/index/fun.py", line 210, in read_header
    assert version in (1, 2)
           ^^^^^^^^^^^^^^^^^
AssertionError

P.S. Just wanna say I love the idea of aider. Thanks for making it as well as open sourcing it

dwaltrip commented 4 months ago

Update: I was able to fix my issue by updating to the latest version of git (2.44) and running the git update-index --index-version=2 command. Aider is now working fine :)

The latest version of git has the option --show-index-version for update-index. I verified that it was at 3 before and then was successfully changed to 2. Not sure what happened when I tried setting it to 2 with my older version of git (it was the system git provided by macos,git version 2.39.3 (Apple Git-145) in this case).

giodamelio commented 3 months ago

For future reference, I don't believe that downgrading your index version is supported. I ended up deleting my index (while the repo was fully checked in and backed up) and running git reset.

Digging into it a little deeper, the issue is because GitPython only supports index version 1 and 2 (relevant code), and since the project is in maintenance mode it seems like there is a decent change that this won't be fixed in near future (though the GitPython maintainer is open to merging feature contributions).

Hopefully the authors successor project GitOxide will be stable and have a Python binding at some point soon.

aantn commented 2 months ago

Having the same issue.

paul-gauthier commented 2 months ago

Did you try updating the index as described earlier in this issue?

aantn commented 2 months ago

Yes, I'm not sure what the issue is:

$ ~/Projects/robusta → git update-index --show-index-version
3

$ ~/Projects/robusta → aider
Traceback (most recent call last):
  File "/opt/homebrew/bin/aider", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/aider/main.py", line 404, in main
    coder.show_announcements()
  File "/opt/homebrew/lib/python3.11/site-packages/aider/coders/base_coder.py", line 356, in show_announcements
    for line in self.get_announcements():
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/aider/coders/base_coder.py", line 159, in get_announcements
    num_files = len(self.repo.get_tracked_files())
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/aider/repo.py", line 200, in get_tracked_files
    staged_files = [path for path, _ in index.entries.keys()]
                                        ^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/gitdb/util.py", line 253, in __getattr__
    self._set_cache_(attr)
  File "/opt/homebrew/lib/python3.11/site-packages/git/index/base.py", line 168, in _set_cache_
    self._deserialize(stream)
  File "/opt/homebrew/lib/python3.11/site-packages/git/index/base.py", line 197, in _deserialize
    self.version, self.entries, self._extension_data, _conten_sha = read_cache(stream)
                                                                    ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/git/index/fun.py", line 252, in read_cache
    version, num_entries = read_header(stream)
                           ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/git/index/fun.py", line 210, in read_header
    assert version in (1, 2)
           ^^^^^^^^^^^^^^^^^
AssertionError

However, I can workaround this with aider --no-git - the git integration is not particularly important to me.

aantn commented 2 months ago

I should clarify - I know what the issue is, I just haven't looked into how to fix it!

$ git update-index --index-version=2
$ git update-index --show-index-version
3
grass29 commented 1 month ago

No skip worktree works for me, but this isn't a solution, as I have to keep certain files silenced, so they do not keep popping up in Source Control changes.

Is there a better workaround?