3 # Copyright (c) 2012 Felipe Contreras
6 test_description='test bash completion'
16 # Be careful when updating this list:
18 # (1) The build tree may have build artifact from different branch, or
19 # the user's $PATH may have a random executable that may begin
20 # with "git-check" that are not part of the subcommands this build
21 # will ship, e.g. "check-ignore". The tests for completion for
22 # subcommand names tests how "check" is expanded; we limit the
23 # possible candidates to "checkout" and "check-attr" to make sure
24 # "check-attr", which is known by the filter function as a
25 # subcommand to be thrown out, while excluding other random files
26 # that happen to begin with "check" to avoid letting them get in
29 # (2) A test makes sure that common subcommands are included in the
30 # completion for "git <TAB>", and a plumbing is excluded. "add",
31 # "filter-branch" and "ls-files" are listed for this.
33 GIT_TESTING_COMMAND_COMPLETION='add checkout check-attr filter-branch ls-files'
35 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
37 # We don't need this function to actually join words or do anything special.
38 # Also, it's cleaner to avoid touching bash's internal completion variables.
39 # So let's override it with a minimal version for testing purposes.
40 _get_comp_words_by_ref ()
42 while [ $# -gt 0 ]; do
48 prev=${_words[_cword-1]}
51 words=("${_words[@]}")
64 echo "${COMPREPLY[*]}" > out
69 local -a COMPREPLY _words
72 (( _cword = ${#_words[@]} - 1 ))
73 __git_wrap__git_main && print_comp
76 # Test high-level completion
78 # 1: typed text so far (cur)
79 # 2: expected completion
84 printf '%s\n' "$2" >expected
86 sed -e 's/Z$//' >expected
88 run_completion "$1" &&
93 # The first argument is the typed text so far (cur); the rest are
94 # passed to __gitcomp. Expected output comes is read from the
95 # standard input, like test_completion().
99 sed -e 's/Z$//' >expected &&
104 test_cmp expected out
107 test_expect_success '__gitcomp - trailing space - options' '
108 test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
109 --reset-author" <<-EOF
116 test_expect_success '__gitcomp - trailing space - config keys' '
117 test_gitcomp "br" "branch. branch.autosetupmerge
118 branch.autosetuprebase browser." <<-\EOF
120 branch.autosetupmerge Z
121 branch.autosetuprebase Z
126 test_expect_success '__gitcomp - option parameter' '
127 test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
134 test_expect_success '__gitcomp - prefix' '
135 test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
136 "branch.maint." "me" <<-\EOF
138 branch.maint.mergeoptions Z
142 test_expect_success '__gitcomp - suffix' '
143 test_gitcomp "branch.me" "master maint next pu" "branch." \
150 test_expect_success 'basic' '
151 run_completion "git \"\"" &&
153 grep -q "^add \$" out &&
155 grep -q "^filter-branch \$" out &&
157 ! grep -q "^ls-files \$" out &&
159 run_completion "git f" &&
160 ! grep -q -v "^f" out
163 test_expect_success 'double dash "git" itself' '
164 test_completion "git --" <<-\EOF
176 --no-replace-objects Z
181 test_expect_success 'double dash "git checkout"' '
182 test_completion "git checkout --" <<-\EOF
195 test_expect_success 'general options' '
196 test_completion "git --ver" "--version " &&
197 test_completion "git --hel" "--help " &&
198 test_completion "git --exe" <<-\EOF &&
202 test_completion "git --htm" "--html-path " &&
203 test_completion "git --pag" "--paginate " &&
204 test_completion "git --no-p" "--no-pager " &&
205 test_completion "git --git" "--git-dir=" &&
206 test_completion "git --wor" "--work-tree=" &&
207 test_completion "git --nam" "--namespace=" &&
208 test_completion "git --bar" "--bare " &&
209 test_completion "git --inf" "--info-path " &&
210 test_completion "git --no-r" "--no-replace-objects "
213 test_expect_success 'general options plus command' '
214 test_completion "git --version check" "checkout " &&
215 test_completion "git --paginate check" "checkout " &&
216 test_completion "git --git-dir=foo check" "checkout " &&
217 test_completion "git --bare check" "checkout " &&
218 test_completion "git --exec-path=foo check" "checkout " &&
219 test_completion "git --html-path check" "checkout " &&
220 test_completion "git --no-pager check" "checkout " &&
221 test_completion "git --work-tree=foo check" "checkout " &&
222 test_completion "git --namespace=foo check" "checkout " &&
223 test_completion "git --paginate check" "checkout " &&
224 test_completion "git --info-path check" "checkout " &&
225 test_completion "git --no-replace-objects check" "checkout "
228 test_expect_success 'git --help completion' '
229 test_completion "git --help ad" "add " &&
230 test_completion "git --help core" "core-tutorial "
233 test_expect_success 'setup for ref completion' '
234 echo content >file1 &&
238 git branch mybranch &&
242 test_expect_success 'checkout completes ref names' '
243 test_completion "git checkout m" <<-\EOF
250 test_expect_success 'show completes all refs' '
251 test_completion "git show m" <<-\EOF
258 test_expect_success '<ref>: completes paths' '
259 test_completion "git show mytag:f" <<-\EOF
265 test_expect_success 'complete tree filename with spaces' '
266 echo content >"name with spaces" &&
268 git commit -m spaces &&
269 test_completion "git show HEAD:nam" <<-\EOF
274 test_expect_failure 'complete tree filename with metacharacters' '
275 echo content >"name with \${meta}" &&
277 git commit -m meta &&
278 test_completion "git show HEAD:nam" <<-\EOF
284 test_expect_success 'send-email' '
285 test_completion "git send-email --cov" "--cover-letter " &&
286 test_completion "git send-email ma" "master "