I am trying to use Gitpython in python on my virtual machine but struggle due to sudo and denied permissions etc. So instead I wanted to try a different approach. When I write sudo git pull it first asks me for the password, then for the git username, and then for the git password, what I want to do now i prefill those in some kind of os.system within python. This is what I have accomplished so far:
os.system("echo <password> | sudo -S git pull")
This solves the first problem with the sudo password. But how can I prefill answers for the questions the command line will return?
1 Answer 1
how can I prefill answers for the questions the command line will return?
By avoiding having to prefill anything.
Meaning, as root, you should be able to do a git pull without having to enter the username/password.
If you can do that as root, in a command line, you will then be able to make it work in a Python os.system("echo <password> | sudo -S git pull") call.
For that:
1/ First set the username in the remote URL itself
cd /path/to/repo
git remote -v
https://aserver/auser/arepo
git remote set-url origin https://username@aserver/auser/arepo
2/ Use a credential helper (done as root) in order for Git itself to look for the password (instead of you having to try and feed it to the command line).
Once that is working as root, repeat the same git pull in your Python program (running as root)