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.
70 test_completion_long
()
72 sed -e 's/Z$//' >expected
&&
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 --no-replace-objects Z
190 test_completion "git --"
193 test_expect_success
'double dash "git checkout"' '
194 sed -e "s/Z$//" >expected <<-\EOF &&
205 test_completion "git checkout --"
208 test_expect_success
'general options' '
209 test_completion "git --ver" "--version " &&
210 test_completion "git --hel" "--help " &&
211 sed -e "s/Z$//" >expected <<-\EOF &&
215 test_completion "git --exe" &&
216 test_completion "git --htm" "--html-path " &&
217 test_completion "git --pag" "--paginate " &&
218 test_completion "git --no-p" "--no-pager " &&
219 test_completion "git --git" "--git-dir=" &&
220 test_completion "git --wor" "--work-tree=" &&
221 test_completion "git --nam" "--namespace=" &&
222 test_completion "git --bar" "--bare " &&
223 test_completion "git --inf" "--info-path " &&
224 test_completion "git --no-r" "--no-replace-objects "
227 test_expect_success
'general options plus command' '
228 test_completion "git --version check" "checkout " &&
229 test_completion "git --paginate check" "checkout " &&
230 test_completion "git --git-dir=foo check" "checkout " &&
231 test_completion "git --bare check" "checkout " &&
232 test_completion "git --help des" "describe " &&
233 test_completion "git --exec-path=foo check" "checkout " &&
234 test_completion "git --html-path check" "checkout " &&
235 test_completion "git --no-pager check" "checkout " &&
236 test_completion "git --work-tree=foo check" "checkout " &&
237 test_completion "git --namespace=foo check" "checkout " &&
238 test_completion "git --paginate check" "checkout " &&
239 test_completion "git --info-path check" "checkout " &&
240 test_completion "git --no-replace-objects check" "checkout "
243 test_expect_success
'setup for ref completion' '
244 echo content >file1 &&
248 git branch mybranch &&
252 test_expect_success
'checkout completes ref names' '
253 test_completion_long "git checkout m" <<-\EOF
260 test_expect_success
'show completes all refs' '
261 test_completion_long "git show m" <<-\EOF
268 test_expect_success
'<ref>: completes paths' '
269 test_completion_long "git show mytag:f" <<-\EOF
275 test_expect_success
'complete tree filename with spaces' '
276 echo content >"name with spaces" &&
278 git commit -m spaces &&
279 test_completion_long "git show HEAD:nam" <<-\EOF
284 test_expect_failure
'complete tree filename with metacharacters' '
285 echo content >"name with \${meta}" &&
287 git commit -m meta &&
288 test_completion_long "git show HEAD:nam" <<-\EOF