I have a python script which executes bash
commands on the linux server. Name of the method is exec_cmd
and it worked perfectly, until now.
I need to execute git log
command on the linux server which returns one specific git commit.
git log --grep="\[AccuRev transaction: 14126178\]"
Output:
`commit a176c1e534735b7b8b6506730288a62c3f2754cb
Author: ....
Date: ...
[AccuRev transaction: 14126178]`
You will notice that git log
command must have backslash when executing it on the server.
In python I tried with my exec_cmd
function which works for any other git command but with this command that includes "
and \
it doesn't work. Output is EMPTY.
exec_cmd(['git', 'log', r'--grep="\[AccuRev transaction: 14126178\]"'], fail=True)
As you see I tried with stringprefix
string literal r
but without luck.
In log I can see it executed like this this:
['git', 'log', '--grep="\\[AccuRev transaction: 14126178\\]"']
I had an issue with similar command for git checkout
that I resolved in python and the difference is that it didn't included quotes in it.
git checkout -b mynewbranch1 ':/\[AccuRev transaction: 21114530\]'
And in python code, the solution that worked was this:
exec_cmd(['git', 'checkout', '-b', "branch1", r':/\[AccuRev transaction: ' +str(transaction_id)+'\]'], fail=True)
What should be corrected in the git log
python code?
Thanks a lot!