Redirecting stdout / stderr / stdin from 'git clone'

I want to write a program that will clone a remote git repository and then do a bunch of other things. The problem is that 'git clone' asks for a password. This does not work when I open the channels for stdin / out / err to 'git clone', because it starts git -remote-http, under which the password for TTY is requested.

I would like to pass the password from my program. I am using Python and Popen from a subprocess. The code below is not wotk.

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

How can i achieve this?

+6
source share
2 answers

If you don't want to use on-demand authentication, as the commentator said, I would use pexpect to automate this interaction

+2
source

You can git clone https://foo: bar@my.git.repo /repo.git to get the data and git remote set-url origin https://my.git.repo/repo.git after that to clear the password. But you have a race condition between the start of cloning and changing the URL.

+2
source

Source: https://habr.com/ru/post/902744/


All Articles