2014-11-04 40 views
9

我有一些奇怪的行爲,關於我的設置,我似乎無法縮小範圍。Tab完成只凍結Git命令

我在我的shell中使用tab完成沒有任何問題(我的shell是zsh)。我遇到的問題是在發出git命令後關於標籤填寫。

例1(正常工作):

我提出一個新的目錄中,更改到它和git init。我然後touch hello.rb。如果我做git add <tab>它會將其更改爲git add hello.rb

例2(不工作):

我在Rails應用程序真的不是很大,如果我嘗試的意圖,這將拉動運行git add G<tab>Gemfile,它只是掛起和掛起,直到我ctrl-c殺了它,輸出:

Killed by signal in __git_complete_index_file after 159s 

在zsh中我使用:

# completion 
autoload -U compinit 
compinit 

有沒有其他人有這個問題?我可以解決這個問題,但是我必須做一些錯誤的事情,而且我不確定在哪裏尋找。

版本的事情:

git version 2.1.2 
zsh 5.0.7 
iTerm2 Build 2.0.0.20141103 

更新:

的Git v 2.2.0已經修復了這個問題,所以如果你遇到這個問題,只是升級。

+1

我確認這個問題 – 907th 2014-11-13 07:56:37

回答

7

我假設你正在使用RVM或類似的工具。

當前git(2.1.3)和舊版本隨附的git-completion.bash存在一個錯誤,當在使用RVM的目錄中列出文件完成時導致無限循環。

這個無限循環的原因是由RVM和其他一些工具改變了chpwd_functions

我發現a patch爲git-comletion.bash,僅影響用於列出文件的__git_ls_files_helper方法。該補丁忽略chpwd_functions,因此,這些無限循環被省略。

簡而言之:將__git_ls_files_helper功能需要從改變:

__git_ls_files_helper() 
{ 
    (
    test -n "${CDPATH+set}" && unset CDPATH 
    cd "$1" 
    if [ "$2" == "--committable" ]; then 
     git diff-index --name-only --relative HEAD 
    else 
     # NOTE: $2 is not quoted in order to support multiple options 
     git ls-files --exclude-standard $2 
    fi 
    ) 2>/dev/null 
} 

到:

__git_ls_files_helper() 
{ 
    (
    test -n "${CDPATH+set}" && unset CDPATH 
    ((${+functions[chpwd]})) && unfunction chpwd 
    ((${#chpwd_functions})) && chpwd_functions=() 
    setopt chaselinks 
    builtin cd "$1" 2>/dev/null 
    if [ "$2" == "--committable" ]; then 
     git diff-index --name-only --relative HEAD 
    else 
     # NOTE: $2 is not quoted in order to support multiple options 
     git ls-files --exclude-standard $2 
    fi 
) 2>/dev/null 
} 

進一步的信息可以在RVM issue discussion on Github找到。 你的git-completion.bash的位置取決於你如何安裝git。當使用自制的位置是一樣的東西

/usr/local/Cellar/git/<git version>/etc/bash_completion.d/ 

在其他系統上,或者使用其他的包管理器時,它通常應該像

/opt/local/etc/bash_completion.d 

有關混帳completion.bash更多信息,請參閱git-scm.com書中的第2.7章Git提示和技巧。

更新:

的Git v 2.2.0已經修復了這個問題,所以如果你遇到這個問題,只是升級。

+0

謝謝Tobias!我將等待git在提交中合併,但這正是我的問題。 – Anthony 2014-11-16 15:15:49

+1

AFAIK這可能還沒有固定在Git v 2.2.0上(我試過這個版本)。我也更新到2.3.0,並且在完成製表符完成之前(在只有23個文件的文件夾上),'zsh'進程在100%CPU使用率下掛起時間> 15秒。 – isaacbernat 2015-02-11 10:26:29

+1

我正在使用'zsh 4.3.11'。切換到'zsh 5.0.7'解決了我的問題。 – isaacbernat 2015-02-11 11:16:49