@@ -638,25 +638,33 @@ __git_ls_files_helper ()
638638}
639639
640640
641- # __git_index_files accepts 1 or 2 arguments:
641+ # __git_index_files accepts 1 to 4 arguments:
642642# 1: Options to pass to ls-files (required).
643643# 2: A directory path (optional).
644644# If provided, only files within the specified directory are listed.
645645# Sub directories are never recursed. Path must have a trailing
646646# slash.
647647# 3: List only paths matching this path component (optional).
648+ # 4: Hide paths whose first component starts with a dot if this is
649+ # "hide-dotfiles" and the third argument is empty (optional).
648650__git_index_files ()
649651{
650- local root=" $2 " match=" $3 "
652+ local root=" $2 " match=" $3 " hide_dotfiles=" ${4-} "
653+ local hide_dotfiles_awk=0
654+ if [ " $hide_dotfiles " = " hide-dotfiles" ] && [ -z " $match " ]; then
655+ hide_dotfiles_awk=1
656+ fi
651657
652658 __git_ls_files_helper " $root " " $1 " " ${match:- ?} " |
653- awk -F / -v pfx=" ${2// \\ / \\\\ } " ' {
659+ awk -F / -v pfx=" ${2// \\ / \\\\ } " -v hide_dotfiles= " $hide_dotfiles_awk " ' {
654660 paths[$1] = 1
655661 }
656662 END {
657663 for (p in paths) {
658664 if (substr(p, 1, 1) != "\"") {
659665 # No special characters, easy!
666+ if (hide_dotfiles == 1 && substr(p, 1, 1) == ".")
667+ continue
660668 print pfx p
661669 continue
662670 }
@@ -675,8 +683,10 @@ __git_index_files ()
675683 # We have seen the same directory unquoted,
676684 # skip it.
677685 continue
678- else
679- print pfx p
686+
687+ if (hide_dotfiles == 1 && substr(p, 1, 1) == ".")
688+ continue
689+ print pfx p
680690 }
681691 }
682692 function dequote(p, bs_idx, out, esc, esc_idx, dec) {
@@ -721,13 +731,15 @@ __git_index_files ()
721731 }'
722732}
723733
724- # __git_complete_index_file requires 1 argument :
734+ # __git_complete_index_file accepts 1 or 2 arguments :
725735# 1: the options to pass to ls-file
736+ # 2: Hide paths whose first component starts with a dot if this is
737+ # "hide-dotfiles" and the current word is empty (optional).
726738#
727739# The exception is --committable, which finds the files appropriate commit.
728740__git_complete_index_file ()
729741{
730- local dequoted_word pfx=" " cur_
742+ local dequoted_word pfx=" " cur_ hide_dotfiles= " ${2-} "
731743
732744 __git_dequote " $cur "
733745
@@ -740,7 +752,7 @@ __git_complete_index_file ()
740752 cur_=" $dequoted_word "
741753 esac
742754
743- __gitcomp_file_direct " $( __git_index_files " $1 " " $pfx " " $cur_ " ) "
755+ __gitcomp_file_direct " $( __git_index_files " $1 " " $pfx " " $cur_ " " $hide_dotfiles " ) "
744756}
745757
746758# Lists branches from the local repository.
@@ -2164,7 +2176,7 @@ _git_ls_files ()
21642176
21652177 # XXX ignore options like --modified and always suggest all cached
21662178 # files.
2167- __git_complete_index_file " --cached"
2179+ __git_complete_index_file " --cached" hide-dotfiles
21682180}
21692181
21702182_git_ls_remote ()
@@ -2397,9 +2409,9 @@ _git_mv ()
23972409 if [ $( __git_count_arguments " mv" ) -gt 0 ]; then
23982410 # We need to show both cached and untracked files (including
23992411 # empty directories) since this may not be the last argument.
2400- __git_complete_index_file " --cached --others --directory"
2412+ __git_complete_index_file " --cached --others --directory" hide-dotfiles
24012413 else
2402- __git_complete_index_file " --cached"
2414+ __git_complete_index_file " --cached" hide-dotfiles
24032415 fi
24042416}
24052417
@@ -3219,7 +3231,7 @@ _git_rm ()
32193231 ;;
32203232 esac
32213233
3222- __git_complete_index_file " --cached"
3234+ __git_complete_index_file " --cached" hide-dotfiles
32233235}
32243236
32253237_git_shortlog ()
0 commit comments