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
63 test $# -gt 1 && echo "$2" > expected
64 run_completion
"$1" &&
68 # Like test_completion, but reads expectation from stdin,
69 # which is convenient when it is multiline. We also process "_" into
70 # spaces to make test vectors more readable.
71 test_completion_long
()
79 test_expect_success
'__gitcomp - trailing space - options' '
80 sed -e "s/Z$//" >expected <<-\EOF &&
88 __gitcomp "--dry-run --reuse-message= --reedit-message=
91 echo "${COMPREPLY[*]}" > out
96 test_expect_success
'__gitcomp - trailing space - config keys' '
97 sed -e "s/Z$//" >expected <<-\EOF &&
99 branch.autosetupmerge Z
100 branch.autosetuprebase Z
104 local -a COMPREPLY &&
106 __gitcomp "branch. branch.autosetupmerge
107 branch.autosetuprebase browser." &&
109 echo "${COMPREPLY[*]}" > out
111 test_cmp expected out
114 test_expect_success
'__gitcomp - option parameter' '
115 sed -e "s/Z$//" >expected <<-\EOF &&
120 local -a COMPREPLY &&
121 cur="--strategy=re" &&
122 __gitcomp "octopus ours recursive resolve subtree
125 echo "${COMPREPLY[*]}" > out
127 test_cmp expected out
130 test_expect_success
'__gitcomp - prefix' '
131 sed -e "s/Z$//" >expected <<-\EOF &&
133 branch.maint.mergeoptions Z
136 local -a COMPREPLY &&
138 __gitcomp "remote merge mergeoptions rebase
139 " "branch.maint." "me" &&
141 echo "${COMPREPLY[*]}" > out
143 test_cmp expected out
146 test_expect_success
'__gitcomp - suffix' '
147 sed -e "s/Z$//" >expected <<-\EOF &&
152 local -a COMPREPLY &&
154 __gitcomp "master maint next pu
155 " "branch." "ma" "." &&
157 echo "${COMPREPLY[*]}" > out
159 test_cmp expected out
162 test_expect_success
'basic' '
163 run_completion "git \"\"" &&
165 grep -q "^add \$" out &&
167 grep -q "^filter-branch \$" out &&
169 ! grep -q "^ls-files \$" out &&
171 run_completion "git f" &&
172 ! grep -q -v "^f" out
175 test_expect_success
'double dash "git" itself' '
176 sed -e "s/Z$//" >expected <<-\EOF &&
188 --no-replace-objects Z
191 test_completion "git --"
194 test_expect_success
'double dash "git checkout"' '
195 sed -e "s/Z$//" >expected <<-\EOF &&
206 test_completion "git checkout --"
209 test_expect_success
'general options' '
210 test_completion "git --ver" "--version " &&
211 test_completion "git --hel" "--help " &&
212 sed -e "s/Z$//" >expected <<-\EOF &&
216 test_completion "git --exe" &&
217 test_completion "git --htm" "--html-path " &&
218 test_completion "git --pag" "--paginate " &&
219 test_completion "git --no-p" "--no-pager " &&
220 test_completion "git --git" "--git-dir=" &&
221 test_completion "git --wor" "--work-tree=" &&
222 test_completion "git --nam" "--namespace=" &&
223 test_completion "git --bar" "--bare " &&
224 test_completion "git --inf" "--info-path " &&
225 test_completion "git --no-r" "--no-replace-objects "
228 test_expect_success
'general options plus command' '
229 test_completion "git --version check" "checkout " &&
230 test_completion "git --paginate check" "checkout " &&
231 test_completion "git --git-dir=foo check" "checkout " &&
232 test_completion "git --bare check" "checkout " &&
233 test_completion "git --help des" "describe " &&
234 test_completion "git --exec-path=foo check" "checkout " &&
235 test_completion "git --html-path check" "checkout " &&
236 test_completion "git --no-pager check" "checkout " &&
237 test_completion "git --work-tree=foo check" "checkout " &&
238 test_completion "git --namespace=foo check" "checkout " &&
239 test_completion "git --paginate check" "checkout " &&
240 test_completion "git --info-path check" "checkout " &&
241 test_completion "git --no-replace-objects check" "checkout "
244 test_expect_success
'setup for ref completion' '
245 echo content >file1 &&
249 git branch mybranch &&
253 test_expect_success
'checkout completes ref names' '
254 test_completion_long "git checkout m" <<-\EOF
261 test_expect_success
'show completes all refs' '
262 test_completion_long "git show m" <<-\EOF
269 test_expect_success
'<ref>: completes paths' '
270 test_completion_long "git show mytag:f" <<-\EOF
276 test_expect_success
'complete tree filename with spaces' '
277 echo content >"name with spaces" &&
279 git commit -m spaces &&
280 test_completion_long "git show HEAD:nam" <<-\EOF
285 test_expect_failure
'complete tree filename with metacharacters' '
286 echo content >"name with \${meta}" &&
288 git commit -m meta &&
289 test_completion_long "git show HEAD:nam" <<-\EOF