Skip to content
\n

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
\n

However, when I run git grep --files-with-matches \"config.isEnabled([[:space:]*]'async-payments'[[:space:]*])\" in the command line, it works.

\n

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:]*])\\\"\".

\n

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.

\n

Any ideas to solve this?

","upvoteCount":1,"url":"https://github.com/gitpython-developers/GitPython/discussions/1164#discussioncomment-408822"}}}

GitCommandError: Cmd('git') failed due to: exit code(1) when execute 'grep' with regex #1164

Answered by rmahdav
rmahdav asked this question in Q&A
Discussion options

You must be logged in to vote

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?

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Byron
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1074 on February 26, 2021 11:18.