[英]Redirecting stdout/stderr/stdin of 'git clone'
我想編寫一個程序來克隆遠程 git 存儲庫,然后做一些其他的事情。 問題是“git clone”要求輸入密碼。 當我打開到 stdin/out/err 到“git clone”的管道時,它不起作用,因為它在下面運行 git-remote-http,提示輸入 TTY 上的密碼。
我想從我的程序中傳遞密碼。 我正在使用 Python 和子進程中的 Popen。 下面的代碼不起作用。
Popen(['git', 'clone', 'https://my.git.repo/repo.git'], shell=False, stdin=PIPE, stdout=PIPE, stderr=PIPE)
我怎樣才能做到這一點?
如果您不想像評論者所說的那樣使用挑戰認證,我會使用pexpect來自動化這種交互
您可以git clone https://foo:bar@my.git.repo/repo.git
獲取數據,然后git remote set-url origin https://my.git.repo/repo.git
清除密碼。 但是,在克隆開始和URL更改之間存在競爭條件。
如果您對使用圖書館感到滿意,您可以嘗試使用Dulwich 。
from dulwich import porcelain
porcelain.clone("https://example.com/repo.git", username="youruser", password="yourpassword")
這似乎沒有存儲用戶名或密碼(我在.git
目錄中搜索了使用的密碼,但沒有找到任何東西)。
因為要找到一個沒有任何明顯問題的最新 Git 庫非常麻煩,我想列出我的來源以供將來參考:
clone
的Dulwich porcelain
文檔根本沒有提到身份驗證是可能的。clone
確實可以使用username:password@
語法進行身份驗證。username
和password
參數。 我已經在我對“dulwich - clone from remote repo authentication”問題的回答中記錄了這一點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.