Tab completion freezes for Git commands only Tab completion freezes for Git commands only shell shell

Tab completion freezes for Git commands only


I'm assuming you are using RVM or some tool like that.

There is a bug in the git-completion.bash shipped with the current git (2.1.3) and older versions, causing an endless loop when listing file completions in directories where RVM is used.

The reason for this endless loop is a change of chpwd_functions, made by RVM and some other tools.

I've found a patch for the git-comletion.bash affecting only the __git_ls_files_helper method which is used for listing files. The patch ignores the chpwd_functions and hence, these endless loops are omitted.

In short: The __git_ls_files_helper function needs to be changed from:

__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}

to:

__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}

Further information can be found in the RVM issue discussion on Github. The location of your git-completion.bash depends on how you have installed git. When using Homebrew, the location is something like

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

on other systems, or when using other package managers, it usually should be something like

/opt/local/etc/bash_completion.d

For further information about the git-completion.bash, take a look at the Git Tips and Tricks, chapter 2.7 in the git-scm.com book.

Update:

Git v 2.2.0 has fixed this issue so just upgrade if you're running into this issue.