2015-03-02 170 views
0

我正在使用GitPython初始化一個新的本地資源庫,創建初始提交併推送到規範化的資源庫。不幸的是,最後一步是失敗,我很難理解爲什麼。我確定我只是使用GIT_SSH_COMMAND變量錯誤,但我不知道如何。沒有太多的例子可以繼續。與GitPython一起使用GIT_SSH_COMMAND

我讀過this SO question,並挖掘到相關的issuecommit,但我顯然沒有把它放在一起正確。

幫助?

的Git V2.3的 「證明」 +

$ git --version                               
git version 2.3.1 

腳本段

# Please take my word that I've init'd the repo and that any variables 
# have been defined and initialized. 
git_ssh_identity_file = os.path.expanduser('~/.ssh/id_rsa') 
git_ssh_cmd = 'ssh -i %s' % git_ssh_identity_file 
with git_project.git.custom_environment(GIT_SSH_COMMAND=git_ssh_cmd): 
    git_project.remotes.origin.push(git_project.heads.master) 

產生的錯誤

Traceback (most recent call last): 
    File "./ct-new-project.py", line 204, in <module> 
    git_project.remotes.origin.push(git_project.heads.master) 
    File "/Library/Python/2.7/site-packages/git/remote.py", line 667, in push 
    return self._get_push_info(proc, progress or RemoteProgress()) 
    File "/Library/Python/2.7/site-packages/git/remote.py", line 588, in _get_push_info 
    handle_process_output(proc, stdout_handler, progress_handler, finalize_process) 
    File "/Library/Python/2.7/site-packages/git/cmd.py", line 202, in handle_process_output 
    return finalizer(process) 
    File "/Library/Python/2.7/site-packages/git/util.py", line 158, in finalize_process 
    proc.wait() 
    File "/Library/Python/2.7/site-packages/git/cmd.py", line 300, in wait 
    raise GitCommandError(self.args, status, self.proc.stderr.read()) 
git.exc.GitCommandError: 'git push --porcelain origin master' returned with exit code 128 
+0

痛苦明顯的問題,所以我相信你已經檢查過它......但你永遠不知道。這是否從命令行工作?即'GIT_SSH_COMMAND ='ssh -i〜/ .ssh/id_rsa'git push - 瓷器原點大師'?以防萬一你的回購有問題。或者'GIT_SSH_COMMAND'特定於GitPython? – kdopen 2015-03-02 16:35:55

+0

我應該說'你的回購狀態有問題'(因爲在推送失敗的原因與SSH覆蓋無關)。是的,我剛剛檢查過,'GIT_SSH_COMMAND'是一個'git'變量,而不是'GitPython',所以你應該能夠從命令行檢查。 – kdopen 2015-03-02 17:11:53

+0

你知道嗎?是和不是。我試過了,但它肯定是在我以前有過別的不正確的一次迭代中。與此同時,我在'.git/config'中的出處與我試圖推動的代碼不同步 - 這是目前的實際問題 - 我試圖推動一個實際上並不存在的回購。 /懲罰headlap – 2015-03-02 17:48:26

回答

1

WHE n GitPython拋出這種類型的錯誤,總是值得檢查它試圖執行的實際命令是否從命令行運行。您的本地克隆中可能發生了一些變化,導致命令無法成功完成。

的你正在努力實現與GitPython什麼等效可以通過以下來完成:

$ GIT_SSH_COMMAND='ssh -i ~/.ssh/id_rsa' git push --porcelain origin master 

至少在Linux。在Windows上,您可能需要直接在單獨的命令中設置環境變量。

當我嘗試這樣做時,我發現有一個「本地」上游我可以推到我的硬盤驅動器上的某個地方,這樣我就可以把它扔掉並重新啓動 - 或者從第二個(原始的)克隆中獲得git push --force上游..因爲你只是知道你至少會搞砸一次。