Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting stdout/stderr/stdin of 'git clone'

Tags:

git

python

I want to write a program which will clone remote git repository and then do bunch of other stuff. The problem is that 'git clone' asks for password. It does not work when I open pipes to stdin/out/err to 'git clone' because it runs git-remote-http underneath which prompts for password on TTY.

I would like to pass the password from my program. I am using Python and Popen from subprocess. Code below does not wotk.

Popen(['git', 'clone', 'https://my.git.repo/repo.git'], shell=False, stdin=PIPE, stdout=PIPE, stderr=PIPE)

How can I achieve this?

like image 602
Kylo Avatar asked Nov 30 '11 11:11

Kylo


2 Answers

If you do not want to use challenge authentication as the commenter said, I would use pexpect to automate this kind of interaction

like image 150
ziu Avatar answered Nov 02 '22 10:11

ziu


You can git clone https://foo:[email protected]/repo.git to get the data, and git remote set-url origin https://my.git.repo/repo.git afterwards to clear the password. But you have an race-condition between the start of the clone, and the URL-change.

like image 2
Rudi Avatar answered Nov 02 '22 12:11

Rudi