completion: add hack to enable file mode in bash < 4

This way we don't need all the compat stuff, different filters, and so on. Also, now we complete exactly the same in bash 3 and bash 4. This is the way bash-completion did it for quite some time, when bash 3 was supported. For more information about the hack: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=272660#64 Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed Apr 27, 2013 at 15:10 UTC 3ffa4df4b2a26768938fc6bf1ed0640885b2bdf1
1 file changed +7 -36
contrib/completion/git-completion.bash
+7 -36
@@ -254,33 +254,21 @@ __gitcomp_file ()
254 # completion will be used.
255 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
256
257 - # Tell Bash that compspec generates filenames.
258 - compopt -o filenames 2>/dev/null
257 + # use a hack to enable file mode in bash < 4
258 + compopt -o filenames 2>/dev/null ||
259 + compgen -f /non-existing-dir/ > /dev/null
260 }
261
261 -__git_index_file_list_filter_compat ()
262 -{
263 - local path
264 -
265 - while read -r path; do
266 - case "$path" in
267 - ?*/*) echo "${path%%/*}/" ;;
268 - *) echo "$path" ;;
269 - esac
270 - done
271 -}
272 -
273 -__git_index_file_list_filter_bash ()
262 +# Process path list returned by "ls-files" and "diff-index --name-only"
263 +# commands, in order to list only file names relative to a specified
264 +# directory, and append a slash to directory names.
265 +__git_index_file_list_filter ()
266 {
267 local path
268
269 while read -r path; do
270 case "$path" in
271 ?*/*)
280 - # XXX if we append a slash to directory names when using
281 - # `compopt -o filenames`, Bash will append another slash.
282 - # This is pretty stupid, and this the reason why we have to
283 - # define a compatible version for this function.
272 echo "${path%%/*}" ;;
273 *)
274 echo "$path" ;;
@@ -288,15 +276,6 @@ __git_index_file_list_filter_bash ()
276 done
277 }
278
291 -# Process path list returned by "ls-files" and "diff-index --name-only"
292 -# commands, in order to list only file names relative to a specified
293 -# directory, and append a slash to directory names.
294 -__git_index_file_list_filter ()
295 -{
296 - # Default to Bash >= 4.x
297 - __git_index_file_list_filter_bash
298 -}
299 -
279 # Execute 'git ls-files', unless the --committable option is specified, in
280 # which case it runs 'git diff-index' to find out the files that can be
281 # committed. It return paths relative to the directory specified in the first
@@ -2651,14 +2630,6 @@ if [[ -n ${ZSH_VERSION-} ]]; then
2630
2631 compdef _git git gitk
2632 return
2654 -elif [[ -n ${BASH_VERSION-} ]]; then
2655 - if ((${BASH_VERSINFO[0]} < 4)); then
2656 - # compopt is not supported
2657 - __git_index_file_list_filter ()
2658 - {
2659 - __git_index_file_list_filter_compat
2660 - }
2661 - fi
2633 fi
2634
2635 __git_func_wrap ()