输入 git stash show stash@{1} 时自动补全问题

8

首先我输入git stash show

然后输入stab,它会显示git stash show stash@{,到目前为止一切正常。

但是当我输入1tab时,它变成了git stash show stashstash@{1},很明显是错误的。

我认为在.git-completion.bash中以下代码可能有误,但我几乎无法阅读。

_git_stash ()
{
    local save_opts='--keep-index --no-keep-index --quiet --patch'
    local subcommands='save list show apply clear drop pop create branch'
    local subcommand="$(__git_find_on_cmdline "$subcommands")"
    if [ -z "$subcommand" ]; then
        case "$cur" in
        --*)
            __gitcomp "$save_opts"
            ;;
        *)
            if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
                __gitcomp "$subcommands"
            else
                COMPREPLY=()
            fi
            ;;
        esac
    else
        case "$subcommand,$cur" in
        save,--*)
            __gitcomp "$save_opts"
            ;;
        apply,--*|pop,--*)
            __gitcomp "--index --quiet"
            ;;
        show,--*|drop,--*|branch,--*)
            COMPREPLY=()
            ;;
        show,*|apply,*|drop,*|pop,*|branch,*)
            __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \                                                               
                    | sed -n -e 's/:.*//p')"
            ;;
        *)
            COMPREPLY=()
            ;;
        esac
    fi
}

有谁知道如何修复它?

Bash版本:GNU bash,版本4.2.37(2)-release(i386-apple-darwin12.0.0)。

Git版本:1.8.0.3

整个源代码:https://gist.github.com/pktangyue/5477924


我正在使用bash 4.1.10(1)。我在我的/etc/bash-completion.d/git-completion.sh中定义了相同的完成函数,并且完成在我的端上正常工作。你能否提供有关你的bash版本的详细信息?如果你能够发布一个链接(可能是到gist的链接)到你完整的git-completion.sh,这可能有助于比较。 - Tuxdude
@Tuxdude 添加了更多信息。 - pktangyue
我了解你至少有10个存储库? 我正在尝试复制你的情况。 我在两个存储库上没有遇到这个问题(git 1.8.2.3,bash 4.2.45,Arch Linux x86_64)。 - kampu
1
修改:实际上,即使有11个存储库,我也无法重现此问题。 我建议您考虑升级bash版本,因为在git的“stash”行为1.8.0.3和1.8.2.3之间似乎没有任何重大变化。 - kampu
2个回答

2

当我手动下载过时的git完成脚本时,我也遇到了同样的问题。通过使用Homebrew获取最新版本,我成功地解决了这个问题。

brew install git bash-completion

请删除您在".profile"中可能存在的旧链接。改用brew脚本。

if [ -f $(brew --prefix)/etc/bash_completion ]; then
    . $(brew --prefix)/etc/bash_completion
fi

现在,当我点击时,它能够正确完成(git stash show stash@{0}会给出 git stash show stash@{0})。

0

Bash-Completion应该作为一个独立于Bash本身的单独软件包。例如,我有来自Cygwin的bash版本4.1.10-4和bash-completion版本1.3-1,您所描述的完成工作正常。

请检查您安装的Bash-Completion版本。您也可以尝试直接从http://bash-completion.alioth.debian.org/安装最新版本,或者尝试仅用上游版本替换文件/etc/bash_completion.d/git


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接