@@ -252,106 +252,50 @@ __gitcomp_file ()
252
252
# since tilde expansion is not applied.
253
253
# This means that COMPREPLY will be empty and Bash default
254
254
# completion will be used.
255
- COMPREPLY=( $( compgen -P " ${2-} " -W " $1 " -- " $ {3-$cur }" ) )
255
+ __gitcompadd " $1 " " ${2-} " " $ {3-$cur }" " "
256
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 +o nospace 2> /dev/null ||
259
+ compgen -f /non-existing-dir/ > /dev/null
259
260
}
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 ()
274
- {
275
- local path
276
-
277
- while read -r path; do
278
- case " $path " in
279
- ?* /* )
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.
284
- echo " ${path%%/* } " ;;
285
- * )
286
- echo " $path " ;;
287
- esac
288
- done
289
- }
290
-
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
-
300
- # Execute git ls-files, returning paths relative to the directory
301
- # specified in the first argument, and using the options specified in
302
- # the second argument.
262
+ # Execute 'git ls-files', unless the --committable option is specified, in
263
+ # which case it runs 'git diff-index' to find out the files that can be
264
+ # committed. It return paths relative to the directory specified in the first
265
+ # argument, and using the options specified in the second argument.
303
266
__git_ls_files_helper ()
304
267
{
305
268
(
306
269
test -n " ${CDPATH+set} " && unset CDPATH
307
- # NOTE: $2 is not quoted in order to support multiple options
308
- cd " $1 " && git ls-files --exclude-standard $2
270
+ cd " $1 "
271
+ if [ " $2 " == " --committable" ]; then
272
+ git diff-index --name-only --relative HEAD
273
+ else
274
+ # NOTE: $2 is not quoted in order to support multiple options
275
+ git ls-files --exclude-standard $2
276
+ fi
309
277
) 2> /dev/null
310
278
}
311
279
312
280
313
- # Execute git diff-index, returning paths relative to the directory
314
- # specified in the first argument, and using the tree object id
315
- # specified in the second argument.
316
- __git_diff_index_helper ()
317
- {
318
- (
319
- test -n " ${CDPATH+set} " && unset CDPATH
320
- cd " $1 " && git diff-index --name-only --relative " $2 "
321
- ) 2> /dev/null
322
- }
323
-
324
281
# __git_index_files accepts 1 or 2 arguments:
325
282
# 1: Options to pass to ls-files (required).
326
- # Supported options are --cached, --modified, --deleted, --others,
327
- # and --directory.
328
283
# 2: A directory path (optional).
329
284
# If provided, only files within the specified directory are listed.
330
285
# Sub directories are never recursed. Path must have a trailing
331
286
# slash.
332
287
__git_index_files ()
333
288
{
334
- local dir=" $( __gitdir) " root=" ${2-.} "
289
+ local dir=" $( __gitdir) " root=" ${2-.} " file
335
290
336
291
if [ -d " $dir " ]; then
337
- __git_ls_files_helper " $root " " $1 " | __git_index_file_list_filter |
338
- sort | uniq
339
- fi
340
- }
341
-
342
- # __git_diff_index_files accepts 1 or 2 arguments:
343
- # 1) The id of a tree object.
344
- # 2) A directory path (optional).
345
- # If provided, only files within the specified directory are listed.
346
- # Sub directories are never recursed. Path must have a trailing
347
- # slash.
348
- __git_diff_index_files ()
349
- {
350
- local dir=" $( __gitdir) " root=" ${2-.} "
351
-
352
- if [ -d " $dir " ]; then
353
- __git_diff_index_helper " $root " " $1 " | __git_index_file_list_filter |
354
- sort | uniq
292
+ __git_ls_files_helper " $root " " $1 " |
293
+ while read -r file; do
294
+ case " $file " in
295
+ ?* /* ) echo " ${file%%/* } " ;;
296
+ * ) echo " $file " ;;
297
+ esac
298
+ done | sort | uniq
355
299
fi
356
300
}
357
301
@@ -552,44 +496,23 @@ __git_complete_revlist_file ()
552
496
}
553
497
554
498
555
- # __git_complete_index_file requires 1 argument: the options to pass to
556
- # ls-file
499
+ # __git_complete_index_file requires 1 argument:
500
+ # 1: the options to pass to ls-file
501
+ #
502
+ # The exception is --committable, which finds the files appropriate commit.
557
503
__git_complete_index_file ()
558
504
{
559
- local pfx cur_=" $cur "
505
+ local pfx= " " cur_=" $cur "
560
506
561
507
case " $cur_ " in
562
508
?* /* )
563
509
pfx=" ${cur_%/* } "
564
510
cur_=" ${cur_##*/ } "
565
511
pfx=" ${pfx} /"
566
-
567
- __gitcomp_file " $( __git_index_files " $1 " " $pfx " ) " " $pfx " " $cur_ "
568
- ;;
569
- * )
570
- __gitcomp_file " $( __git_index_files " $1 " ) " " " " $cur_ "
571
512
;;
572
513
esac
573
- }
574
514
575
- # __git_complete_diff_index_file requires 1 argument: the id of a tree
576
- # object
577
- __git_complete_diff_index_file ()
578
- {
579
- local pfx cur_=" $cur "
580
-
581
- case " $cur_ " in
582
- ?* /* )
583
- pfx=" ${cur_%/* } "
584
- cur_=" ${cur_##*/ } "
585
- pfx=" ${pfx} /"
586
-
587
- __gitcomp_file " $( __git_diff_index_files " $1 " " $pfx " ) " " $pfx " " $cur_ "
588
- ;;
589
- * )
590
- __gitcomp_file " $( __git_diff_index_files " $1 " ) " " " " $cur_ "
591
- ;;
592
- esac
515
+ __gitcomp_file " $( __git_index_files " $1 " " $pfx " ) " " $pfx " " $cur_ "
593
516
}
594
517
595
518
__git_complete_file ()
@@ -1213,7 +1136,7 @@ _git_commit ()
1213
1136
esac
1214
1137
1215
1138
if git rev-parse --verify --quiet HEAD > /dev/null; then
1216
- __git_complete_diff_index_file " HEAD "
1139
+ __git_complete_index_file " --committable "
1217
1140
else
1218
1141
# This is the first commit
1219
1142
__git_complete_index_file " --cached"
@@ -2702,14 +2625,6 @@ if [[ -n ${ZSH_VERSION-} ]]; then
2702
2625
2703
2626
compdef _git git gitk
2704
2627
return
2705
- elif [[ -n ${BASH_VERSION-} ]]; then
2706
- if (( ${BASH_VERSINFO[0]} < 4 )) ; then
2707
- # compopt is not supported
2708
- __git_index_file_list_filter ()
2709
- {
2710
- __git_index_file_list_filter_compat
2711
- }
2712
- fi
2713
2628
fi
2714
2629
2715
2630
__git_func_wrap ()
0 commit comments