Skip to content

Commit 3ffa4df

Browse files
felipecgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fda54ef commit 3ffa4df

File tree

1 file changed

+7
-36
lines changed

1 file changed

+7
-36
lines changed

contrib/completion/git-completion.bash

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -254,49 +254,28 @@ __gitcomp_file ()
254254
# completion will be used.
255255
__gitcompadd "$1" "${2-}" "${3-$cur}" ""
256256

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
259260
}
260261

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 ()
274266
{
275267
local path
276268

277269
while read -r path; do
278270
case "$path" in
279271
?*/*)
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.
284272
echo "${path%%/*}" ;;
285273
*)
286274
echo "$path" ;;
287275
esac
288276
done
289277
}
290278

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-
300279
# Execute 'git ls-files', unless the --committable option is specified, in
301280
# which case it runs 'git diff-index' to find out the files that can be
302281
# committed. It return paths relative to the directory specified in the first
@@ -2651,14 +2630,6 @@ if [[ -n ${ZSH_VERSION-} ]]; then
26512630

26522631
compdef _git git gitk
26532632
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
26622633
fi
26632634

26642635
__git_func_wrap ()

0 commit comments

Comments
 (0)