Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork966
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
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. |
BetaWas this translation helpful?Give feedback.
All reactions
The issue is resolved by removing\" from the"\"config.isEnabled([[:space:]*]'" + item + "'[[:space:]*])\"".
Another issue comes up now. If the result of executinggrep 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?
Replies: 4 comments 1 reply
-
It’s unlikely git is executed in the correct directory, which is why one would rather instantiate a Docs forhow to invoke git, and herefor the troubleshooting. Please feel free to keep posting into the closed issue for follow ups. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Thanks for the response. |
BetaWas this translation helpful?Give feedback.
All reactions
-
The issue is resolved by removing Another issue comes up now. If the result of executing Any ideas to solve this? |
BetaWas this translation helpful?Give feedback.
All reactions
-
By the looks of it, there isno 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. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Here's my "trick" to catch exit code 1 try:returnself.repo.git.grep("-l",pattern)exceptGitCommandErrorasexc:# git grep exits with status 1 when there are no matches; treat as an empty resultifexc.status==1:return []# Re-raise unexpected git errorsraise |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
This discussion was converted from issue#1074 on February 26, 2021 11:18.