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" &&
74 # The first argument is the typed text so far (cur); the rest are
75 # passed to __gitcomp. Expected output comes is read from the
76 # standard input, like test_completion().
80 sed -e 's/Z$//' >expected
&&
88 test_expect_success
'__gitcomp - trailing space - options' '
89 test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
90 --reset-author" <<-EOF
97 test_expect_success
'__gitcomp - trailing space - config keys' '
98 test_gitcomp "br" "branch. branch.autosetupmerge
99 branch.autosetuprebase browser." <<-\EOF
101 branch.autosetupmerge Z
102 branch.autosetuprebase Z
107 test_expect_success
'__gitcomp - option parameter' '
108 test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
115 test_expect_success
'__gitcomp - prefix' '
116 test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
117 "branch.maint." "me" <<-\EOF
119 branch.maint.mergeoptions Z
123 test_expect_success
'__gitcomp - suffix' '
124 test_gitcomp "branch.me" "master maint next pu" "branch." \
131 test_expect_success
'basic' '
132 run_completion "git \"\"" &&
134 grep -q "^add \$" out &&
136 grep -q "^filter-branch \$" out &&
138 ! grep -q "^ls-files \$" out &&
140 run_completion "git f" &&
141 ! grep -q -v "^f" out
144 test_expect_success
'double dash "git" itself' '
145 test_completion "git --" <<-\EOF
157 --no-replace-objects Z
162 test_expect_success
'double dash "git checkout"' '
163 test_completion "git checkout --" <<-\EOF
176 test_expect_success
'general options' '
177 test_completion "git --ver" "--version " &&
178 test_completion "git --hel" "--help " &&
179 test_completion "git --exe" <<-\EOF &&
183 test_completion "git --htm" "--html-path " &&
184 test_completion "git --pag" "--paginate " &&
185 test_completion "git --no-p" "--no-pager " &&
186 test_completion "git --git" "--git-dir=" &&
187 test_completion "git --wor" "--work-tree=" &&
188 test_completion "git --nam" "--namespace=" &&
189 test_completion "git --bar" "--bare " &&
190 test_completion "git --inf" "--info-path " &&
191 test_completion "git --no-r" "--no-replace-objects "
194 test_expect_success
'general options plus command' '
195 test_completion "git --version check" "checkout " &&
196 test_completion "git --paginate check" "checkout " &&
197 test_completion "git --git-dir=foo check" "checkout " &&
198 test_completion "git --bare check" "checkout " &&
199 test_completion "git --help des" "describe " &&
200 test_completion "git --exec-path=foo check" "checkout " &&
201 test_completion "git --html-path check" "checkout " &&
202 test_completion "git --no-pager check" "checkout " &&
203 test_completion "git --work-tree=foo check" "checkout " &&
204 test_completion "git --namespace=foo check" "checkout " &&
205 test_completion "git --paginate check" "checkout " &&
206 test_completion "git --info-path check" "checkout " &&
207 test_completion "git --no-replace-objects check" "checkout "
210 test_expect_success
'setup for ref completion' '
211 echo content >file1 &&
215 git branch mybranch &&
219 test_expect_success
'checkout completes ref names' '
220 test_completion "git checkout m" <<-\EOF
227 test_expect_success
'show completes all refs' '
228 test_completion "git show m" <<-\EOF
235 test_expect_success
'<ref>: completes paths' '
236 test_completion "git show mytag:f" <<-\EOF
242 test_expect_success
'complete tree filename with spaces' '
243 echo content >"name with spaces" &&
245 git commit -m spaces &&
246 test_completion "git show HEAD:nam" <<-\EOF
251 test_expect_failure
'complete tree filename with metacharacters' '
252 echo content >"name with \${meta}" &&
254 git commit -m meta &&
255 test_completion "git show HEAD:nam" <<-\EOF
261 test_expect_success
'send-email' '
262 test_completion "git send-email --cov" "--cover-letter " &&
263 test_completion "git send-email ma" "master "