I would really need a big help on this since I am convinced I did everything OK. I have my exec_command method which was working for all different bash commands until now. I never had issue with it until now.
def exec_cmd(cmd, fail=True):
"""
Execute shell command
:param cmd: list containing command and its parameters
"""
try:
print cmd
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
return output
..............
I want for Git repo, to execute specific command which should create a new branch based on a specific commit from the current branch. On some previous question I got a really amazing Git command to execute that only in one line (based on the commit message) Manually on Linux server this command execution works:
git checkout -b newBranch ":/\[AccuRev transaction: 971867\]"
Updating files: 100% (32046/32046), done.
Switched to a new branch 'newBranch'
So now I want to execute it from python:
os.chdir('/home/user/git_repo')
exec_cmd(['git', 'checkout', '-b', 'newBranch', '\":/\[AccuRev transaction: 971867\]\"'])
but it fails although executed command in the log ERROR message looks EXACTLY the same compared to the manual command (but maybe some slashes or white spaces are generating the issue).
exec_cmd:
['git', 'checkout', '-b', 'newBranch', '":/\\[AccuRev transaction: 971867\\]"']
Exception when executing cmd!!!!
ERROR: command "git checkout -b newBranch ":/\[AccuRev transaction: 971867\]"" failed with return code 128
Command output:
fatal: '":/\[AccuRev transaction: 971867\]"' is not a commit and a branch 'newBranch' cannot be created from it