Skip to content

Commit

Permalink
bash: offer only paths after '--'
Browse files Browse the repository at this point in the history
Many git commands use '--' to separate subcommands, options, and refs
from paths.  However, the programmable completion for several of these
commands does not respect the '--', and offer subcommands, options, or
refs after a '--', although only paths are permitted.  e.g. 'git bisect
-- <TAB>' offers subcommands, 'git log -- --<TAB>' offers options and
'git log -- git<TAB>' offers all gitgui tags.

The completion for the following commands share this wrong behaviour:
  am add bisect commit diff log reset shortlog submodule gitk.

To avoid this, we check the presence of a '--' on the command line first
and let the shell do filename completion, if one is found.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Acked-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
SZEDER Gábor authored and Junio C Hamano committed Jul 8, 2008
1 parent 1db4a75 commit d773c63
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,18 @@ __git_find_subcommand ()
done
}

__git_has_doubledash ()
{
local c=1
while [ $c -lt $COMP_CWORD ]; do
if [ "--" = "${COMP_WORDS[c]}" ]; then
return 0
fi
c=$((++c))
done
return 1
}

__git_whitespacelist="nowarn warn error error-all strip"

_git_am ()
Expand Down Expand Up @@ -497,6 +509,8 @@ _git_apply ()

_git_add ()
{
__git_has_doubledash && return

local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
Expand All @@ -511,6 +525,8 @@ _git_add ()

_git_bisect ()
{
__git_has_doubledash && return

local subcommands="start bad good reset visualize replay log"
local subcommand="$(__git_find_subcommand "$subcommands")"
if [ -z "$subcommand" ]; then
Expand Down Expand Up @@ -613,6 +629,8 @@ _git_cherry_pick ()

_git_commit ()
{
__git_has_doubledash && return

local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
Expand All @@ -632,6 +650,8 @@ _git_describe ()

_git_diff ()
{
__git_has_doubledash && return

local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
Expand Down Expand Up @@ -734,6 +754,8 @@ _git_ls_tree ()

_git_log ()
{
__git_has_doubledash && return

local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--pretty=*)
Expand Down Expand Up @@ -1085,6 +1107,8 @@ _git_remote ()

_git_reset ()
{
__git_has_doubledash && return

local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
Expand All @@ -1097,6 +1121,8 @@ _git_reset ()

_git_shortlog ()
{
__git_has_doubledash && return

local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
--*)
Expand Down Expand Up @@ -1143,6 +1169,8 @@ _git_stash ()

_git_submodule ()
{
__git_has_doubledash && return

local subcommands="add status init update"
if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
local cur="${COMP_WORDS[COMP_CWORD]}"
Expand Down Expand Up @@ -1349,6 +1377,8 @@ _git ()

_gitk ()
{
__git_has_doubledash && return

local cur="${COMP_WORDS[COMP_CWORD]}"
local g="$(git rev-parse --git-dir 2>/dev/null)"
local merge=""
Expand Down

0 comments on commit d773c63

Please sign in to comment.