Aider-AI / aider

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

If a file is being ignore in .aiderignore it shouldn't be put in context or else put in write-only mode. #479

Closed harleypig closed 8 months ago

harleypig commented 8 months ago

When asking questions or reporting issues, it is very helpful if you can include:

To change the desktop background color to dark-blue, I will update the vm-setup/gnome-settings.yml file. The specific setting to change is the primary-color under the Set desktop background options task.

Here is the diff for the change:

--- vm-setup/gnome-settings.yml
+++ vm-setup/gnome-settings.yml
@@ ... @@
    - name: Set desktop background options
      shell: "gsettings set org.gnome.desktop.background {{ item }}"
      with_items:
-        - primary-color '#27285C'
+        - primary-color '#00008B'
        - show-desktop-icons false
\```

This change sets the primary color to a dark blue (`#00008B`).

> Committing vm-setup/gnome-settings.yml before applying edits.  
> Update exception #1, retrying...  
> Cmd('git') failed due to: exit code(1)
  cmdline: git commit -m Added gnome settings configuration file. --no-verify -- /home/harleypig/projects/dotfiles/vm-setup/gnome-settings.yml
  stdout: 'On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean'  
> ^C again to exit  

The error message you've provided indicates that the `git commit` command failed because there were no

I pressed ^C again because it gets caught in a loop.

I'm getting this trace. It's the same in every loop.

Traceback (most recent call last):
  File "/home/harleypig/.local/lib/python3.10/site-packages/aider/coders/base_coder.py", line 902, in apply_updates
    edited = self.update_files()
  File "/home/harleypig/.local/lib/python3.10/site-packages/aider/coders/base_coder.py", line 896, in update_files
    edits = self.prepare_to_edit(edits)
  File "/home/harleypig/.local/lib/python3.10/site-packages/aider/coders/base_coder.py", line 889, in prepare_to_edit
    self.dirty_commit()
  File "/home/harleypig/.local/lib/python3.10/site-packages/aider/coders/base_coder.py", line 1000, in dirty_commit
    self.repo.commit(fnames=self.need_commit_before_edits)
  File "/home/harleypig/.local/lib/python3.10/site-packages/aider/repo.py", line 92, in commit
    self.repo.git.commit(cmd)
  File "/home/harleypig/.local/lib/python3.10/site-packages/git/cmd.py", line 736, in <lambda>
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
  File "/home/harleypig/.local/lib/python3.10/site-packages/git/cmd.py", line 1316, in _call_process
    return self.execute(call, **exec_kwargs)
  File "/home/harleypig/.local/lib/python3.10/site-packages/git/cmd.py", line 1111, in execute
    raise GitCommandError(redacted_command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
  cmdline: git commit -m Added gnome settings configuration file. --no-verify -- /home/harleypig/projects/dotfiles/vm-setup/gnome-settings.yml
  stdout: 'On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean'
Update exception #1, retrying...
Cmd('git') failed due to: exit code(1)
  cmdline: git commit -m Added gnome settings configuration file. --no-verify -- 
/home/harleypig/projects/dotfiles/vm-setup/gnome-settings.yml
  stdout: 'On branch master
Your branch is up to date with 'origin/master'.

I've closed all of my terminal windows, which made no difference. I even rebooted my virtual machine, but it still failed.

I tried moving the chat and input history files and tags cache directory out of the way. Nope.

I am confused ... this is not happening in any of the other repositories I'm using Aider with.

harleypig commented 8 months ago

Well ... I'm an idiot.

I was ignoring the vm-setup directory in .aiderignore.

So, I'm gonna change the title of this issue to something more appropriate.

When starting aider (in this case aider vm-setup/*.yml) and the files being loaded are ignored by .aiderignore should either not be loaded or put into write-only mode.

paul-gauthier commented 8 months ago

Thanks for trying aider and filing this issue.

I've made aider fully and vocally ignore files that match the aiderignore spec. The change is available in the main branch. You can get it by installing the latest version from github:

python -m pip install --upgrade git+https://github.com/paul-gauthier/aider.git

If you have a chance to try it, let me know if it works better for you.

harleypig commented 8 months ago

Doesn't seem to have made a difference, other than change was applied before it died.

$ cat .aiderignore
archive/*
bin/*
lib/*
shell_startup.d/*
tests/*
vm-setup/*
vm-setup/credentials.yml
$ aider vm-setup/sweetums.yml 
Aider v0.24.2-dev
Model: gpt-4-1106-preview using udiff edit format
Git repo: .git with 26 files
Repo-map: using 2048 tokens
Added vm-setup/sweetums.yml to the chat.
Use /help to see in-chat commands, run with --help to see cmd line args
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
vm-setup/sweetums.yml                                                                                                                                          
> Add a comment to sweetums.yml stating that we should be ignoring this file.

 --- vm-setup/sweetums.yml
 +++ vm-setup/sweetums.yml
 @@ ... @@
  ---
 +# This file should be ignored
  - hosts: localhost
    become: yes

Committing vm-setup/sweetums.yml before applying edits.
Cmd('git') failed due to: exit code(1)
  cmdline: git commit -m Added vm-setup/sweetums.yml. --no-verify -- /home/harleypig/projects/dotfiles/vm-setup/sweetums.yml
  stdout: 'On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   .aiderignore

no changes added to commit (use "git add" and/or "git commit -a")'

Traceback (most recent call last):
  File "/home/harleypig/.local/lib/python3.10/site-packages/aider/coders/base_coder.py", line 908, in apply_updates
    edited = self.update_files()
  File "/home/harleypig/.local/lib/python3.10/site-packages/aider/coders/base_coder.py", line 902, in update_files
    edits = self.prepare_to_edit(edits)
  File "/home/harleypig/.local/lib/python3.10/site-packages/aider/coders/base_coder.py", line 895, in prepare_to_edit
    self.dirty_commit()
  File "/home/harleypig/.local/lib/python3.10/site-packages/aider/coders/base_coder.py", line 1006, in dirty_commit
    self.repo.commit(fnames=self.need_commit_before_edits)
  File "/home/harleypig/.local/lib/python3.10/site-packages/aider/repo.py", line 94, in commit
    self.repo.git.commit(cmd)
  File "/home/harleypig/.local/lib/python3.10/site-packages/git/cmd.py", line 736, in <lambda>
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
  File "/home/harleypig/.local/lib/python3.10/site-packages/git/cmd.py", line 1316, in _call_process
    return self.execute(call, **exec_kwargs)
  File "/home/harleypig/.local/lib/python3.10/site-packages/git/cmd.py", line 1111, in execute
    raise GitCommandError(redacted_command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
  cmdline: git commit -m Added vm-setup/sweetums.yml. --no-verify -- /home/harleypig/projects/dotfiles/vm-setup/sweetums.yml
  stdout: 'On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   .aiderignore

no changes added to commit (use "git add" and/or "git commit -a")'
Update exception #1, retrying...
Cmd('git') failed due to: exit code(1)
  cmdline: git commit -m Added vm-setup/sweetums.yml. --no-verify -- /home/harleypig/projects/dotfiles/vm-setup/sweetums.yml
  stdout: 'On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   .aiderignore

no changes added to commit (use "git add" and/or "git commit -a")'
It seems like you're encountering an issue with a Git command outside of the scope of our current interaction. The error message indicates that there are
changes in the .aiderignore file that have not been staged for commit. To resolve this issue, you would typically stage the changes with git add .aiderignore
and then commit them with git commit -m "Your commit message".

However, since I am here to assist with code changes and not to execute Git commands, please let me know if there's anything else you'd like to do with the
sweetums.yml file or any other file that you have made read-write in this chat.

.aiderignore
Add these files to the chat? y
To address the Git error you encountered, you can add an entry to the .aiderignore file to ignore the vm-setup/sweetums.yml file. Here is the diff for the
change to .aiderignore:

 --- .aiderignore
 +++ .aiderignore
 @@ ... @@
  archive/*
  bin/*
  lib/*
  shell_startup.d/*
  tests/*
  vm-setup/*
 +vm-setup/sweetums.yml
  vm-setup/credentials.yml

After applying this change, the vm-setup/sweetums.yml file will be ignored as per your request. Remember to stage and commit this change in your local Git
repository.

Committing .aiderignore before applying edits.
Commit 6904a84 Removed '#' from the beginning of the 'vm-setup/*' line in .aiderignore.
Applied edit to .aiderignore
Commit 3372182 aider: Added vm-setup/sweetums.yml to .aiderignore.
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
.aiderignore vm-setup/sweetums.yml
>
harleypig commented 8 months ago

Oops ... no ... the change to sweetums.yml was not made, but it did add the specific file to .aiderignore, even though it was already being ignored by vm-setup/* ...

harleypig commented 8 months ago

If I use vm-setup/** in my .aiderignore the only difference is that it doesn't modify .aiderignore.

harleypig commented 8 months ago

If it makes any difference, vm-setup is not in my .gitignore file.

paul-gauthier commented 8 months ago

Ok, I think I understand what went wrong. I pushed a new version. The change is available in the main branch. If you have a chance to try it, let me know if it works better for you.

harleypig commented 8 months ago

Looks like that worked.

$ aider vm-setup/test-role.yml 
Aider v0.24.2-dev
Model: gpt-4-1106-preview using udiff edit format
Skipping /home/harleypig/projects/dotfiles/vm-setup/test-role.yml that matches aiderignore spec.
Git repo: .git with 26 files
Repo-map: using 2048 tokens
Use /help to see in-chat commands, run with --help to see cmd line args
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
>

Thanks.