3 # Copyright (c) 2012 Felipe Contreras
6 test_description
='test bash completion'
16 .
"$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
18 # We don't need this function to actually join words or do anything special.
19 # Also, it's cleaner to avoid touching bash's internal completion variables.
20 # So let's override it with a minimal version for testing purposes.
21 _get_comp_words_by_ref
()
23 while [ $# -gt 0 ]; do
29 prev
=${_words[_cword-1]}
32 words
=("${_words[@]}")
45 echo "${COMPREPLY[*]}" > out
50 local -a COMPREPLY _words
53 (( _cword
= ${#_words[@]} - 1 ))
54 __git_wrap__git_main
&& print_comp
57 # Test high-level completion
59 # 1: typed text so far (cur)
60 # 2: expected completion
65 printf '%s\n' "$2" >expected
67 sed -e 's/Z$//' >expected
69 run_completion
"$1" &&
75 test_expect_success
'__gitcomp - trailing space - options' '
76 sed -e "s/Z$//" >expected <<-\EOF &&
84 __gitcomp "--dry-run --reuse-message= --reedit-message=
87 echo "${COMPREPLY[*]}" > out
92 test_expect_success
'__gitcomp - trailing space - config keys' '
93 sed -e "s/Z$//" >expected <<-\EOF &&
95 branch.autosetupmerge Z
96 branch.autosetuprebase Z
100 local -a COMPREPLY &&
102 __gitcomp "branch. branch.autosetupmerge
103 branch.autosetuprebase browser." &&
105 echo "${COMPREPLY[*]}" > out
107 test_cmp expected out
110 test_expect_success
'__gitcomp - option parameter' '
111 sed -e "s/Z$//" >expected <<-\EOF &&
116 local -a COMPREPLY &&
117 cur="--strategy=re" &&
118 __gitcomp "octopus ours recursive resolve subtree
121 echo "${COMPREPLY[*]}" > out
123 test_cmp expected out
126 test_expect_success
'__gitcomp - prefix' '
127 sed -e "s/Z$//" >expected <<-\EOF &&
129 branch.maint.mergeoptions Z
132 local -a COMPREPLY &&
134 __gitcomp "remote merge mergeoptions rebase
135 " "branch.maint." "me" &&
137 echo "${COMPREPLY[*]}" > out
139 test_cmp expected out
142 test_expect_success
'__gitcomp - suffix' '
143 sed -e "s/Z$//" >expected <<-\EOF &&
148 local -a COMPREPLY &&
150 __gitcomp "master maint next pu
151 " "branch." "ma" "." &&
153 echo "${COMPREPLY[*]}" > out
155 test_cmp expected out
158 test_expect_success
'basic' '
159 run_completion "git \"\"" &&
161 grep -q "^add \$" out &&
163 grep -q "^filter-branch \$" out &&
165 ! grep -q "^ls-files \$" out &&
167 run_completion "git f" &&
168 ! grep -q -v "^f" out
171 test_expect_success
'double dash "git" itself' '
172 test_completion "git --" <<-\EOF
184 --no-replace-objects Z
189 test_expect_success
'double dash "git checkout"' '
190 test_completion "git checkout --" <<-\EOF
203 test_expect_success
'general options' '
204 test_completion "git --ver" "--version " &&
205 test_completion "git --hel" "--help " &&
206 test_completion "git --exe" <<-\EOF &&
210 test_completion "git --htm" "--html-path " &&
211 test_completion "git --pag" "--paginate " &&
212 test_completion "git --no-p" "--no-pager " &&
213 test_completion "git --git" "--git-dir=" &&
214 test_completion "git --wor" "--work-tree=" &&
215 test_completion "git --nam" "--namespace=" &&
216 test_completion "git --bar" "--bare " &&
217 test_completion "git --inf" "--info-path " &&
218 test_completion "git --no-r" "--no-replace-objects "
221 test_expect_success
'general options plus command' '
222 test_completion "git --version check" "checkout " &&
223 test_completion "git --paginate check" "checkout " &&
224 test_completion "git --git-dir=foo check" "checkout " &&
225 test_completion "git --bare check" "checkout " &&
226 test_completion "git --help des" "describe " &&
227 test_completion "git --exec-path=foo check" "checkout " &&
228 test_completion "git --html-path check" "checkout " &&
229 test_completion "git --no-pager check" "checkout " &&
230 test_completion "git --work-tree=foo check" "checkout " &&
231 test_completion "git --namespace=foo check" "checkout " &&
232 test_completion "git --paginate check" "checkout " &&
233 test_completion "git --info-path check" "checkout " &&
234 test_completion "git --no-replace-objects check" "checkout "
237 test_expect_success
'setup for ref completion' '
238 echo content >file1 &&
242 git branch mybranch &&
246 test_expect_success
'checkout completes ref names' '
247 test_completion "git checkout m" <<-\EOF
254 test_expect_success
'show completes all refs' '
255 test_completion "git show m" <<-\EOF
262 test_expect_success
'<ref>: completes paths' '
263 test_completion "git show mytag:f" <<-\EOF
269 test_expect_success
'complete tree filename with spaces' '
270 echo content >"name with spaces" &&
272 git commit -m spaces &&
273 test_completion "git show HEAD:nam" <<-\EOF
278 test_expect_failure
'complete tree filename with metacharacters' '
279 echo content >"name with \${meta}" &&
281 git commit -m meta &&
282 test_completion "git show HEAD:nam" <<-\EOF