I am getting the following error:
\n---------------------------------------------------------------------------\nGitCommandError Traceback (most recent call last)\n<ipython-input-82-f4329c19384f> in <module>\n 3 \n 4 for item in toggles:\n----> 5 files_result = Repo.execute([\"git\", \"grep\", \"--files-with-matches\", \"\\\"config.isEnabled([[:space:]*]'\" + item + \"'[[:space:]*])\\\"\"])\n 6 files = files_result.splitlines()\n 7 \n\n/opt/anaconda3/lib/python3.8/site-packages/git/cmd.py in execute(self, command, istream, with_extended_output, with_exceptions, as_process, output_stream, stdout_as_string, kill_after_timeout, with_stdout, universal_newlines, shell, env, max_chunk_size, **subprocess_kwargs)\n 820 \n 821 if with_exceptions and status != 0:\n--> 822 raise GitCommandError(command, status, stderr_value, stdout_value)\n 823 \n 824 if isinstance(stdout_value, bytes) and stdout_as_string: # could also be output_stream\n\nGitCommandError: Cmd('git') failed due to: exit code(1)\n cmdline: git grep --files-with-matches \"config.isEnabled([[:space:]*]'async-payments'[[:space:]*])\"\n\n
However, when I run git grep --files-with-matches \"config.isEnabled([[:space:]*]'async-payments'[[:space:]*])\"
in the command line, it works.
I appreciate any help.
","upvoteCount":1,"answerCount":4,"acceptedAnswer":{"@type":"Answer","text":"The issue is resolved by removing \\\"
from the \"\\\"config.isEnabled([[:space:]*]'\" + item + \"'[[:space:]*])\\\"\"
.
Another issue comes up now. If the result of executing grep
function is empty, I am getting the same error GitCommandError: Cmd('git') failed due to: exit code(1)
. When there is any result, it works fine.
Any ideas to solve this?
","upvoteCount":1,"url":"https://github.com/gitpython-developers/GitPython/discussions/1164#discussioncomment-408822"}}}-
Hi, I am trying to execute a grep command with regex using the execute() function. A part of my code is:
I am getting the following error:
However, when I run I appreciate any help. |
Beta Was this translation helpful? Give feedback.
-
It’s unlikely git is executed in the correct directory, which is why one would rather instantiate a Docs for how to invoke git, and here for the troubleshooting. Please feel free to keep posting into the closed issue for follow ups. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the response.
|
Beta Was this translation helpful? Give feedback.
-
The issue is resolved by removing Another issue comes up now. If the result of executing Any ideas to solve this? |
Beta Was this translation helpful? Give feedback.
-
By the looks of it, there is no way to ignore a non-zero exit code nor does git grep allow to ignore empty results. As you are effectively executing the git program, maybe it’s easiest to call git yourself. |
Beta Was this translation helpful? Give feedback.
The issue is resolved by removing
\"
from the"\"config.isEnabled([[:space:]*]'" + item + "'[[:space:]*])\""
.Another issue comes up now. If the result of executing
grep
function is empty, I am getting the same errorGitCommandError: Cmd('git') failed due to: exit code(1)
. When there is any result, it works fine.Any ideas to solve this?