58
58
#
59
59
# When set to "1" suggest all options, including options which are
60
60
# typically hidden (e.g. '--allow-empty' for 'git commit').
61
+ #
62
+ # GIT_COMPLETION_IGNORE_CASE
63
+ #
64
+ # When set, uses for-each-ref '--ignore-case' to find refs that match
65
+ # case insensitively, even on systems with case sensitive file systems
66
+ # (e.g., completing tag name "FOO" on "git checkout f<TAB>").
61
67
62
68
case " $COMP_WORDBREAKS " in
63
69
* :* ) : great ;;
@@ -646,6 +652,7 @@ __git_heads ()
646
652
local pfx=" ${1-} " cur_=" ${2-} " sfx=" ${3-} "
647
653
648
654
__git for-each-ref --format=" ${pfx// \% /%% } %(refname:strip=2)$sfx " \
655
+ ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
649
656
" refs/heads/$cur_ *" " refs/heads/$cur_ */**"
650
657
}
651
658
@@ -659,6 +666,7 @@ __git_remote_heads ()
659
666
local pfx=" ${1-} " cur_=" ${2-} " sfx=" ${3-} "
660
667
661
668
__git for-each-ref --format=" ${pfx// \% /%% } %(refname:strip=2)$sfx " \
669
+ ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
662
670
" refs/remotes/$cur_ *" " refs/remotes/$cur_ */**"
663
671
}
664
672
@@ -669,6 +677,7 @@ __git_tags ()
669
677
local pfx=" ${1-} " cur_=" ${2-} " sfx=" ${3-} "
670
678
671
679
__git for-each-ref --format=" ${pfx// \% /%% } %(refname:strip=2)$sfx " \
680
+ ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
672
681
" refs/tags/$cur_ *" " refs/tags/$cur_ */**"
673
682
}
674
683
@@ -688,6 +697,7 @@ __git_dwim_remote_heads ()
688
697
# but only output if the branch name is unique
689
698
__git for-each-ref --format=" $fer_pfx %(refname:strip=3)$sfx " \
690
699
--sort=" refname:strip=3" \
700
+ ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
691
701
" refs/remotes/*/$cur_ *" " refs/remotes/*/$cur_ */**" | \
692
702
uniq -u
693
703
}
@@ -712,6 +722,7 @@ __git_refs ()
712
722
local format refs
713
723
local pfx=" ${3-} " cur_=" ${4-$cur } " sfx=" ${5-} "
714
724
local match=" ${4-} "
725
+ local umatch=" ${4-} "
715
726
local fer_pfx=" ${pfx// \% /%% } " # "escape" for-each-ref format specifiers
716
727
717
728
__git_find_repo_path
@@ -735,12 +746,19 @@ __git_refs ()
735
746
fi
736
747
fi
737
748
749
+ if test " ${GIT_COMPLETION_IGNORE_CASE: +1} " = " 1"
750
+ then
751
+ # uppercase with tr instead of ${match,^^} for bash 3.2 compatibility
752
+ umatch=$( echo " $match " | tr a-z A-Z 2> /dev/null || echo " $match " )
753
+ fi
754
+
738
755
if [ " $list_refs_from " = path ]; then
739
756
if [[ " $cur_ " == ^* ]]; then
740
757
pfx=" $pfx ^"
741
758
fer_pfx=" $fer_pfx ^"
742
759
cur_=${cur_# ^}
743
760
match=${match# ^}
761
+ umatch=${umatch# ^}
744
762
fi
745
763
case " $cur_ " in
746
764
refs|refs/* )
@@ -751,7 +769,7 @@ __git_refs ()
751
769
* )
752
770
for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD; do
753
771
case " $i " in
754
- $match * )
772
+ $match * | $umatch * )
755
773
if [ -e " $dir /$i " ]; then
756
774
echo " $pfx$i$sfx "
757
775
fi
@@ -765,6 +783,7 @@ __git_refs ()
765
783
;;
766
784
esac
767
785
__git_dir=" $dir " __git for-each-ref --format=" $fer_pfx %($format )$sfx " \
786
+ ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
768
787
" ${refs[@]} "
769
788
if [ -n " $track " ]; then
770
789
__git_dwim_remote_heads " $pfx " " $match " " $sfx "
@@ -784,15 +803,16 @@ __git_refs ()
784
803
* )
785
804
if [ " $list_refs_from " = remote ]; then
786
805
case " HEAD" in
787
- $match * ) echo " ${pfx} HEAD$sfx " ;;
806
+ $match * | $umatch * ) echo " ${pfx} HEAD$sfx " ;;
788
807
esac
789
808
__git for-each-ref --format=" $fer_pfx %(refname:strip=3)$sfx " \
809
+ ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
790
810
" refs/remotes/$remote /$match *" \
791
811
" refs/remotes/$remote /$match */**"
792
812
else
793
813
local query_symref
794
814
case " HEAD" in
795
- $match * ) query_symref=" HEAD" ;;
815
+ $match * | $umatch * ) query_symref=" HEAD" ;;
796
816
esac
797
817
__git ls-remote " $remote " $query_symref \
798
818
" refs/tags/$match *" " refs/heads/$match *" \
0 commit comments