3 # Copyright (c) 2012 Felipe Contreras
6 if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then
7 # we are in full-on bash mode
9 elif type bash >/dev/null 2>&1; then
10 # execute in full-on bash mode
14 echo '1..0 #SKIP skipping bash completion tests; bash not available'
18 test_description='test bash completion'
28 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
30 # We don't need this function to actually join words or do anything special.
31 # Also, it's cleaner to avoid touching bash's internal completion variables.
32 # So let's override it with a minimal version for testing purposes.
33 _get_comp_words_by_ref ()
35 while [ $# -gt 0 ]; do
41 prev=${_words[_cword-1]}
44 words=("${_words[@]}")
57 echo "${COMPREPLY[*]}" > out
62 local -a COMPREPLY _words
65 (( _cword = ${#_words[@]} - 1 ))
71 test $# -gt 1 && echo "$2" > expected
72 run_completion "$@" &&
78 test_expect_success '__gitcomp - trailing space - options' '
79 sed -e "s/Z$//" >expected <<-\EOF &&
87 __gitcomp "--dry-run --reuse-message= --reedit-message=
90 echo "${COMPREPLY[*]}" > out
95 test_expect_success '__gitcomp - trailing space - config keys' '
96 sed -e "s/Z$//" >expected <<-\EOF &&
98 branch.autosetupmerge Z
99 branch.autosetuprebase Z
103 local -a COMPREPLY &&
105 __gitcomp "branch. branch.autosetupmerge
106 branch.autosetuprebase browser." &&
108 echo "${COMPREPLY[*]}" > out
110 test_cmp expected out
113 test_expect_success '__gitcomp - option parameter' '
114 sed -e "s/Z$//" >expected <<-\EOF &&
119 local -a COMPREPLY &&
120 cur="--strategy=re" &&
121 __gitcomp "octopus ours recursive resolve subtree
124 echo "${COMPREPLY[*]}" > out
126 test_cmp expected out
129 test_expect_success '__gitcomp - prefix' '
130 sed -e "s/Z$//" >expected <<-\EOF &&
132 branch.maint.mergeoptions Z
135 local -a COMPREPLY &&
137 __gitcomp "remote merge mergeoptions rebase
138 " "branch.maint." "me" &&
140 echo "${COMPREPLY[*]}" > out
142 test_cmp expected out
145 test_expect_success '__gitcomp - suffix' '
146 sed -e "s/Z$//" >expected <<-\EOF &&
151 local -a COMPREPLY &&
153 __gitcomp "master maint next pu
154 " "branch." "ma" "." &&
156 echo "${COMPREPLY[*]}" > out
158 test_cmp expected out
161 test_expect_success 'basic' '
162 run_completion "git \"\"" &&
164 grep -q "^add \$" out &&
166 grep -q "^filter-branch \$" out &&
168 ! grep -q "^ls-files \$" out &&
170 run_completion "git f" &&
171 ! grep -q -v "^f" out
174 test_expect_success 'double dash "git" itself' '
175 sed -e "s/Z$//" >expected <<-\EOF &&
187 test_completion "git --"
190 test_expect_success 'double dash "git checkout"' '
191 sed -e "s/Z$//" >expected <<-\EOF &&
202 test_completion "git checkout --"