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.
This commit is contained in:
Paul Gauthier 2023-05-11 16:56:28 -07:00
parent 173a91a8c2
commit 8e06300495

View file

@ -465,7 +465,7 @@ class Coder:
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)
these_diffs = repo.git.diff("HEAD", "--color", "--", relative_fname)
else:
these_diffs = repo.git.diff("HEAD", relative_fname)