重定向' git clone'的stdout / stderr / stdin

时间:2011-11-30 11:29:53

标签: python git

我想编写一个程序,它将克隆远程git存储库,然后做一堆其他的东西。问题是'git clone'要求输入密码。当我打开stdin / out / err到'git clone'的管道时,它不起作用,因为它在下面运行git-remote-http,提示在TTY上输入密码。

我想从我的程序中传递密码。我在子进程中使用Python和Popen。下面的代码没有wotk。

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

我怎样才能做到这一点?

2 个答案:

答案 0 :(得分:2)

如果您不想像评论者所说的那样使用质询身份验证,我会使用pexpect自动进行此类互动

答案 1 :(得分:2)

您可以git clone https://foo:bar@my.git.repo/repo.git获取数据,然后git remote set-url origin https://my.git.repo/repo.git清除密码。但是,在克隆开始和URL更改之间存在竞争条件。