Skip to content

Commit 1d66ec5

Browse files
szedergitster
authored andcommitted
bash: complete 'git diff ...branc<TAB>'
While doing a final sanity check before merging a topic Bsomething, it is a good idea to review what damage Bsomething branch would make, by running: $ git diff ...Bsomething Unfortunately, our completion script for 'git diff' doesn't offer anything after '...'. This is because 'git diff's completion function invokes __git_complete_file() for non-option arguments to complete the '<tree>:<path>' extended SHA-1 notation, but this helper function doesn't support refs after '...' or '..'. Completion of refs after '...' or '..' is supported by the __git_complete_revlist() helper function, but that doesn't support '<tree>:<path>'. To support both '...<ref>' and '<tree>:<path>' notations for 'git diff', this patch, instead of adding yet another helper function, joins __git_complete_file() and __git_complete_revlist() into the new common function __git_complete_revlist_file(). The old helper functions __git_complete_file() and __git_complete_revlist() are changed to be a direct wrapper around the new __git_complete_revlist_file(), because they might be used in user-supplied completion scripts and we don't want to break them. This change will cause some wrong suggestions for other commands which use __git_complete_file() ('git diff' and friends) or __git_complete_revlist() ('git log' and friends), e.g. 'git diff ...master:Doc<TAB>' and 'git log master:Doc<TAB>' will complete the path to 'Documentation/', although neither commands make any sense. However, both of these were actively wrong to begin with as soon as the user entered the ':', so there is no real harm done. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 80152b0 commit 1d66ec5

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

contrib/completion/git-completion.bash

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -662,11 +662,14 @@ __git_compute_merge_strategies ()
662662
: ${__git_merge_strategies:=$(__git_list_merge_strategies)}
663663
}
664664

665-
__git_complete_file ()
665+
__git_complete_revlist_file ()
666666
{
667667
local pfx ls ref cur
668668
_get_comp_words_by_ref -n =: cur
669669
case "$cur" in
670+
*..?*:*)
671+
return
672+
;;
670673
?*:*)
671674
ref="${cur%%:*}"
672675
cur="${cur#*:}"
@@ -705,17 +708,6 @@ __git_complete_file ()
705708
s/^.* //')" \
706709
-- "$cur"))
707710
;;
708-
*)
709-
__gitcomp "$(__git_refs)"
710-
;;
711-
esac
712-
}
713-
714-
__git_complete_revlist ()
715-
{
716-
local pfx cur
717-
_get_comp_words_by_ref -n =: cur
718-
case "$cur" in
719711
*...*)
720712
pfx="${cur%...*}..."
721713
cur="${cur#*...}"
@@ -732,6 +724,17 @@ __git_complete_revlist ()
732724
esac
733725
}
734726

727+
728+
__git_complete_file ()
729+
{
730+
__git_complete_revlist_file
731+
}
732+
733+
__git_complete_revlist ()
734+
{
735+
__git_complete_revlist_file
736+
}
737+
735738
__git_complete_remote_or_refspec ()
736739
{
737740
local cur words cword
@@ -1354,7 +1357,7 @@ _git_diff ()
13541357
return
13551358
;;
13561359
esac
1357-
__git_complete_file
1360+
__git_complete_revlist_file
13581361
}
13591362

13601363
__git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff

0 commit comments

Comments
 (0)