'Command executed via pexpect not taking effect
I am trying to cherry-pick gerrit reviews using a python script. I already have the string required to cherry-pick a review. I have used pexpect to automate the password input step.
Here is an example. For each review I have to execute the following 2 commands:
- git fetch "ssh://[email protected]:34343/project" refs/changes/45/255645/38
- git cherry-pick FETCH_HEAD
Only the first command asks for a password. Here is the code i have written:
child = pexpect.spawn('git fetch "ssh://[email protected]:34343/project" refs/changes/45/255645/38')
child.logfile_read = sys.stdout
child.expect(r'Enter passphrase for key(.*?):', timeout=10)
child.sendline('mypwd')
child.expect([pexpect.TIMEOUT, 'host$', pexpect.EOF])
child.sendline('git cherry-pick FETCH_HEAD')
child.expect([pexpect.TIMEOUT, 'host$', pexpect.EOF])
When i run the script i dont see any error. However the second command (git cherry-pick FETCH_HEAD) doesnt seem to be executed. I say this because when i run these commands manually the second command throws a git merge conflict. When i run the script i dont see cherry-pick in progress (git status shows all clean). I tried some variants but cannot get it to work. Please help.
Thanks in advance
Solution 1:[1]
In order to add logs without modifying your script, use GIT_TRACE2 environment variables for tracing events.
export GIT_TRACE2=1
export GIT_TRACE2_EVENT=1
(or set, if you are on Windows)
Make also sure to launch your script with the same account you used to do manual testing.
If the second command does not seem to be executed, check if, as in this thread, the prompt is the issue:
It seems the problem was with the prompt I expected back.
If I change theexpectto "child.expect('$ .*', timeout=15)", it works.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
