From 8e06300495b947c39254e2005ff1fb887b5d5a18 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 11 May 2023 16:56:28 -0700 Subject: [PATCH] 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 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 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 [...] -- [...]'' 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. --- aider/coder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aider/coder.py b/aider/coder.py index 9e0e08493..352a9f240 100755 --- a/aider/coder.py +++ b/aider/coder.py @@ -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)