]>
Commit | Line | Data |
---|---|---|
5c293a6b FC |
1 | #!/bin/sh |
2 | # | |
af806a2c | 3 | # Copyright (c) 2012-2020 Felipe Contreras |
5c293a6b FC |
4 | # |
5 | ||
5c293a6b FC |
6 | test_description='test bash completion' |
7 | ||
334afbc7 JS |
8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master |
9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME | |
10 | ||
f8891cfa | 11 | . ./lib-bash.sh |
5c293a6b FC |
12 | |
13 | complete () | |
14 | { | |
15 | # do nothing | |
16 | return 0 | |
17 | } | |
18 | ||
84a97131 | 19 | # Be careful when updating these lists: |
50478223 JH |
20 | # |
21 | # (1) The build tree may have build artifact from different branch, or | |
22 | # the user's $PATH may have a random executable that may begin | |
23 | # with "git-check" that are not part of the subcommands this build | |
24 | # will ship, e.g. "check-ignore". The tests for completion for | |
25 | # subcommand names tests how "check" is expanded; we limit the | |
26 | # possible candidates to "checkout" and "check-attr" to make sure | |
27 | # "check-attr", which is known by the filter function as a | |
28 | # subcommand to be thrown out, while excluding other random files | |
29 | # that happen to begin with "check" to avoid letting them get in | |
30 | # the way. | |
31 | # | |
32 | # (2) A test makes sure that common subcommands are included in the | |
33 | # completion for "git <TAB>", and a plumbing is excluded. "add", | |
483e8611 | 34 | # "rebase" and "ls-files" are listed for this. |
50478223 | 35 | |
483e8611 EN |
36 | GIT_TESTING_ALL_COMMAND_LIST='add checkout check-attr rebase ls-files' |
37 | GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout rebase' | |
50478223 | 38 | |
5c293a6b FC |
39 | . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" |
40 | ||
41 | # We don't need this function to actually join words or do anything special. | |
42 | # Also, it's cleaner to avoid touching bash's internal completion variables. | |
43 | # So let's override it with a minimal version for testing purposes. | |
44 | _get_comp_words_by_ref () | |
45 | { | |
46 | while [ $# -gt 0 ]; do | |
47 | case "$1" in | |
48 | cur) | |
49 | cur=${_words[_cword]} | |
50 | ;; | |
51 | prev) | |
52 | prev=${_words[_cword-1]} | |
53 | ;; | |
54 | words) | |
55 | words=("${_words[@]}") | |
56 | ;; | |
57 | cword) | |
58 | cword=$_cword | |
59 | ;; | |
60 | esac | |
61 | shift | |
62 | done | |
63 | } | |
64 | ||
65 | print_comp () | |
66 | { | |
67 | local IFS=$'\n' | |
68 | echo "${COMPREPLY[*]}" > out | |
69 | } | |
70 | ||
71 | run_completion () | |
72 | { | |
73 | local -a COMPREPLY _words | |
74 | local _cword | |
75 | _words=( $1 ) | |
0ef09702 | 76 | test "${1: -1}" = ' ' && _words[${#_words[@]}+1]='' |
5c293a6b | 77 | (( _cword = ${#_words[@]} - 1 )) |
93b291e0 | 78 | __git_wrap__git_main && print_comp |
5c293a6b FC |
79 | } |
80 | ||
701ecdf1 FC |
81 | # Test high-level completion |
82 | # Arguments are: | |
83 | # 1: typed text so far (cur) | |
84 | # 2: expected completion | |
5c293a6b FC |
85 | test_completion () |
86 | { | |
2fbaf813 FC |
87 | if test $# -gt 1 |
88 | then | |
89 | printf '%s\n' "$2" >expected | |
90 | else | |
9703797c | 91 | sed -e 's/Z$//' |sort >expected |
2fbaf813 | 92 | fi && |
701ecdf1 | 93 | run_completion "$1" && |
9703797c SG |
94 | sort out >out_sorted && |
95 | test_cmp expected out_sorted | |
5c293a6b FC |
96 | } |
97 | ||
e4615238 FC |
98 | # Test __gitcomp. |
99 | # The first argument is the typed text so far (cur); the rest are | |
100 | # passed to __gitcomp. Expected output comes is read from the | |
101 | # standard input, like test_completion(). | |
102 | test_gitcomp () | |
49ba92b4 | 103 | { |
17393033 | 104 | local -a COMPREPLY && |
e4615238 | 105 | sed -e 's/Z$//' >expected && |
eac90623 | 106 | local cur="$1" && |
17393033 FC |
107 | shift && |
108 | __gitcomp "$@" && | |
109 | print_comp && | |
74a8c849 | 110 | test_cmp expected out |
49ba92b4 JK |
111 | } |
112 | ||
43369a22 FC |
113 | # Test __gitcomp_nl |
114 | # Arguments are: | |
115 | # 1: current word (cur) | |
116 | # -: the rest are passed to __gitcomp_nl | |
117 | test_gitcomp_nl () | |
118 | { | |
119 | local -a COMPREPLY && | |
120 | sed -e 's/Z$//' >expected && | |
eac90623 | 121 | local cur="$1" && |
43369a22 FC |
122 | shift && |
123 | __gitcomp_nl "$@" && | |
124 | print_comp && | |
125 | test_cmp expected out | |
126 | } | |
127 | ||
128 | invalid_variable_name='${foo.bar}' | |
129 | ||
c9a102e8 SG |
130 | actual="$TRASH_DIRECTORY/actual" |
131 | ||
f6114408 SG |
132 | if test_have_prereq MINGW |
133 | then | |
134 | ROOT="$(pwd -W)" | |
135 | else | |
136 | ROOT="$(pwd)" | |
137 | fi | |
138 | ||
fad9484f | 139 | test_expect_success 'setup for __git_find_repo_path/__gitdir tests' ' |
c9a102e8 | 140 | mkdir -p subdir/subsubdir && |
fad9484f | 141 | mkdir -p non-repo && |
c9a102e8 SG |
142 | git init otherrepo |
143 | ' | |
144 | ||
fad9484f | 145 | test_expect_success '__git_find_repo_path - from command line (through $__git_dir)' ' |
f6114408 | 146 | echo "$ROOT/otherrepo/.git" >expected && |
c9a102e8 | 147 | ( |
f6114408 | 148 | __git_dir="$ROOT/otherrepo/.git" && |
fad9484f SG |
149 | __git_find_repo_path && |
150 | echo "$__git_repo_path" >"$actual" | |
beb6ee71 | 151 | ) && |
c9a102e8 SG |
152 | test_cmp expected "$actual" |
153 | ' | |
154 | ||
fad9484f | 155 | test_expect_success '__git_find_repo_path - .git directory in cwd' ' |
c9a102e8 | 156 | echo ".git" >expected && |
beb6ee71 | 157 | ( |
fad9484f SG |
158 | __git_find_repo_path && |
159 | echo "$__git_repo_path" >"$actual" | |
beb6ee71 | 160 | ) && |
c9a102e8 SG |
161 | test_cmp expected "$actual" |
162 | ' | |
163 | ||
fad9484f | 164 | test_expect_success '__git_find_repo_path - .git directory in parent' ' |
f6114408 | 165 | echo "$ROOT/.git" >expected && |
c9a102e8 SG |
166 | ( |
167 | cd subdir/subsubdir && | |
fad9484f SG |
168 | __git_find_repo_path && |
169 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
170 | ) && |
171 | test_cmp expected "$actual" | |
172 | ' | |
173 | ||
fad9484f | 174 | test_expect_success '__git_find_repo_path - cwd is a .git directory' ' |
c9a102e8 SG |
175 | echo "." >expected && |
176 | ( | |
177 | cd .git && | |
fad9484f SG |
178 | __git_find_repo_path && |
179 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
180 | ) && |
181 | test_cmp expected "$actual" | |
182 | ' | |
183 | ||
fad9484f | 184 | test_expect_success '__git_find_repo_path - parent is a .git directory' ' |
f6114408 | 185 | echo "$ROOT/.git" >expected && |
c9a102e8 | 186 | ( |
5340d471 | 187 | cd .git/objects && |
fad9484f SG |
188 | __git_find_repo_path && |
189 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
190 | ) && |
191 | test_cmp expected "$actual" | |
192 | ' | |
193 | ||
fad9484f | 194 | test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in cwd' ' |
f6114408 | 195 | echo "$ROOT/otherrepo/.git" >expected && |
c9a102e8 | 196 | ( |
f6114408 | 197 | GIT_DIR="$ROOT/otherrepo/.git" && |
c9a102e8 | 198 | export GIT_DIR && |
fad9484f SG |
199 | __git_find_repo_path && |
200 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
201 | ) && |
202 | test_cmp expected "$actual" | |
203 | ' | |
204 | ||
fad9484f | 205 | test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in parent' ' |
f6114408 | 206 | echo "$ROOT/otherrepo/.git" >expected && |
c9a102e8 | 207 | ( |
f6114408 | 208 | GIT_DIR="$ROOT/otherrepo/.git" && |
c9a102e8 SG |
209 | export GIT_DIR && |
210 | cd subdir && | |
fad9484f SG |
211 | __git_find_repo_path && |
212 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
213 | ) && |
214 | test_cmp expected "$actual" | |
215 | ' | |
216 | ||
fad9484f | 217 | test_expect_success '__git_find_repo_path - from command line while "git -C"' ' |
80ac0744 SG |
218 | echo "$ROOT/.git" >expected && |
219 | ( | |
220 | __git_dir="$ROOT/.git" && | |
221 | __git_C_args=(-C otherrepo) && | |
fad9484f SG |
222 | __git_find_repo_path && |
223 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
224 | ) && |
225 | test_cmp expected "$actual" | |
226 | ' | |
227 | ||
fad9484f | 228 | test_expect_success '__git_find_repo_path - relative dir from command line and "git -C"' ' |
80ac0744 SG |
229 | echo "$ROOT/otherrepo/.git" >expected && |
230 | ( | |
231 | cd subdir && | |
232 | __git_dir="otherrepo/.git" && | |
233 | __git_C_args=(-C ..) && | |
fad9484f SG |
234 | __git_find_repo_path && |
235 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
236 | ) && |
237 | test_cmp expected "$actual" | |
238 | ' | |
239 | ||
fad9484f | 240 | test_expect_success '__git_find_repo_path - $GIT_DIR set while "git -C"' ' |
80ac0744 SG |
241 | echo "$ROOT/.git" >expected && |
242 | ( | |
243 | GIT_DIR="$ROOT/.git" && | |
244 | export GIT_DIR && | |
245 | __git_C_args=(-C otherrepo) && | |
fad9484f SG |
246 | __git_find_repo_path && |
247 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
248 | ) && |
249 | test_cmp expected "$actual" | |
250 | ' | |
251 | ||
fad9484f | 252 | test_expect_success '__git_find_repo_path - relative dir in $GIT_DIR and "git -C"' ' |
80ac0744 SG |
253 | echo "$ROOT/otherrepo/.git" >expected && |
254 | ( | |
255 | cd subdir && | |
256 | GIT_DIR="otherrepo/.git" && | |
257 | export GIT_DIR && | |
258 | __git_C_args=(-C ..) && | |
fad9484f SG |
259 | __git_find_repo_path && |
260 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
261 | ) && |
262 | test_cmp expected "$actual" | |
263 | ' | |
264 | ||
fad9484f | 265 | test_expect_success '__git_find_repo_path - "git -C" while .git directory in cwd' ' |
80ac0744 SG |
266 | echo "$ROOT/otherrepo/.git" >expected && |
267 | ( | |
268 | __git_C_args=(-C otherrepo) && | |
fad9484f SG |
269 | __git_find_repo_path && |
270 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
271 | ) && |
272 | test_cmp expected "$actual" | |
273 | ' | |
274 | ||
fad9484f | 275 | test_expect_success '__git_find_repo_path - "git -C" while cwd is a .git directory' ' |
80ac0744 SG |
276 | echo "$ROOT/otherrepo/.git" >expected && |
277 | ( | |
278 | cd .git && | |
279 | __git_C_args=(-C .. -C otherrepo) && | |
fad9484f SG |
280 | __git_find_repo_path && |
281 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
282 | ) && |
283 | test_cmp expected "$actual" | |
284 | ' | |
285 | ||
fad9484f | 286 | test_expect_success '__git_find_repo_path - "git -C" while .git directory in parent' ' |
80ac0744 SG |
287 | echo "$ROOT/otherrepo/.git" >expected && |
288 | ( | |
289 | cd subdir && | |
290 | __git_C_args=(-C .. -C otherrepo) && | |
fad9484f SG |
291 | __git_find_repo_path && |
292 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
293 | ) && |
294 | test_cmp expected "$actual" | |
295 | ' | |
296 | ||
fad9484f | 297 | test_expect_success '__git_find_repo_path - non-existing path in "git -C"' ' |
80ac0744 SG |
298 | ( |
299 | __git_C_args=(-C non-existing) && | |
fad9484f SG |
300 | test_must_fail __git_find_repo_path && |
301 | printf "$__git_repo_path" >"$actual" | |
80ac0744 SG |
302 | ) && |
303 | test_must_be_empty "$actual" | |
304 | ' | |
305 | ||
fad9484f | 306 | test_expect_success '__git_find_repo_path - non-existing path in $__git_dir' ' |
a2f03b0e SG |
307 | ( |
308 | __git_dir="non-existing" && | |
fad9484f SG |
309 | test_must_fail __git_find_repo_path && |
310 | printf "$__git_repo_path" >"$actual" | |
a2f03b0e SG |
311 | ) && |
312 | test_must_be_empty "$actual" | |
313 | ' | |
314 | ||
fad9484f | 315 | test_expect_success '__git_find_repo_path - non-existing $GIT_DIR' ' |
c9a102e8 | 316 | ( |
f6114408 | 317 | GIT_DIR="$ROOT/non-existing" && |
c9a102e8 | 318 | export GIT_DIR && |
fad9484f SG |
319 | test_must_fail __git_find_repo_path && |
320 | printf "$__git_repo_path" >"$actual" | |
8f0fa85d SG |
321 | ) && |
322 | test_must_be_empty "$actual" | |
c9a102e8 SG |
323 | ' |
324 | ||
fad9484f | 325 | test_expect_success '__git_find_repo_path - gitfile in cwd' ' |
f6114408 SG |
326 | echo "$ROOT/otherrepo/.git" >expected && |
327 | echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git && | |
c9a102e8 SG |
328 | test_when_finished "rm -f subdir/.git" && |
329 | ( | |
330 | cd subdir && | |
fad9484f SG |
331 | __git_find_repo_path && |
332 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
333 | ) && |
334 | test_cmp expected "$actual" | |
335 | ' | |
336 | ||
fad9484f | 337 | test_expect_success '__git_find_repo_path - gitfile in parent' ' |
f6114408 SG |
338 | echo "$ROOT/otherrepo/.git" >expected && |
339 | echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git && | |
c9a102e8 SG |
340 | test_when_finished "rm -f subdir/.git" && |
341 | ( | |
342 | cd subdir/subsubdir && | |
fad9484f SG |
343 | __git_find_repo_path && |
344 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
345 | ) && |
346 | test_cmp expected "$actual" | |
347 | ' | |
348 | ||
fad9484f | 349 | test_expect_success SYMLINKS '__git_find_repo_path - resulting path avoids symlinks' ' |
f6114408 | 350 | echo "$ROOT/otherrepo/.git" >expected && |
c9a102e8 SG |
351 | mkdir otherrepo/dir && |
352 | test_when_finished "rm -rf otherrepo/dir" && | |
353 | ln -s otherrepo/dir link && | |
354 | test_when_finished "rm -f link" && | |
355 | ( | |
356 | cd link && | |
fad9484f SG |
357 | __git_find_repo_path && |
358 | echo "$__git_repo_path" >"$actual" | |
359 | ) && | |
360 | test_cmp expected "$actual" | |
361 | ' | |
362 | ||
363 | test_expect_success '__git_find_repo_path - not a git repository' ' | |
364 | ( | |
365 | cd non-repo && | |
366 | GIT_CEILING_DIRECTORIES="$ROOT" && | |
367 | export GIT_CEILING_DIRECTORIES && | |
368 | test_must_fail __git_find_repo_path && | |
369 | printf "$__git_repo_path" >"$actual" | |
370 | ) && | |
371 | test_must_be_empty "$actual" | |
372 | ' | |
373 | ||
374 | test_expect_success '__gitdir - finds repo' ' | |
375 | echo "$ROOT/.git" >expected && | |
376 | ( | |
377 | cd subdir/subsubdir && | |
c9a102e8 SG |
378 | __gitdir >"$actual" |
379 | ) && | |
380 | test_cmp expected "$actual" | |
381 | ' | |
382 | ||
fad9484f | 383 | |
4dc8b1c1 | 384 | test_expect_success '__gitdir - returns error when cannot find repo' ' |
fad9484f SG |
385 | ( |
386 | __git_dir="non-existing" && | |
387 | test_must_fail __gitdir >"$actual" | |
388 | ) && | |
8f0fa85d | 389 | test_must_be_empty "$actual" |
c9a102e8 SG |
390 | ' |
391 | ||
fad9484f SG |
392 | test_expect_success '__gitdir - repo as argument' ' |
393 | echo "otherrepo/.git" >expected && | |
394 | ( | |
395 | __gitdir "otherrepo" >"$actual" | |
396 | ) && | |
397 | test_cmp expected "$actual" | |
398 | ' | |
399 | ||
400 | test_expect_success '__gitdir - remote as argument' ' | |
401 | echo "remote" >expected && | |
402 | ( | |
403 | __gitdir "remote" >"$actual" | |
404 | ) && | |
405 | test_cmp expected "$actual" | |
406 | ' | |
407 | ||
f12785a3 SG |
408 | |
409 | test_expect_success '__git_dequote - plain unquoted word' ' | |
410 | __git_dequote unquoted-word && | |
411 | verbose test unquoted-word = "$dequoted_word" | |
412 | ' | |
413 | ||
414 | # input: b\a\c\k\'\\\"s\l\a\s\h\es | |
415 | # expected: back'\"slashes | |
416 | test_expect_success '__git_dequote - backslash escaped' ' | |
417 | __git_dequote "b\a\c\k\\'\''\\\\\\\"s\l\a\s\h\es" && | |
418 | verbose test "back'\''\\\"slashes" = "$dequoted_word" | |
419 | ' | |
420 | ||
421 | # input: sin'gle\' '"quo'ted | |
422 | # expected: single\ "quoted | |
423 | test_expect_success '__git_dequote - single quoted' ' | |
424 | __git_dequote "'"sin'gle\\\\' '\\\"quo'ted"'" && | |
425 | verbose test '\''single\ "quoted'\'' = "$dequoted_word" | |
426 | ' | |
427 | ||
428 | # input: dou"ble\\" "\"\quot"ed | |
429 | # expected: double\ "\quoted | |
430 | test_expect_success '__git_dequote - double quoted' ' | |
431 | __git_dequote '\''dou"ble\\" "\"\quot"ed'\'' && | |
432 | verbose test '\''double\ "\quoted'\'' = "$dequoted_word" | |
433 | ' | |
434 | ||
435 | # input: 'open single quote | |
436 | test_expect_success '__git_dequote - open single quote' ' | |
437 | __git_dequote "'\''open single quote" && | |
438 | verbose test "open single quote" = "$dequoted_word" | |
439 | ' | |
440 | ||
441 | # input: "open double quote | |
442 | test_expect_success '__git_dequote - open double quote' ' | |
443 | __git_dequote "\"open double quote" && | |
444 | verbose test "open double quote" = "$dequoted_word" | |
445 | ' | |
446 | ||
447 | ||
fef56eb0 SG |
448 | test_expect_success '__gitcomp_direct - puts everything into COMPREPLY as-is' ' |
449 | sed -e "s/Z$//g" >expected <<-EOF && | |
450 | with-trailing-space Z | |
451 | without-trailing-spaceZ | |
452 | --option Z | |
453 | --option=Z | |
454 | $invalid_variable_name Z | |
455 | EOF | |
456 | ( | |
457 | cur=should_be_ignored && | |
458 | __gitcomp_direct "$(cat expected)" && | |
459 | print_comp | |
460 | ) && | |
461 | test_cmp expected out | |
462 | ' | |
463 | ||
74a8c849 | 464 | test_expect_success '__gitcomp - trailing space - options' ' |
e4615238 FC |
465 | test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message= |
466 | --reset-author" <<-EOF | |
74a8c849 SG |
467 | --reuse-message=Z |
468 | --reedit-message=Z | |
469 | --reset-author Z | |
470 | EOF | |
74a8c849 SG |
471 | ' |
472 | ||
473 | test_expect_success '__gitcomp - trailing space - config keys' ' | |
e4615238 FC |
474 | test_gitcomp "br" "branch. branch.autosetupmerge |
475 | branch.autosetuprebase browser." <<-\EOF | |
74a8c849 SG |
476 | branch.Z |
477 | branch.autosetupmerge Z | |
478 | branch.autosetuprebase Z | |
479 | browser.Z | |
480 | EOF | |
74a8c849 SG |
481 | ' |
482 | ||
483 | test_expect_success '__gitcomp - option parameter' ' | |
e4615238 FC |
484 | test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \ |
485 | "" "re" <<-\EOF | |
74a8c849 SG |
486 | recursive Z |
487 | resolve Z | |
488 | EOF | |
74a8c849 SG |
489 | ' |
490 | ||
491 | test_expect_success '__gitcomp - prefix' ' | |
e4615238 FC |
492 | test_gitcomp "branch.me" "remote merge mergeoptions rebase" \ |
493 | "branch.maint." "me" <<-\EOF | |
74a8c849 SG |
494 | branch.maint.merge Z |
495 | branch.maint.mergeoptions Z | |
496 | EOF | |
74a8c849 SG |
497 | ' |
498 | ||
499 | test_expect_success '__gitcomp - suffix' ' | |
6dca5dbf | 500 | test_gitcomp "branch.me" "master maint next seen" "branch." \ |
e4615238 | 501 | "ma" "." <<-\EOF |
74a8c849 SG |
502 | branch.master.Z |
503 | branch.maint.Z | |
504 | EOF | |
74a8c849 SG |
505 | ' |
506 | ||
b221b5ab NTND |
507 | test_expect_success '__gitcomp - ignore optional negative options' ' |
508 | test_gitcomp "--" "--abc --def --no-one -- --no-two" <<-\EOF | |
509 | --abc Z | |
510 | --def Z | |
511 | --no-one Z | |
512 | --no-... Z | |
513 | EOF | |
514 | ' | |
515 | ||
516 | test_expect_success '__gitcomp - ignore/narrow optional negative options' ' | |
517 | test_gitcomp "--a" "--abc --abcdef --no-one -- --no-two" <<-\EOF | |
518 | --abc Z | |
519 | --abcdef Z | |
520 | EOF | |
521 | ' | |
522 | ||
523 | test_expect_success '__gitcomp - ignore/narrow optional negative options' ' | |
524 | test_gitcomp "--n" "--abc --def --no-one -- --no-two" <<-\EOF | |
525 | --no-one Z | |
526 | --no-... Z | |
527 | EOF | |
528 | ' | |
529 | ||
530 | test_expect_success '__gitcomp - expand all negative options' ' | |
531 | test_gitcomp "--no-" "--abc --def --no-one -- --no-two" <<-\EOF | |
532 | --no-one Z | |
533 | --no-two Z | |
534 | EOF | |
535 | ' | |
536 | ||
537 | test_expect_success '__gitcomp - expand/narrow all negative options' ' | |
538 | test_gitcomp "--no-o" "--abc --def --no-one -- --no-two" <<-\EOF | |
539 | --no-one Z | |
540 | EOF | |
541 | ' | |
542 | ||
7d13e0a3 | 543 | test_expect_success '__gitcomp - doesnt fail because of invalid variable name' ' |
43369a22 FC |
544 | __gitcomp "$invalid_variable_name" |
545 | ' | |
546 | ||
547 | read -r -d "" refs <<-\EOF | |
f33f2d3d | 548 | main |
43369a22 | 549 | maint |
43369a22 | 550 | next |
6dca5dbf | 551 | seen |
43369a22 FC |
552 | EOF |
553 | ||
554 | test_expect_success '__gitcomp_nl - trailing space' ' | |
555 | test_gitcomp_nl "m" "$refs" <<-EOF | |
f33f2d3d | 556 | main Z |
43369a22 | 557 | maint Z |
43369a22 FC |
558 | EOF |
559 | ' | |
560 | ||
561 | test_expect_success '__gitcomp_nl - prefix' ' | |
562 | test_gitcomp_nl "--fixup=m" "$refs" "--fixup=" "m" <<-EOF | |
f33f2d3d | 563 | --fixup=main Z |
43369a22 | 564 | --fixup=maint Z |
43369a22 FC |
565 | EOF |
566 | ' | |
567 | ||
568 | test_expect_success '__gitcomp_nl - suffix' ' | |
569 | test_gitcomp_nl "branch.ma" "$refs" "branch." "ma" "." <<-\EOF | |
f33f2d3d | 570 | branch.main.Z |
43369a22 | 571 | branch.maint.Z |
43369a22 FC |
572 | EOF |
573 | ' | |
574 | ||
575 | test_expect_success '__gitcomp_nl - no suffix' ' | |
576 | test_gitcomp_nl "ma" "$refs" "" "ma" "" <<-\EOF | |
f33f2d3d | 577 | mainZ |
43369a22 | 578 | maintZ |
43369a22 FC |
579 | EOF |
580 | ' | |
581 | ||
7d13e0a3 | 582 | test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name' ' |
43369a22 FC |
583 | __gitcomp_nl "$invalid_variable_name" |
584 | ' | |
585 | ||
2acc1940 SG |
586 | test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from config file' ' |
587 | cat >expect <<-EOF && | |
588 | remote_from_file_1 | |
589 | remote_from_file_2 | |
590 | remote_in_config_1 | |
591 | remote_in_config_2 | |
592 | EOF | |
593 | test_when_finished "rm -rf .git/remotes" && | |
594 | mkdir -p .git/remotes && | |
595 | >.git/remotes/remote_from_file_1 && | |
596 | >.git/remotes/remote_from_file_2 && | |
597 | test_when_finished "git remote remove remote_in_config_1" && | |
598 | git remote add remote_in_config_1 git://remote_1 && | |
599 | test_when_finished "git remote remove remote_in_config_2" && | |
600 | git remote add remote_in_config_2 git://remote_2 && | |
beb6ee71 SG |
601 | ( |
602 | __git_remotes >actual | |
603 | ) && | |
2acc1940 SG |
604 | test_cmp expect actual |
605 | ' | |
606 | ||
69a77596 SG |
607 | test_expect_success '__git_is_configured_remote' ' |
608 | test_when_finished "git remote remove remote_1" && | |
609 | git remote add remote_1 git://remote_1 && | |
610 | test_when_finished "git remote remove remote_2" && | |
611 | git remote add remote_2 git://remote_2 && | |
beb6ee71 SG |
612 | ( |
613 | verbose __git_is_configured_remote remote_2 && | |
614 | test_must_fail __git_is_configured_remote non-existent | |
615 | ) | |
69a77596 SG |
616 | ' |
617 | ||
fb9cd420 SG |
618 | test_expect_success 'setup for ref completion' ' |
619 | git commit --allow-empty -m initial && | |
620 | git branch matching-branch && | |
621 | git tag matching-tag && | |
622 | ( | |
623 | cd otherrepo && | |
624 | git commit --allow-empty -m initial && | |
625 | git branch -m master master-in-other && | |
626 | git branch branch-in-other && | |
627 | git tag tag-in-other | |
628 | ) && | |
629 | git remote add other "$ROOT/otherrepo/.git" && | |
630 | git fetch --no-tags other && | |
631 | rm -f .git/FETCH_HEAD && | |
632 | git init thirdrepo | |
633 | ' | |
634 | ||
635 | test_expect_success '__git_refs - simple' ' | |
636 | cat >expected <<-EOF && | |
637 | HEAD | |
638 | master | |
639 | matching-branch | |
640 | other/branch-in-other | |
641 | other/master-in-other | |
642 | matching-tag | |
643 | EOF | |
644 | ( | |
645 | cur= && | |
646 | __git_refs >"$actual" | |
647 | ) && | |
648 | test_cmp expected "$actual" | |
649 | ' | |
650 | ||
651 | test_expect_success '__git_refs - full refs' ' | |
652 | cat >expected <<-EOF && | |
653 | refs/heads/master | |
654 | refs/heads/matching-branch | |
e896369b SG |
655 | refs/remotes/other/branch-in-other |
656 | refs/remotes/other/master-in-other | |
657 | refs/tags/matching-tag | |
fb9cd420 SG |
658 | EOF |
659 | ( | |
660 | cur=refs/heads/ && | |
661 | __git_refs >"$actual" | |
662 | ) && | |
663 | test_cmp expected "$actual" | |
664 | ' | |
665 | ||
666 | test_expect_success '__git_refs - repo given on the command line' ' | |
667 | cat >expected <<-EOF && | |
668 | HEAD | |
669 | branch-in-other | |
670 | master-in-other | |
671 | tag-in-other | |
672 | EOF | |
673 | ( | |
674 | __git_dir="$ROOT/otherrepo/.git" && | |
675 | cur= && | |
676 | __git_refs >"$actual" | |
677 | ) && | |
678 | test_cmp expected "$actual" | |
679 | ' | |
680 | ||
681 | test_expect_success '__git_refs - remote on local file system' ' | |
682 | cat >expected <<-EOF && | |
683 | HEAD | |
684 | branch-in-other | |
685 | master-in-other | |
686 | tag-in-other | |
687 | EOF | |
688 | ( | |
689 | cur= && | |
690 | __git_refs otherrepo >"$actual" | |
691 | ) && | |
692 | test_cmp expected "$actual" | |
693 | ' | |
694 | ||
695 | test_expect_success '__git_refs - remote on local file system - full refs' ' | |
696 | cat >expected <<-EOF && | |
697 | refs/heads/branch-in-other | |
698 | refs/heads/master-in-other | |
699 | refs/tags/tag-in-other | |
700 | EOF | |
701 | ( | |
702 | cur=refs/ && | |
703 | __git_refs otherrepo >"$actual" | |
704 | ) && | |
705 | test_cmp expected "$actual" | |
706 | ' | |
707 | ||
708 | test_expect_success '__git_refs - configured remote' ' | |
709 | cat >expected <<-EOF && | |
710 | HEAD | |
711 | branch-in-other | |
712 | master-in-other | |
713 | EOF | |
714 | ( | |
715 | cur= && | |
716 | __git_refs other >"$actual" | |
717 | ) && | |
718 | test_cmp expected "$actual" | |
719 | ' | |
720 | ||
721 | test_expect_success '__git_refs - configured remote - full refs' ' | |
722 | cat >expected <<-EOF && | |
e896369b | 723 | HEAD |
fb9cd420 SG |
724 | refs/heads/branch-in-other |
725 | refs/heads/master-in-other | |
726 | refs/tags/tag-in-other | |
727 | EOF | |
728 | ( | |
729 | cur=refs/ && | |
730 | __git_refs other >"$actual" | |
731 | ) && | |
732 | test_cmp expected "$actual" | |
733 | ' | |
734 | ||
5c12f642 | 735 | test_expect_success '__git_refs - configured remote - repo given on the command line' ' |
fb9cd420 SG |
736 | cat >expected <<-EOF && |
737 | HEAD | |
738 | branch-in-other | |
739 | master-in-other | |
740 | EOF | |
741 | ( | |
742 | cd thirdrepo && | |
743 | __git_dir="$ROOT/.git" && | |
744 | cur= && | |
745 | __git_refs other >"$actual" | |
746 | ) && | |
747 | test_cmp expected "$actual" | |
748 | ' | |
749 | ||
5c12f642 | 750 | test_expect_success '__git_refs - configured remote - full refs - repo given on the command line' ' |
fb9cd420 | 751 | cat >expected <<-EOF && |
e896369b | 752 | HEAD |
fb9cd420 SG |
753 | refs/heads/branch-in-other |
754 | refs/heads/master-in-other | |
755 | refs/tags/tag-in-other | |
756 | EOF | |
757 | ( | |
758 | cd thirdrepo && | |
759 | __git_dir="$ROOT/.git" && | |
760 | cur=refs/ && | |
761 | __git_refs other >"$actual" | |
762 | ) && | |
763 | test_cmp expected "$actual" | |
764 | ' | |
765 | ||
69a77596 | 766 | test_expect_success '__git_refs - configured remote - remote name matches a directory' ' |
fb9cd420 SG |
767 | cat >expected <<-EOF && |
768 | HEAD | |
769 | branch-in-other | |
770 | master-in-other | |
771 | EOF | |
772 | mkdir other && | |
773 | test_when_finished "rm -rf other" && | |
774 | ( | |
775 | cur= && | |
776 | __git_refs other >"$actual" | |
777 | ) && | |
778 | test_cmp expected "$actual" | |
779 | ' | |
780 | ||
91b7ea81 | 781 | test_expect_success '__git_refs - URL remote' ' |
fb9cd420 SG |
782 | cat >expected <<-EOF && |
783 | HEAD | |
784 | branch-in-other | |
785 | master-in-other | |
786 | tag-in-other | |
787 | EOF | |
788 | ( | |
789 | cur= && | |
790 | __git_refs "file://$ROOT/otherrepo/.git" >"$actual" | |
791 | ) && | |
792 | test_cmp expected "$actual" | |
793 | ' | |
794 | ||
795 | test_expect_success '__git_refs - URL remote - full refs' ' | |
796 | cat >expected <<-EOF && | |
e896369b | 797 | HEAD |
fb9cd420 SG |
798 | refs/heads/branch-in-other |
799 | refs/heads/master-in-other | |
800 | refs/tags/tag-in-other | |
801 | EOF | |
802 | ( | |
803 | cur=refs/ && | |
804 | __git_refs "file://$ROOT/otherrepo/.git" >"$actual" | |
805 | ) && | |
806 | test_cmp expected "$actual" | |
807 | ' | |
808 | ||
91b7ea81 | 809 | test_expect_success '__git_refs - non-existing remote' ' |
fb9cd420 SG |
810 | ( |
811 | cur= && | |
812 | __git_refs non-existing >"$actual" | |
813 | ) && | |
814 | test_must_be_empty "$actual" | |
815 | ' | |
816 | ||
817 | test_expect_success '__git_refs - non-existing remote - full refs' ' | |
818 | ( | |
819 | cur=refs/ && | |
820 | __git_refs non-existing >"$actual" | |
821 | ) && | |
822 | test_must_be_empty "$actual" | |
823 | ' | |
824 | ||
91b7ea81 | 825 | test_expect_success '__git_refs - non-existing URL remote' ' |
fb9cd420 SG |
826 | ( |
827 | cur= && | |
828 | __git_refs "file://$ROOT/non-existing" >"$actual" | |
829 | ) && | |
830 | test_must_be_empty "$actual" | |
831 | ' | |
832 | ||
833 | test_expect_success '__git_refs - non-existing URL remote - full refs' ' | |
834 | ( | |
835 | cur=refs/ && | |
836 | __git_refs "file://$ROOT/non-existing" >"$actual" | |
837 | ) && | |
838 | test_must_be_empty "$actual" | |
839 | ' | |
840 | ||
62a1b732 | 841 | test_expect_success '__git_refs - not in a git repository' ' |
fb9cd420 SG |
842 | ( |
843 | GIT_CEILING_DIRECTORIES="$ROOT" && | |
844 | export GIT_CEILING_DIRECTORIES && | |
845 | cd subdir && | |
846 | cur= && | |
847 | __git_refs >"$actual" | |
848 | ) && | |
849 | test_must_be_empty "$actual" | |
850 | ' | |
851 | ||
852 | test_expect_success '__git_refs - unique remote branches for git checkout DWIMery' ' | |
853 | cat >expected <<-EOF && | |
854 | HEAD | |
855 | master | |
856 | matching-branch | |
857 | other/ambiguous | |
858 | other/branch-in-other | |
859 | other/master-in-other | |
860 | remote/ambiguous | |
861 | remote/branch-in-remote | |
862 | matching-tag | |
863 | branch-in-other | |
864 | branch-in-remote | |
865 | master-in-other | |
866 | EOF | |
867 | for remote_ref in refs/remotes/other/ambiguous \ | |
868 | refs/remotes/remote/ambiguous \ | |
869 | refs/remotes/remote/branch-in-remote | |
870 | do | |
871 | git update-ref $remote_ref master && | |
872 | test_when_finished "git update-ref -d $remote_ref" | |
873 | done && | |
874 | ( | |
875 | cur= && | |
876 | __git_refs "" 1 >"$actual" | |
877 | ) && | |
878 | test_cmp expected "$actual" | |
879 | ' | |
880 | ||
2ea328a1 SG |
881 | test_expect_success '__git_refs - after --opt=' ' |
882 | cat >expected <<-EOF && | |
883 | HEAD | |
884 | master | |
885 | matching-branch | |
886 | other/branch-in-other | |
887 | other/master-in-other | |
888 | matching-tag | |
889 | EOF | |
890 | ( | |
891 | cur="--opt=" && | |
892 | __git_refs "" "" "" "" >"$actual" | |
893 | ) && | |
894 | test_cmp expected "$actual" | |
895 | ' | |
896 | ||
897 | test_expect_success '__git_refs - after --opt= - full refs' ' | |
898 | cat >expected <<-EOF && | |
899 | refs/heads/master | |
900 | refs/heads/matching-branch | |
901 | refs/remotes/other/branch-in-other | |
902 | refs/remotes/other/master-in-other | |
903 | refs/tags/matching-tag | |
904 | EOF | |
905 | ( | |
906 | cur="--opt=refs/" && | |
907 | __git_refs "" "" "" refs/ >"$actual" | |
908 | ) && | |
909 | test_cmp expected "$actual" | |
910 | ' | |
911 | ||
aed38813 SG |
912 | test_expect_success '__git refs - exluding refs' ' |
913 | cat >expected <<-EOF && | |
914 | ^HEAD | |
915 | ^master | |
916 | ^matching-branch | |
917 | ^other/branch-in-other | |
918 | ^other/master-in-other | |
919 | ^matching-tag | |
920 | EOF | |
921 | ( | |
922 | cur=^ && | |
923 | __git_refs >"$actual" | |
924 | ) && | |
925 | test_cmp expected "$actual" | |
926 | ' | |
927 | ||
928 | test_expect_success '__git refs - exluding full refs' ' | |
929 | cat >expected <<-EOF && | |
930 | ^refs/heads/master | |
931 | ^refs/heads/matching-branch | |
932 | ^refs/remotes/other/branch-in-other | |
933 | ^refs/remotes/other/master-in-other | |
934 | ^refs/tags/matching-tag | |
935 | EOF | |
936 | ( | |
937 | cur=^refs/ && | |
938 | __git_refs >"$actual" | |
939 | ) && | |
940 | test_cmp expected "$actual" | |
941 | ' | |
942 | ||
e896369b SG |
943 | test_expect_success 'setup for filtering matching refs' ' |
944 | git branch matching/branch && | |
945 | git tag matching/tag && | |
946 | git -C otherrepo branch matching/branch-in-other && | |
947 | git fetch --no-tags other && | |
948 | rm -f .git/FETCH_HEAD | |
949 | ' | |
950 | ||
4dc8b1c1 | 951 | test_expect_success '__git_refs - do not filter refs unless told so' ' |
e896369b SG |
952 | cat >expected <<-EOF && |
953 | HEAD | |
954 | master | |
955 | matching-branch | |
956 | matching/branch | |
957 | other/branch-in-other | |
958 | other/master-in-other | |
959 | other/matching/branch-in-other | |
960 | matching-tag | |
961 | matching/tag | |
962 | EOF | |
963 | ( | |
964 | cur=master && | |
965 | __git_refs >"$actual" | |
966 | ) && | |
967 | test_cmp expected "$actual" | |
968 | ' | |
969 | ||
970 | test_expect_success '__git_refs - only matching refs' ' | |
971 | cat >expected <<-EOF && | |
972 | matching-branch | |
973 | matching/branch | |
974 | matching-tag | |
975 | matching/tag | |
976 | EOF | |
977 | ( | |
978 | cur=mat && | |
979 | __git_refs "" "" "" "$cur" >"$actual" | |
980 | ) && | |
981 | test_cmp expected "$actual" | |
982 | ' | |
983 | ||
984 | test_expect_success '__git_refs - only matching refs - full refs' ' | |
985 | cat >expected <<-EOF && | |
986 | refs/heads/matching-branch | |
987 | refs/heads/matching/branch | |
988 | EOF | |
989 | ( | |
990 | cur=refs/heads/mat && | |
991 | __git_refs "" "" "" "$cur" >"$actual" | |
992 | ) && | |
993 | test_cmp expected "$actual" | |
994 | ' | |
995 | ||
996 | test_expect_success '__git_refs - only matching refs - remote on local file system' ' | |
997 | cat >expected <<-EOF && | |
998 | master-in-other | |
999 | matching/branch-in-other | |
1000 | EOF | |
1001 | ( | |
1002 | cur=ma && | |
1003 | __git_refs otherrepo "" "" "$cur" >"$actual" | |
1004 | ) && | |
1005 | test_cmp expected "$actual" | |
1006 | ' | |
1007 | ||
1008 | test_expect_success '__git_refs - only matching refs - configured remote' ' | |
1009 | cat >expected <<-EOF && | |
1010 | master-in-other | |
1011 | matching/branch-in-other | |
1012 | EOF | |
1013 | ( | |
1014 | cur=ma && | |
1015 | __git_refs other "" "" "$cur" >"$actual" | |
1016 | ) && | |
1017 | test_cmp expected "$actual" | |
1018 | ' | |
1019 | ||
1020 | test_expect_success '__git_refs - only matching refs - remote - full refs' ' | |
1021 | cat >expected <<-EOF && | |
1022 | refs/heads/master-in-other | |
1023 | refs/heads/matching/branch-in-other | |
1024 | EOF | |
1025 | ( | |
1026 | cur=refs/heads/ma && | |
1027 | __git_refs other "" "" "$cur" >"$actual" | |
1028 | ) && | |
1029 | test_cmp expected "$actual" | |
1030 | ' | |
1031 | ||
1032 | test_expect_success '__git_refs - only matching refs - checkout DWIMery' ' | |
1033 | cat >expected <<-EOF && | |
1034 | matching-branch | |
1035 | matching/branch | |
1036 | matching-tag | |
1037 | matching/tag | |
1038 | matching/branch-in-other | |
1039 | EOF | |
1040 | for remote_ref in refs/remotes/other/ambiguous \ | |
1041 | refs/remotes/remote/ambiguous \ | |
1042 | refs/remotes/remote/branch-in-remote | |
1043 | do | |
1044 | git update-ref $remote_ref master && | |
1045 | test_when_finished "git update-ref -d $remote_ref" | |
1046 | done && | |
1047 | ( | |
1048 | cur=mat && | |
1049 | __git_refs "" 1 "" "$cur" >"$actual" | |
1050 | ) && | |
1051 | test_cmp expected "$actual" | |
1052 | ' | |
1053 | ||
1054 | test_expect_success 'teardown after filtering matching refs' ' | |
1055 | git branch -d matching/branch && | |
1056 | git tag -d matching/tag && | |
1057 | git update-ref -d refs/remotes/other/matching/branch-in-other && | |
1058 | git -C otherrepo branch -D matching/branch-in-other | |
1059 | ' | |
1060 | ||
8164360f | 1061 | test_expect_success PREPARE_FOR_MAIN_BRANCH '__git_refs - for-each-ref format specifiers in prefix' ' |
fef56eb0 SG |
1062 | cat >expected <<-EOF && |
1063 | evil-%%-%42-%(refname)..master | |
1064 | EOF | |
1065 | ( | |
8164360f JS |
1066 | cur="evil-%%-%42-%(refname)..mai" && |
1067 | __git_refs "" "" "evil-%%-%42-%(refname).." mai >"$actual" | |
fef56eb0 SG |
1068 | ) && |
1069 | test_cmp expected "$actual" | |
1070 | ' | |
1071 | ||
15b4a163 SG |
1072 | test_expect_success '__git_complete_refs - simple' ' |
1073 | sed -e "s/Z$//" >expected <<-EOF && | |
1074 | HEAD Z | |
1075 | master Z | |
1076 | matching-branch Z | |
1077 | other/branch-in-other Z | |
1078 | other/master-in-other Z | |
1079 | matching-tag Z | |
1080 | EOF | |
1081 | ( | |
1082 | cur= && | |
1083 | __git_complete_refs && | |
1084 | print_comp | |
1085 | ) && | |
1086 | test_cmp expected out | |
1087 | ' | |
1088 | ||
1089 | test_expect_success '__git_complete_refs - matching' ' | |
1090 | sed -e "s/Z$//" >expected <<-EOF && | |
1091 | matching-branch Z | |
1092 | matching-tag Z | |
1093 | EOF | |
1094 | ( | |
1095 | cur=mat && | |
1096 | __git_complete_refs && | |
1097 | print_comp | |
1098 | ) && | |
1099 | test_cmp expected out | |
1100 | ' | |
1101 | ||
1102 | test_expect_success '__git_complete_refs - remote' ' | |
1103 | sed -e "s/Z$//" >expected <<-EOF && | |
1104 | HEAD Z | |
1105 | branch-in-other Z | |
1106 | master-in-other Z | |
1107 | EOF | |
1108 | ( | |
cff4243d | 1109 | cur= && |
15b4a163 SG |
1110 | __git_complete_refs --remote=other && |
1111 | print_comp | |
1112 | ) && | |
1113 | test_cmp expected out | |
1114 | ' | |
1115 | ||
1116 | test_expect_success '__git_complete_refs - track' ' | |
1117 | sed -e "s/Z$//" >expected <<-EOF && | |
1118 | HEAD Z | |
1119 | master Z | |
1120 | matching-branch Z | |
1121 | other/branch-in-other Z | |
1122 | other/master-in-other Z | |
1123 | matching-tag Z | |
1124 | branch-in-other Z | |
1125 | master-in-other Z | |
1126 | EOF | |
1127 | ( | |
cff4243d | 1128 | cur= && |
15b4a163 SG |
1129 | __git_complete_refs --track && |
1130 | print_comp | |
1131 | ) && | |
1132 | test_cmp expected out | |
1133 | ' | |
1134 | ||
1135 | test_expect_success '__git_complete_refs - current word' ' | |
1136 | sed -e "s/Z$//" >expected <<-EOF && | |
1137 | matching-branch Z | |
1138 | matching-tag Z | |
1139 | EOF | |
1140 | ( | |
1141 | cur="--option=mat" && | |
1142 | __git_complete_refs --cur="${cur#*=}" && | |
1143 | print_comp | |
1144 | ) && | |
1145 | test_cmp expected out | |
1146 | ' | |
1147 | ||
1148 | test_expect_success '__git_complete_refs - prefix' ' | |
1149 | sed -e "s/Z$//" >expected <<-EOF && | |
1150 | v1.0..matching-branch Z | |
1151 | v1.0..matching-tag Z | |
1152 | EOF | |
1153 | ( | |
1154 | cur=v1.0..mat && | |
1155 | __git_complete_refs --pfx=v1.0.. --cur=mat && | |
1156 | print_comp | |
1157 | ) && | |
1158 | test_cmp expected out | |
1159 | ' | |
1160 | ||
1161 | test_expect_success '__git_complete_refs - suffix' ' | |
1162 | cat >expected <<-EOF && | |
1163 | HEAD. | |
1164 | master. | |
1165 | matching-branch. | |
1166 | other/branch-in-other. | |
1167 | other/master-in-other. | |
1168 | matching-tag. | |
1169 | EOF | |
1170 | ( | |
1171 | cur= && | |
1172 | __git_complete_refs --sfx=. && | |
1173 | print_comp | |
1174 | ) && | |
1175 | test_cmp expected out | |
1176 | ' | |
1177 | ||
aa0644f7 SG |
1178 | test_expect_success '__git_complete_fetch_refspecs - simple' ' |
1179 | sed -e "s/Z$//" >expected <<-EOF && | |
1180 | HEAD:HEAD Z | |
1181 | branch-in-other:branch-in-other Z | |
1182 | master-in-other:master-in-other Z | |
1183 | EOF | |
1184 | ( | |
1185 | cur= && | |
1186 | __git_complete_fetch_refspecs other && | |
1187 | print_comp | |
1188 | ) && | |
1189 | test_cmp expected out | |
1190 | ' | |
1191 | ||
1192 | test_expect_success '__git_complete_fetch_refspecs - matching' ' | |
1193 | sed -e "s/Z$//" >expected <<-EOF && | |
1194 | branch-in-other:branch-in-other Z | |
1195 | EOF | |
1196 | ( | |
1197 | cur=br && | |
1198 | __git_complete_fetch_refspecs other "" br && | |
1199 | print_comp | |
1200 | ) && | |
1201 | test_cmp expected out | |
1202 | ' | |
1203 | ||
1204 | test_expect_success '__git_complete_fetch_refspecs - prefix' ' | |
1205 | sed -e "s/Z$//" >expected <<-EOF && | |
1206 | +HEAD:HEAD Z | |
1207 | +branch-in-other:branch-in-other Z | |
1208 | +master-in-other:master-in-other Z | |
1209 | EOF | |
1210 | ( | |
1211 | cur="+" && | |
1212 | __git_complete_fetch_refspecs other "+" "" && | |
1213 | print_comp | |
1214 | ) && | |
1215 | test_cmp expected out | |
1216 | ' | |
1217 | ||
1218 | test_expect_success '__git_complete_fetch_refspecs - fully qualified' ' | |
1219 | sed -e "s/Z$//" >expected <<-EOF && | |
1220 | refs/heads/branch-in-other:refs/heads/branch-in-other Z | |
1221 | refs/heads/master-in-other:refs/heads/master-in-other Z | |
1222 | refs/tags/tag-in-other:refs/tags/tag-in-other Z | |
1223 | EOF | |
1224 | ( | |
1225 | cur=refs/ && | |
1226 | __git_complete_fetch_refspecs other "" refs/ && | |
1227 | print_comp | |
1228 | ) && | |
1229 | test_cmp expected out | |
1230 | ' | |
1231 | ||
1232 | test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' ' | |
1233 | sed -e "s/Z$//" >expected <<-EOF && | |
1234 | +refs/heads/branch-in-other:refs/heads/branch-in-other Z | |
1235 | +refs/heads/master-in-other:refs/heads/master-in-other Z | |
1236 | +refs/tags/tag-in-other:refs/tags/tag-in-other Z | |
1237 | EOF | |
1238 | ( | |
1239 | cur=+refs/ && | |
1240 | __git_complete_fetch_refspecs other + refs/ && | |
1241 | print_comp | |
1242 | ) && | |
1243 | test_cmp expected out | |
1244 | ' | |
1245 | ||
68d97c7f | 1246 | test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' ' |
fab466f9 JK |
1247 | test_completion "git switch " <<-\EOF |
1248 | branch-in-other Z | |
1249 | master Z | |
1250 | master-in-other Z | |
1251 | matching-branch Z | |
1252 | EOF | |
1253 | ' | |
1254 | ||
1255 | test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' ' | |
1256 | test_completion "git checkout " <<-\EOF | |
1257 | HEAD Z | |
1258 | branch-in-other Z | |
1259 | master Z | |
1260 | master-in-other Z | |
1261 | matching-branch Z | |
1262 | matching-tag Z | |
1263 | other/branch-in-other Z | |
1264 | other/master-in-other Z | |
1265 | EOF | |
1266 | ' | |
1267 | ||
ab58e90f JK |
1268 | test_expect_success 'git switch - with --no-guess, complete only local branches' ' |
1269 | test_completion "git switch --no-guess " <<-\EOF | |
1270 | master Z | |
1271 | matching-branch Z | |
1272 | EOF | |
1273 | ' | |
1274 | ||
1275 | test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete only local branches' ' | |
1276 | GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch " <<-\EOF | |
1277 | master Z | |
1278 | matching-branch Z | |
1279 | EOF | |
1280 | ' | |
1281 | ||
68d97c7f | 1282 | test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete local branches and unique remote names for DWIM logic' ' |
ab58e90f JK |
1283 | GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch --guess " <<-\EOF |
1284 | branch-in-other Z | |
1285 | master Z | |
1286 | master-in-other Z | |
1287 | matching-branch Z | |
1288 | EOF | |
1289 | ' | |
1290 | ||
68d97c7f | 1291 | test_expect_success 'git switch - a later --guess overrides previous --no-guess, complete local and remote unique branches for DWIM' ' |
ab58e90f JK |
1292 | test_completion "git switch --no-guess --guess " <<-\EOF |
1293 | branch-in-other Z | |
1294 | master Z | |
1295 | master-in-other Z | |
1296 | matching-branch Z | |
1297 | EOF | |
1298 | ' | |
1299 | ||
4e79adf4 | 1300 | test_expect_success 'git switch - a later --no-guess overrides previous --guess, complete only local branches' ' |
ab58e90f JK |
1301 | test_completion "git switch --guess --no-guess " <<-\EOF |
1302 | master Z | |
1303 | matching-branch Z | |
1304 | EOF | |
1305 | ' | |
1306 | ||
1307 | test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS=1 only completes refs' ' | |
1308 | GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout " <<-\EOF | |
1309 | HEAD Z | |
1310 | master Z | |
1311 | matching-branch Z | |
1312 | matching-tag Z | |
1313 | other/branch-in-other Z | |
1314 | other/master-in-other Z | |
1315 | EOF | |
1316 | ' | |
1317 | ||
4e79adf4 | 1318 | test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS=1, complete refs and unique remote branches for DWIM' ' |
ab58e90f JK |
1319 | GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout --guess " <<-\EOF |
1320 | HEAD Z | |
1321 | branch-in-other Z | |
1322 | master Z | |
1323 | master-in-other Z | |
1324 | matching-branch Z | |
1325 | matching-tag Z | |
1326 | other/branch-in-other Z | |
1327 | other/master-in-other Z | |
1328 | EOF | |
1329 | ' | |
1330 | ||
1331 | test_expect_success 'git checkout - with --no-guess, only completes refs' ' | |
1332 | test_completion "git checkout --no-guess " <<-\EOF | |
1333 | HEAD Z | |
1334 | master Z | |
1335 | matching-branch Z | |
1336 | matching-tag Z | |
1337 | other/branch-in-other Z | |
1338 | other/master-in-other Z | |
1339 | EOF | |
1340 | ' | |
1341 | ||
4e79adf4 | 1342 | test_expect_success 'git checkout - a later --guess overrides previous --no-guess, complete refs and unique remote branches for DWIM' ' |
ab58e90f JK |
1343 | test_completion "git checkout --no-guess --guess " <<-\EOF |
1344 | HEAD Z | |
1345 | branch-in-other Z | |
1346 | master Z | |
1347 | master-in-other Z | |
1348 | matching-branch Z | |
1349 | matching-tag Z | |
1350 | other/branch-in-other Z | |
1351 | other/master-in-other Z | |
1352 | EOF | |
1353 | ' | |
1354 | ||
1355 | test_expect_success 'git checkout - a later --no-guess overrides previous --guess, complete only refs' ' | |
1356 | test_completion "git checkout --guess --no-guess " <<-\EOF | |
1357 | HEAD Z | |
1358 | master Z | |
1359 | matching-branch Z | |
1360 | matching-tag Z | |
1361 | other/branch-in-other Z | |
1362 | other/master-in-other Z | |
1363 | EOF | |
1364 | ' | |
1365 | ||
64f1f58f DL |
1366 | test_expect_success 'git checkout - with checkout.guess = false, only completes refs' ' |
1367 | test_config checkout.guess false && | |
1368 | test_completion "git checkout " <<-\EOF | |
1369 | HEAD Z | |
1370 | master Z | |
1371 | matching-branch Z | |
1372 | matching-tag Z | |
1373 | other/branch-in-other Z | |
1374 | other/master-in-other Z | |
1375 | EOF | |
1376 | ' | |
1377 | ||
1378 | test_expect_success 'git checkout - with checkout.guess = true, completes refs and unique remote branches for DWIM' ' | |
1379 | test_config checkout.guess true && | |
1380 | test_completion "git checkout " <<-\EOF | |
1381 | HEAD Z | |
1382 | branch-in-other Z | |
1383 | master Z | |
1384 | master-in-other Z | |
1385 | matching-branch Z | |
1386 | matching-tag Z | |
1387 | other/branch-in-other Z | |
1388 | other/master-in-other Z | |
1389 | EOF | |
1390 | ' | |
1391 | ||
1392 | test_expect_success 'git checkout - a later --guess overrides previous checkout.guess = false, complete refs and unique remote branches for DWIM' ' | |
1393 | test_config checkout.guess false && | |
1394 | test_completion "git checkout --guess " <<-\EOF | |
1395 | HEAD Z | |
1396 | branch-in-other Z | |
1397 | master Z | |
1398 | master-in-other Z | |
1399 | matching-branch Z | |
1400 | matching-tag Z | |
1401 | other/branch-in-other Z | |
1402 | other/master-in-other Z | |
1403 | EOF | |
1404 | ' | |
1405 | ||
1406 | test_expect_success 'git checkout - a later --no-guess overrides previous checkout.guess = true, complete only refs' ' | |
1407 | test_config checkout.guess true && | |
1408 | test_completion "git checkout --no-guess " <<-\EOF | |
1409 | HEAD Z | |
1410 | master Z | |
1411 | matching-branch Z | |
1412 | matching-tag Z | |
1413 | other/branch-in-other Z | |
1414 | other/master-in-other Z | |
1415 | EOF | |
1416 | ' | |
1417 | ||
e69fb0a1 JK |
1418 | test_expect_success 'git switch - with --detach, complete all references' ' |
1419 | test_completion "git switch --detach " <<-\EOF | |
1420 | HEAD Z | |
1421 | master Z | |
1422 | matching-branch Z | |
1423 | matching-tag Z | |
1424 | other/branch-in-other Z | |
1425 | other/master-in-other Z | |
1426 | EOF | |
1427 | ' | |
1428 | ||
6d76a5cc | 1429 | test_expect_success 'git checkout - with --detach, complete only references' ' |
e69fb0a1 JK |
1430 | test_completion "git checkout --detach " <<-\EOF |
1431 | HEAD Z | |
1432 | master Z | |
1433 | matching-branch Z | |
1434 | matching-tag Z | |
1435 | other/branch-in-other Z | |
1436 | other/master-in-other Z | |
1437 | EOF | |
1438 | ' | |
1439 | ||
1440 | test_expect_success 'git switch - with -d, complete all references' ' | |
1441 | test_completion "git switch -d " <<-\EOF | |
1442 | HEAD Z | |
1443 | master Z | |
1444 | matching-branch Z | |
1445 | matching-tag Z | |
1446 | other/branch-in-other Z | |
1447 | other/master-in-other Z | |
1448 | EOF | |
1449 | ' | |
1450 | ||
6d76a5cc | 1451 | test_expect_success 'git checkout - with -d, complete only references' ' |
e69fb0a1 JK |
1452 | test_completion "git checkout -d " <<-\EOF |
1453 | HEAD Z | |
1454 | master Z | |
1455 | matching-branch Z | |
1456 | matching-tag Z | |
1457 | other/branch-in-other Z | |
1458 | other/master-in-other Z | |
1459 | EOF | |
1460 | ' | |
1461 | ||
00e7bd2b | 1462 | test_expect_success 'git switch - with --track, complete only remote branches' ' |
c55b99c3 JK |
1463 | test_completion "git switch --track " <<-\EOF |
1464 | other/branch-in-other Z | |
1465 | other/master-in-other Z | |
1466 | EOF | |
1467 | ' | |
1468 | ||
00e7bd2b | 1469 | test_expect_success 'git checkout - with --track, complete only remote branches' ' |
c55b99c3 JK |
1470 | test_completion "git checkout --track " <<-\EOF |
1471 | other/branch-in-other Z | |
1472 | other/master-in-other Z | |
1473 | EOF | |
1474 | ' | |
1475 | ||
1476 | test_expect_success 'git switch - with --no-track, complete only local branch names' ' | |
1477 | test_completion "git switch --no-track " <<-\EOF | |
1478 | master Z | |
1479 | matching-branch Z | |
1480 | EOF | |
1481 | ' | |
1482 | ||
1483 | test_expect_success 'git checkout - with --no-track, complete only local references' ' | |
1484 | test_completion "git checkout --no-track " <<-\EOF | |
1485 | HEAD Z | |
1486 | master Z | |
1487 | matching-branch Z | |
1488 | matching-tag Z | |
1489 | other/branch-in-other Z | |
1490 | other/master-in-other Z | |
1491 | EOF | |
1492 | ' | |
1493 | ||
acb658fe | 1494 | test_expect_success 'git switch - with -c, complete all references' ' |
b07d77a2 JK |
1495 | test_completion "git switch -c new-branch " <<-\EOF |
1496 | HEAD Z | |
1497 | master Z | |
1498 | matching-branch Z | |
1499 | matching-tag Z | |
1500 | other/branch-in-other Z | |
1501 | other/master-in-other Z | |
1502 | EOF | |
1503 | ' | |
1504 | ||
acb658fe | 1505 | test_expect_success 'git switch - with -C, complete all references' ' |
b07d77a2 JK |
1506 | test_completion "git switch -C new-branch " <<-\EOF |
1507 | HEAD Z | |
1508 | master Z | |
1509 | matching-branch Z | |
1510 | matching-tag Z | |
1511 | other/branch-in-other Z | |
1512 | other/master-in-other Z | |
1513 | EOF | |
1514 | ' | |
1515 | ||
acb658fe | 1516 | test_expect_success 'git switch - with -c and --track, complete all references' ' |
b07d77a2 JK |
1517 | test_completion "git switch -c new-branch --track " <<-EOF |
1518 | HEAD Z | |
1519 | master Z | |
1520 | matching-branch Z | |
1521 | matching-tag Z | |
1522 | other/branch-in-other Z | |
1523 | other/master-in-other Z | |
1524 | EOF | |
1525 | ' | |
1526 | ||
acb658fe | 1527 | test_expect_success 'git switch - with -C and --track, complete all references' ' |
b07d77a2 JK |
1528 | test_completion "git switch -C new-branch --track " <<-EOF |
1529 | HEAD Z | |
1530 | master Z | |
1531 | matching-branch Z | |
1532 | matching-tag Z | |
1533 | other/branch-in-other Z | |
1534 | other/master-in-other Z | |
1535 | EOF | |
1536 | ' | |
1537 | ||
acb658fe | 1538 | test_expect_success 'git switch - with -c and --no-track, complete all references' ' |
b07d77a2 JK |
1539 | test_completion "git switch -c new-branch --no-track " <<-\EOF |
1540 | HEAD Z | |
1541 | master Z | |
1542 | matching-branch Z | |
1543 | matching-tag Z | |
1544 | other/branch-in-other Z | |
1545 | other/master-in-other Z | |
1546 | EOF | |
1547 | ' | |
1548 | ||
acb658fe | 1549 | test_expect_success 'git switch - with -C and --no-track, complete all references' ' |
b07d77a2 JK |
1550 | test_completion "git switch -C new-branch --no-track " <<-\EOF |
1551 | HEAD Z | |
1552 | master Z | |
1553 | matching-branch Z | |
1554 | matching-tag Z | |
1555 | other/branch-in-other Z | |
1556 | other/master-in-other Z | |
1557 | EOF | |
1558 | ' | |
1559 | ||
acb658fe | 1560 | test_expect_success 'git checkout - with -b, complete all references' ' |
b07d77a2 JK |
1561 | test_completion "git checkout -b new-branch " <<-\EOF |
1562 | HEAD Z | |
1563 | master Z | |
1564 | matching-branch Z | |
1565 | matching-tag Z | |
1566 | other/branch-in-other Z | |
1567 | other/master-in-other Z | |
1568 | EOF | |
1569 | ' | |
1570 | ||
acb658fe | 1571 | test_expect_success 'git checkout - with -B, complete all references' ' |
b07d77a2 JK |
1572 | test_completion "git checkout -B new-branch " <<-\EOF |
1573 | HEAD Z | |
1574 | master Z | |
1575 | matching-branch Z | |
1576 | matching-tag Z | |
1577 | other/branch-in-other Z | |
1578 | other/master-in-other Z | |
1579 | EOF | |
1580 | ' | |
1581 | ||
acb658fe | 1582 | test_expect_success 'git checkout - with -b and --track, complete all references' ' |
b07d77a2 JK |
1583 | test_completion "git checkout -b new-branch --track " <<-EOF |
1584 | HEAD Z | |
1585 | master Z | |
1586 | matching-branch Z | |
1587 | matching-tag Z | |
1588 | other/branch-in-other Z | |
1589 | other/master-in-other Z | |
1590 | EOF | |
1591 | ' | |
1592 | ||
acb658fe | 1593 | test_expect_success 'git checkout - with -B and --track, complete all references' ' |
b07d77a2 JK |
1594 | test_completion "git checkout -B new-branch --track " <<-EOF |
1595 | HEAD Z | |
1596 | master Z | |
1597 | matching-branch Z | |
1598 | matching-tag Z | |
1599 | other/branch-in-other Z | |
1600 | other/master-in-other Z | |
1601 | EOF | |
1602 | ' | |
1603 | ||
1604 | test_expect_success 'git checkout - with -b and --no-track, complete all references' ' | |
1605 | test_completion "git checkout -b new-branch --no-track " <<-\EOF | |
1606 | HEAD Z | |
1607 | master Z | |
1608 | matching-branch Z | |
1609 | matching-tag Z | |
1610 | other/branch-in-other Z | |
1611 | other/master-in-other Z | |
1612 | EOF | |
1613 | ' | |
1614 | ||
1615 | test_expect_success 'git checkout - with -B and --no-track, complete all references' ' | |
1616 | test_completion "git checkout -B new-branch --no-track " <<-\EOF | |
1617 | HEAD Z | |
1618 | master Z | |
1619 | matching-branch Z | |
1620 | matching-tag Z | |
1621 | other/branch-in-other Z | |
1622 | other/master-in-other Z | |
1623 | EOF | |
1624 | ' | |
1625 | ||
68d97c7f | 1626 | test_expect_success 'git switch - for -c, complete local branches and unique remote branches' ' |
7f59d604 JK |
1627 | test_completion "git switch -c " <<-\EOF |
1628 | branch-in-other Z | |
1629 | master Z | |
1630 | master-in-other Z | |
1631 | matching-branch Z | |
1632 | EOF | |
1633 | ' | |
1634 | ||
68d97c7f | 1635 | test_expect_success 'git switch - for -C, complete local branches and unique remote branches' ' |
7f59d604 JK |
1636 | test_completion "git switch -C " <<-\EOF |
1637 | branch-in-other Z | |
1638 | master Z | |
1639 | master-in-other Z | |
1640 | matching-branch Z | |
1641 | EOF | |
1642 | ' | |
1643 | ||
1644 | test_expect_success 'git switch - for -c with --no-guess, complete local branches only' ' | |
1645 | test_completion "git switch --no-guess -c " <<-\EOF | |
1646 | master Z | |
1647 | matching-branch Z | |
1648 | EOF | |
1649 | ' | |
1650 | ||
1651 | test_expect_success 'git switch - for -C with --no-guess, complete local branches only' ' | |
1652 | test_completion "git switch --no-guess -C " <<-\EOF | |
1653 | master Z | |
1654 | matching-branch Z | |
1655 | EOF | |
1656 | ' | |
1657 | ||
1658 | test_expect_success 'git switch - for -c with --no-track, complete local branches only' ' | |
1659 | test_completion "git switch --no-track -c " <<-\EOF | |
1660 | master Z | |
1661 | matching-branch Z | |
1662 | EOF | |
1663 | ' | |
1664 | ||
1665 | test_expect_success 'git switch - for -C with --no-track, complete local branches only' ' | |
1666 | test_completion "git switch --no-track -C " <<-\EOF | |
1667 | master Z | |
1668 | matching-branch Z | |
1669 | EOF | |
1670 | ' | |
1671 | ||
acb658fe | 1672 | test_expect_success 'git checkout - for -b, complete local branches and unique remote branches' ' |
7f59d604 JK |
1673 | test_completion "git checkout -b " <<-\EOF |
1674 | branch-in-other Z | |
1675 | master Z | |
1676 | master-in-other Z | |
1677 | matching-branch Z | |
1678 | EOF | |
1679 | ' | |
1680 | ||
acb658fe | 1681 | test_expect_success 'git checkout - for -B, complete local branches and unique remote branches' ' |
7f59d604 JK |
1682 | test_completion "git checkout -B " <<-\EOF |
1683 | branch-in-other Z | |
1684 | master Z | |
1685 | master-in-other Z | |
1686 | matching-branch Z | |
1687 | EOF | |
1688 | ' | |
1689 | ||
acb658fe | 1690 | test_expect_success 'git checkout - for -b with --no-guess, complete local branches only' ' |
7f59d604 JK |
1691 | test_completion "git checkout --no-guess -b " <<-\EOF |
1692 | master Z | |
1693 | matching-branch Z | |
1694 | EOF | |
1695 | ' | |
1696 | ||
acb658fe | 1697 | test_expect_success 'git checkout - for -B with --no-guess, complete local branches only' ' |
7f59d604 JK |
1698 | test_completion "git checkout --no-guess -B " <<-\EOF |
1699 | master Z | |
1700 | matching-branch Z | |
1701 | EOF | |
1702 | ' | |
1703 | ||
acb658fe | 1704 | test_expect_success 'git checkout - for -b with --no-track, complete local branches only' ' |
7f59d604 JK |
1705 | test_completion "git checkout --no-track -b " <<-\EOF |
1706 | master Z | |
1707 | matching-branch Z | |
1708 | EOF | |
1709 | ' | |
1710 | ||
acb658fe | 1711 | test_expect_success 'git checkout - for -B with --no-track, complete local branches only' ' |
7f59d604 JK |
1712 | test_completion "git checkout --no-track -B " <<-\EOF |
1713 | master Z | |
1714 | matching-branch Z | |
1715 | EOF | |
1716 | ' | |
1717 | ||
68d97c7f | 1718 | test_expect_success 'git switch - with --orphan completes local branch names and unique remote branch names' ' |
c81ca56b JK |
1719 | test_completion "git switch --orphan " <<-\EOF |
1720 | branch-in-other Z | |
1721 | master Z | |
1722 | master-in-other Z | |
1723 | matching-branch Z | |
1724 | EOF | |
1725 | ' | |
1726 | ||
91439928 | 1727 | test_expect_success 'git switch - --orphan with branch already provided completes nothing else' ' |
c81ca56b JK |
1728 | test_completion "git switch --orphan master " <<-\EOF |
1729 | ||
1730 | EOF | |
1731 | ' | |
1732 | ||
91439928 | 1733 | test_expect_success 'git checkout - with --orphan completes local branch names and unique remote branch names' ' |
c81ca56b JK |
1734 | test_completion "git checkout --orphan " <<-\EOF |
1735 | branch-in-other Z | |
1736 | master Z | |
1737 | master-in-other Z | |
1738 | matching-branch Z | |
1739 | EOF | |
1740 | ' | |
1741 | ||
91439928 | 1742 | test_expect_success 'git checkout - --orphan with branch already provided completes local refs for a start-point' ' |
c81ca56b JK |
1743 | test_completion "git checkout --orphan master " <<-\EOF |
1744 | HEAD Z | |
1745 | master Z | |
1746 | matching-branch Z | |
1747 | matching-tag Z | |
1748 | other/branch-in-other Z | |
1749 | other/master-in-other Z | |
1750 | EOF | |
1751 | ' | |
1752 | ||
fb9cd420 SG |
1753 | test_expect_success 'teardown after ref completion' ' |
1754 | git branch -d matching-branch && | |
1755 | git tag -d matching-tag && | |
1756 | git remote remove other | |
1757 | ' | |
1758 | ||
7d314073 SG |
1759 | |
1760 | test_path_completion () | |
1761 | { | |
165293af | 1762 | test $# = 2 || BUG "not 2 parameters to test_path_completion" |
7d314073 SG |
1763 | |
1764 | local cur="$1" expected="$2" | |
1765 | echo "$expected" >expected && | |
1766 | ( | |
1767 | # In the following tests calling this function we only | |
1768 | # care about how __git_complete_index_file() deals with | |
1769 | # unusual characters in path names. By requesting only | |
7a40cf15 | 1770 | # untracked files we do not have to bother adding any |
7d314073 SG |
1771 | # paths to the index in those tests. |
1772 | __git_complete_index_file --others && | |
1773 | print_comp | |
1774 | ) && | |
1775 | test_cmp expected out | |
1776 | } | |
1777 | ||
1778 | test_expect_success 'setup for path completion tests' ' | |
1779 | mkdir simple-dir \ | |
1780 | "spaces in dir" \ | |
1781 | árvíztűrő && | |
1782 | touch simple-dir/simple-file \ | |
1783 | "spaces in dir/spaces in file" \ | |
1784 | "árvíztűrő/Сайн яваарай" && | |
1785 | if test_have_prereq !MINGW && | |
1786 | mkdir BS\\dir \ | |
1787 | '$'separators\034in\035dir'' && | |
1788 | touch BS\\dir/DQ\"file \ | |
1789 | '$'separators\034in\035dir/sep\036in\037file'' | |
1790 | then | |
6ec63305 | 1791 | test_set_prereq FUNNIERNAMES |
7d314073 SG |
1792 | else |
1793 | rm -rf BS\\dir '$'separators\034in\035dir'' | |
1794 | fi | |
1795 | ' | |
1796 | ||
1797 | test_expect_success '__git_complete_index_file - simple' ' | |
1798 | test_path_completion simple simple-dir && # Bash is supposed to | |
1799 | # add the trailing /. | |
1800 | test_path_completion simple-dir/simple simple-dir/simple-file | |
1801 | ' | |
1802 | ||
1803 | test_expect_success \ | |
1804 | '__git_complete_index_file - escaped characters on cmdline' ' | |
1805 | test_path_completion spac "spaces in dir" && # Bash will turn this | |
1806 | # into "spaces\ in\ dir" | |
1807 | test_path_completion "spaces\\ i" \ | |
1808 | "spaces in dir" && | |
1809 | test_path_completion "spaces\\ in\\ dir/s" \ | |
1810 | "spaces in dir/spaces in file" && | |
1811 | test_path_completion "spaces\\ in\\ dir/spaces\\ i" \ | |
1812 | "spaces in dir/spaces in file" | |
1813 | ' | |
1814 | ||
1815 | test_expect_success \ | |
1816 | '__git_complete_index_file - quoted characters on cmdline' ' | |
1817 | # Testing with an opening but without a corresponding closing | |
1818 | # double quote is important. | |
1819 | test_path_completion \"spac "spaces in dir" && | |
1820 | test_path_completion "\"spaces i" \ | |
1821 | "spaces in dir" && | |
1822 | test_path_completion "\"spaces in dir/s" \ | |
1823 | "spaces in dir/spaces in file" && | |
1824 | test_path_completion "\"spaces in dir/spaces i" \ | |
1825 | "spaces in dir/spaces in file" | |
1826 | ' | |
1827 | ||
1828 | test_expect_success '__git_complete_index_file - UTF-8 in ls-files output' ' | |
1829 | test_path_completion á árvíztűrő && | |
1830 | test_path_completion árvíztűrő/С "árvíztűrő/Сайн яваарай" | |
1831 | ' | |
1832 | ||
6ec63305 | 1833 | test_expect_success FUNNIERNAMES \ |
7d314073 SG |
1834 | '__git_complete_index_file - C-style escapes in ls-files output' ' |
1835 | test_path_completion BS \ | |
1836 | BS\\dir && | |
1837 | test_path_completion BS\\\\d \ | |
1838 | BS\\dir && | |
1839 | test_path_completion BS\\\\dir/DQ \ | |
1840 | BS\\dir/DQ\"file && | |
1841 | test_path_completion BS\\\\dir/DQ\\\"f \ | |
1842 | BS\\dir/DQ\"file | |
1843 | ' | |
1844 | ||
6ec63305 | 1845 | test_expect_success FUNNIERNAMES \ |
7d314073 SG |
1846 | '__git_complete_index_file - \nnn-escaped characters in ls-files output' ' |
1847 | test_path_completion sep '$'separators\034in\035dir'' && | |
1848 | test_path_completion '$'separators\034i'' \ | |
1849 | '$'separators\034in\035dir'' && | |
1850 | test_path_completion '$'separators\034in\035dir/sep'' \ | |
1851 | '$'separators\034in\035dir/sep\036in\037file'' && | |
1852 | test_path_completion '$'separators\034in\035dir/sep\036i'' \ | |
1853 | '$'separators\034in\035dir/sep\036in\037file'' | |
1854 | ' | |
1855 | ||
1856 | test_expect_success FUNNYNAMES \ | |
1857 | '__git_complete_index_file - removing repeated quoted path components' ' | |
1858 | test_when_finished rm -r repeated-quoted && | |
1859 | mkdir repeated-quoted && # A directory whose name in itself | |
1860 | # would not be quoted ... | |
1861 | >repeated-quoted/0-file && | |
1862 | >repeated-quoted/1\"file && # ... but here the file makes the | |
1863 | # dirname quoted ... | |
1864 | >repeated-quoted/2-file && | |
1865 | >repeated-quoted/3\"file && # ... and here, too. | |
1866 | ||
1867 | # Still, we shold only list the directory name only once. | |
1868 | test_path_completion repeated repeated-quoted | |
1869 | ' | |
1870 | ||
1871 | test_expect_success 'teardown after path completion tests' ' | |
1872 | rm -rf simple-dir "spaces in dir" árvíztűrő \ | |
1873 | BS\\dir '$'separators\034in\035dir'' | |
1874 | ' | |
1875 | ||
2712e915 SG |
1876 | test_expect_success '__git_find_on_cmdline - single match' ' |
1877 | echo list >expect && | |
1878 | ( | |
1879 | words=(git command --opt list) && | |
1880 | cword=${#words[@]} && | |
1881 | __git_find_on_cmdline "add list remove" >actual | |
1882 | ) && | |
1883 | test_cmp expect actual | |
1884 | ' | |
1885 | ||
1886 | test_expect_success '__git_find_on_cmdline - multiple matches' ' | |
1887 | echo remove >expect && | |
1888 | ( | |
1889 | words=(git command -o --opt remove list add) && | |
1890 | cword=${#words[@]} && | |
1891 | __git_find_on_cmdline "add list remove" >actual | |
1892 | ) && | |
1893 | test_cmp expect actual | |
1894 | ' | |
1895 | ||
1896 | test_expect_success '__git_find_on_cmdline - no match' ' | |
1897 | ( | |
1898 | words=(git command --opt branch) && | |
1899 | cword=${#words[@]} && | |
1900 | __git_find_on_cmdline "add list remove" >actual | |
1901 | ) && | |
1902 | test_must_be_empty actual | |
1903 | ' | |
7d314073 | 1904 | |
367efd54 SG |
1905 | test_expect_success '__git_find_on_cmdline - single match with index' ' |
1906 | echo "3 list" >expect && | |
1907 | ( | |
1908 | words=(git command --opt list) && | |
1909 | cword=${#words[@]} && | |
1910 | __git_find_on_cmdline --show-idx "add list remove" >actual | |
1911 | ) && | |
1912 | test_cmp expect actual | |
1913 | ' | |
1914 | ||
1915 | test_expect_success '__git_find_on_cmdline - multiple matches with index' ' | |
1916 | echo "4 remove" >expect && | |
1917 | ( | |
1918 | words=(git command -o --opt remove list add) && | |
1919 | cword=${#words[@]} && | |
1920 | __git_find_on_cmdline --show-idx "add list remove" >actual | |
1921 | ) && | |
1922 | test_cmp expect actual | |
1923 | ' | |
1924 | ||
1925 | test_expect_success '__git_find_on_cmdline - no match with index' ' | |
1926 | ( | |
1927 | words=(git command --opt branch) && | |
1928 | cword=${#words[@]} && | |
1929 | __git_find_on_cmdline --show-idx "add list remove" >actual | |
1930 | ) && | |
1931 | test_must_be_empty actual | |
1932 | ' | |
7d314073 | 1933 | |
12bdc880 SG |
1934 | test_expect_success '__git_get_config_variables' ' |
1935 | cat >expect <<-EOF && | |
1936 | name-1 | |
1937 | name-2 | |
1938 | EOF | |
1939 | test_config interesting.name-1 good && | |
1940 | test_config interesting.name-2 good && | |
1941 | test_config subsection.interesting.name-3 bad && | |
1942 | __git_get_config_variables interesting >actual && | |
1943 | test_cmp expect actual | |
1944 | ' | |
1945 | ||
e8f9e428 SG |
1946 | test_expect_success '__git_pretty_aliases' ' |
1947 | cat >expect <<-EOF && | |
1948 | author | |
1949 | hash | |
1950 | EOF | |
1951 | test_config pretty.author "%an %ae" && | |
1952 | test_config pretty.hash %H && | |
1953 | __git_pretty_aliases >actual && | |
1954 | test_cmp expect actual | |
1955 | ' | |
1956 | ||
5c293a6b | 1957 | test_expect_success 'basic' ' |
cdbff7d6 | 1958 | run_completion "git " && |
5c293a6b FC |
1959 | # built-in |
1960 | grep -q "^add \$" out && | |
1961 | # script | |
483e8611 | 1962 | grep -q "^rebase \$" out && |
5c293a6b FC |
1963 | # plumbing |
1964 | ! grep -q "^ls-files \$" out && | |
1965 | ||
483e8611 EN |
1966 | run_completion "git r" && |
1967 | ! grep -q -v "^r" out | |
5c293a6b FC |
1968 | ' |
1969 | ||
1970 | test_expect_success 'double dash "git" itself' ' | |
2fbaf813 | 1971 | test_completion "git --" <<-\EOF |
5c293a6b FC |
1972 | --paginate Z |
1973 | --no-pager Z | |
1974 | --git-dir= | |
1975 | --bare Z | |
1976 | --version Z | |
1977 | --exec-path Z | |
3ffcd086 | 1978 | --exec-path= |
5c293a6b | 1979 | --html-path Z |
66fb37d0 | 1980 | --man-path Z |
69ef3c02 | 1981 | --info-path Z |
5c293a6b FC |
1982 | --work-tree= |
1983 | --namespace= | |
69ef3c02 | 1984 | --no-replace-objects Z |
5c293a6b FC |
1985 | --help Z |
1986 | EOF | |
5c293a6b FC |
1987 | ' |
1988 | ||
1989 | test_expect_success 'double dash "git checkout"' ' | |
2fbaf813 | 1990 | test_completion "git checkout --" <<-\EOF |
5c293a6b | 1991 | --quiet Z |
77afafb2 NTND |
1992 | --detach Z |
1993 | --track Z | |
1994 | --orphan=Z | |
5c293a6b FC |
1995 | --ours Z |
1996 | --theirs Z | |
5c293a6b | 1997 | --merge Z |
77afafb2 | 1998 | --conflict=Z |
5c293a6b | 1999 | --patch Z |
6357d9d0 | 2000 | --ignore-skip-worktree-bits Z |
77afafb2 | 2001 | --ignore-other-worktrees Z |
6357d9d0 | 2002 | --recurse-submodules Z |
77afafb2 | 2003 | --progress Z |
be4908f1 NTND |
2004 | --guess Z |
2005 | --no-guess Z | |
b221b5ab | 2006 | --no-... Z |
091e04bc | 2007 | --overlay Z |
a9aecc7a AM |
2008 | --pathspec-file-nul Z |
2009 | --pathspec-from-file=Z | |
5c293a6b | 2010 | EOF |
5c293a6b FC |
2011 | ' |
2012 | ||
69ef3c02 FC |
2013 | test_expect_success 'general options' ' |
2014 | test_completion "git --ver" "--version " && | |
2015 | test_completion "git --hel" "--help " && | |
2fbaf813 | 2016 | test_completion "git --exe" <<-\EOF && |
3ffcd086 JN |
2017 | --exec-path Z |
2018 | --exec-path= | |
2019 | EOF | |
69ef3c02 FC |
2020 | test_completion "git --htm" "--html-path " && |
2021 | test_completion "git --pag" "--paginate " && | |
2022 | test_completion "git --no-p" "--no-pager " && | |
2023 | test_completion "git --git" "--git-dir=" && | |
2024 | test_completion "git --wor" "--work-tree=" && | |
2025 | test_completion "git --nam" "--namespace=" && | |
2026 | test_completion "git --bar" "--bare " && | |
2027 | test_completion "git --inf" "--info-path " && | |
2028 | test_completion "git --no-r" "--no-replace-objects " | |
2029 | ' | |
911d5da6 SG |
2030 | |
2031 | test_expect_success 'general options plus command' ' | |
2032 | test_completion "git --version check" "checkout " && | |
2033 | test_completion "git --paginate check" "checkout " && | |
2034 | test_completion "git --git-dir=foo check" "checkout " && | |
2035 | test_completion "git --bare check" "checkout " && | |
911d5da6 SG |
2036 | test_completion "git --exec-path=foo check" "checkout " && |
2037 | test_completion "git --html-path check" "checkout " && | |
2038 | test_completion "git --no-pager check" "checkout " && | |
2039 | test_completion "git --work-tree=foo check" "checkout " && | |
2040 | test_completion "git --namespace=foo check" "checkout " && | |
2041 | test_completion "git --paginate check" "checkout " && | |
2042 | test_completion "git --info-path check" "checkout " && | |
336d694c SG |
2043 | test_completion "git --no-replace-objects check" "checkout " && |
2044 | test_completion "git --git-dir some/path check" "checkout " && | |
2045 | test_completion "git -c conf.var=value check" "checkout " && | |
2046 | test_completion "git -C some/path check" "checkout " && | |
2047 | test_completion "git --work-tree some/path check" "checkout " && | |
2048 | test_completion "git --namespace name/space check" "checkout " | |
911d5da6 SG |
2049 | ' |
2050 | ||
50478223 JH |
2051 | test_expect_success 'git --help completion' ' |
2052 | test_completion "git --help ad" "add " && | |
2053 | test_completion "git --help core" "core-tutorial " | |
2054 | ' | |
2055 | ||
057ab54b | 2056 | test_expect_success 'completion.commands removes multiple commands' ' |
402e3e15 TZ |
2057 | test_config completion.commands "-cherry -mergetool" && |
2058 | git --list-cmds=list-mainporcelain,list-complete,config >out && | |
2059 | ! grep -E "^(cherry|mergetool)$" out | |
2060 | ' | |
2061 | ||
fb9cd420 | 2062 | test_expect_success 'setup for integration tests' ' |
49ba92b4 JK |
2063 | echo content >file1 && |
2064 | echo more >file2 && | |
e5edbef4 | 2065 | git add file1 file2 && |
49ba92b4 JK |
2066 | git commit -m one && |
2067 | git branch mybranch && | |
2068 | git tag mytag | |
2069 | ' | |
2070 | ||
2071 | test_expect_success 'checkout completes ref names' ' | |
2fbaf813 | 2072 | test_completion "git checkout m" <<-\EOF |
43ea0812 FC |
2073 | master Z |
2074 | mybranch Z | |
2075 | mytag Z | |
49ba92b4 JK |
2076 | EOF |
2077 | ' | |
2078 | ||
80ac0744 SG |
2079 | test_expect_success 'git -C <path> checkout uses the right repo' ' |
2080 | test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF | |
2081 | branch-in-other Z | |
2082 | EOF | |
2083 | ' | |
2084 | ||
49ba92b4 | 2085 | test_expect_success 'show completes all refs' ' |
2fbaf813 | 2086 | test_completion "git show m" <<-\EOF |
43ea0812 FC |
2087 | master Z |
2088 | mybranch Z | |
2089 | mytag Z | |
49ba92b4 JK |
2090 | EOF |
2091 | ' | |
2092 | ||
2093 | test_expect_success '<ref>: completes paths' ' | |
2fbaf813 | 2094 | test_completion "git show mytag:f" <<-\EOF |
6d54f528 CY |
2095 | file1Z |
2096 | file2Z | |
49ba92b4 JK |
2097 | EOF |
2098 | ' | |
2099 | ||
bafed0df JK |
2100 | test_expect_success 'complete tree filename with spaces' ' |
2101 | echo content >"name with spaces" && | |
e5edbef4 | 2102 | git add "name with spaces" && |
bafed0df | 2103 | git commit -m spaces && |
2fbaf813 | 2104 | test_completion "git show HEAD:nam" <<-\EOF |
6d54f528 | 2105 | name with spacesZ |
bafed0df JK |
2106 | EOF |
2107 | ' | |
2108 | ||
7d13e0a3 | 2109 | test_expect_success 'complete tree filename with metacharacters' ' |
bafed0df | 2110 | echo content >"name with \${meta}" && |
e5edbef4 | 2111 | git add "name with \${meta}" && |
bafed0df | 2112 | git commit -m meta && |
2fbaf813 | 2113 | test_completion "git show HEAD:nam" <<-\EOF |
6d54f528 CY |
2114 | name with ${meta}Z |
2115 | name with spacesZ | |
bafed0df JK |
2116 | EOF |
2117 | ' | |
2118 | ||
0365b9ec | 2119 | test_expect_success PERL 'send-email' ' |
bf8e65b3 DL |
2120 | test_completion "git send-email --cov" <<-\EOF && |
2121 | --cover-from-description=Z | |
2122 | --cover-letter Z | |
2123 | EOF | |
2f65494d FC |
2124 | test_completion "git send-email ma" "master " |
2125 | ' | |
2126 | ||
ddf07bdd FC |
2127 | test_expect_success 'complete files' ' |
2128 | git init tmp && cd tmp && | |
2129 | test_when_finished "cd .. && rm -rf tmp" && | |
2130 | ||
2131 | echo "expected" > .gitignore && | |
2132 | echo "out" >> .gitignore && | |
9703797c | 2133 | echo "out_sorted" >> .gitignore && |
ddf07bdd FC |
2134 | |
2135 | git add .gitignore && | |
2136 | test_completion "git commit " ".gitignore" && | |
2137 | ||
2138 | git commit -m ignore && | |
2139 | ||
2140 | touch new && | |
2141 | test_completion "git add " "new" && | |
2142 | ||
2143 | git add new && | |
2144 | git commit -a -m new && | |
2145 | test_completion "git add " "" && | |
2146 | ||
2147 | git mv new modified && | |
2148 | echo modify > modified && | |
2149 | test_completion "git add " "modified" && | |
2150 | ||
c0af173a EN |
2151 | mkdir -p some/deep && |
2152 | touch some/deep/path && | |
2153 | test_completion "git add some/" "some/deep" && | |
2154 | git clean -f some && | |
2155 | ||
ddf07bdd FC |
2156 | touch untracked && |
2157 | ||
2158 | : TODO .gitignore should not be here && | |
2159 | test_completion "git rm " <<-\EOF && | |
2160 | .gitignore | |
2161 | modified | |
2162 | EOF | |
2163 | ||
2164 | test_completion "git clean " "untracked" && | |
2165 | ||
2166 | : TODO .gitignore should not be here && | |
2167 | test_completion "git mv " <<-\EOF && | |
2168 | .gitignore | |
2169 | modified | |
2170 | EOF | |
2171 | ||
2172 | mkdir dir && | |
2173 | touch dir/file-in-dir && | |
2174 | git add dir/file-in-dir && | |
2175 | git commit -m dir && | |
2176 | ||
2177 | mkdir untracked-dir && | |
2178 | ||
2179 | : TODO .gitignore should not be here && | |
2180 | test_completion "git mv modified " <<-\EOF && | |
2181 | .gitignore | |
2182 | dir | |
2183 | modified | |
2184 | untracked | |
2185 | untracked-dir | |
2186 | EOF | |
2187 | ||
2188 | test_completion "git commit " "modified" && | |
2189 | ||
2190 | : TODO .gitignore should not be here && | |
8fb26872 | 2191 | test_completion "git ls-files " <<-\EOF && |
ddf07bdd FC |
2192 | .gitignore |
2193 | dir | |
2194 | modified | |
2195 | EOF | |
2196 | ||
2197 | touch momified && | |
2198 | test_completion "git add mom" "momified" | |
2199 | ' | |
2200 | ||
56f24e80 SP |
2201 | test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" ' |
2202 | test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" && | |
2203 | test_completion "git co m" <<-\EOF | |
2204 | master Z | |
2205 | mybranch Z | |
2206 | mytag Z | |
2207 | EOF | |
2208 | ' | |
2209 | ||
2210 | test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' ' | |
2211 | test_config alias.co "!f () { VAR=val git checkout ... ; } f" && | |
2212 | test_completion "git co m" <<-\EOF | |
2213 | master Z | |
2214 | mybranch Z | |
2215 | mytag Z | |
2216 | EOF | |
2217 | ' | |
2218 | ||
2219 | test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' ' | |
2220 | test_config alias.co "!f() { : git checkout ; if ... } f" && | |
2221 | test_completion "git co m" <<-\EOF | |
2222 | master Z | |
2223 | mybranch Z | |
2224 | mytag Z | |
2225 | EOF | |
2226 | ' | |
2227 | ||
9f642a71 NTND |
2228 | test_expect_success 'completion without explicit _git_xxx function' ' |
2229 | test_completion "git version --" <<-\EOF | |
2230 | --build-options Z | |
2b1c01d2 | 2231 | --no-build-options Z |
9f642a71 NTND |
2232 | EOF |
2233 | ' | |
2234 | ||
f03efba4 FC |
2235 | test_expect_failure 'complete with tilde expansion' ' |
2236 | git init tmp && cd tmp && | |
2237 | test_when_finished "cd .. && rm -rf tmp" && | |
2238 | ||
2239 | touch ~/tmp/file && | |
2240 | ||
2241 | test_completion "git add ~/tmp/" "~/tmp/file" | |
2242 | ' | |
2243 | ||
723c1d52 ÆAB |
2244 | test_expect_success 'setup other remote for remote reference completion' ' |
2245 | git remote add other otherrepo && | |
2246 | git fetch other | |
2247 | ' | |
2248 | ||
2249 | for flag in -d --delete | |
2250 | do | |
2251 | test_expect_success "__git_complete_remote_or_refspec - push $flag other" ' | |
2252 | sed -e "s/Z$//" >expected <<-EOF && | |
2253 | master-in-other Z | |
2254 | EOF | |
2255 | ( | |
2256 | words=(git push '$flag' other ma) && | |
2257 | cword=${#words[@]} cur=${words[cword-1]} && | |
2258 | __git_complete_remote_or_refspec && | |
2259 | print_comp | |
2260 | ) && | |
2261 | test_cmp expected out | |
2262 | ' | |
2263 | ||
2264 | test_expect_failure "__git_complete_remote_or_refspec - push other $flag" ' | |
2265 | sed -e "s/Z$//" >expected <<-EOF && | |
2266 | master-in-other Z | |
2267 | EOF | |
2268 | ( | |
2269 | words=(git push other '$flag' ma) && | |
2270 | cword=${#words[@]} cur=${words[cword-1]} && | |
2271 | __git_complete_remote_or_refspec && | |
2272 | print_comp | |
2273 | ) && | |
2274 | test_cmp expected out | |
2275 | ' | |
2276 | done | |
2277 | ||
d9438873 | 2278 | test_expect_success 'git config - section' ' |
7a09a8f0 SG |
2279 | test_completion "git config br" <<-\EOF |
2280 | branch.Z | |
2281 | browser.Z | |
2282 | EOF | |
2283 | ' | |
2284 | ||
2285 | test_expect_success 'git config - variable name' ' | |
2286 | test_completion "git config log.d" <<-\EOF | |
2287 | log.date Z | |
2288 | log.decorate Z | |
2289 | EOF | |
2290 | ' | |
2291 | ||
2292 | test_expect_success 'git config - value' ' | |
2293 | test_completion "git config color.pager " <<-\EOF | |
2294 | false Z | |
2295 | true Z | |
2296 | EOF | |
2297 | ' | |
2298 | ||
e1e00089 SG |
2299 | test_expect_success 'git -c - section' ' |
2300 | test_completion "git -c br" <<-\EOF | |
2301 | branch.Z | |
2302 | browser.Z | |
2303 | EOF | |
2304 | ' | |
2305 | ||
2306 | test_expect_success 'git -c - variable name' ' | |
2307 | test_completion "git -c log.d" <<-\EOF | |
2308 | log.date=Z | |
2309 | log.decorate=Z | |
2310 | EOF | |
2311 | ' | |
2312 | ||
dd334728 SG |
2313 | test_expect_success 'git -c - value' ' |
2314 | test_completion "git -c color.pager=" <<-\EOF | |
5af9d5f6 SG |
2315 | false Z |
2316 | true Z | |
2317 | EOF | |
2318 | ' | |
2319 | ||
2320 | test_expect_success 'git clone --config= - section' ' | |
2321 | test_completion "git clone --config=br" <<-\EOF | |
2322 | branch.Z | |
2323 | browser.Z | |
2324 | EOF | |
2325 | ' | |
2326 | ||
2327 | test_expect_success 'git clone --config= - variable name' ' | |
2328 | test_completion "git clone --config=log.d" <<-\EOF | |
2329 | log.date=Z | |
2330 | log.decorate=Z | |
2331 | EOF | |
2332 | ' | |
2333 | ||
2334 | test_expect_success 'git clone --config= - value' ' | |
2335 | test_completion "git clone --config=color.pager=" <<-\EOF | |
dd334728 SG |
2336 | false Z |
2337 | true Z | |
2338 | EOF | |
2339 | ' | |
2340 | ||
8b0eaa41 SG |
2341 | test_expect_success 'sourcing the completion script clears cached commands' ' |
2342 | __git_compute_all_commands && | |
2343 | verbose test -n "$__git_all_commands" && | |
2344 | . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && | |
2345 | verbose test -z "$__git_all_commands" | |
2346 | ' | |
2347 | ||
6cdccfce | 2348 | test_expect_success 'sourcing the completion script clears cached merge strategies' ' |
1ff750b1 | 2349 | GIT_TEST_GETTEXT_POISON=false && |
8b0eaa41 SG |
2350 | __git_compute_merge_strategies && |
2351 | verbose test -n "$__git_merge_strategies" && | |
2352 | . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && | |
2353 | verbose test -z "$__git_merge_strategies" | |
2354 | ' | |
2355 | ||
2356 | test_expect_success 'sourcing the completion script clears cached --options' ' | |
2357 | __gitcomp_builtin checkout && | |
2358 | verbose test -n "$__gitcomp_builtin_checkout" && | |
2359 | __gitcomp_builtin notes_edit && | |
2360 | verbose test -n "$__gitcomp_builtin_notes_edit" && | |
2361 | . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && | |
2362 | verbose test -z "$__gitcomp_builtin_checkout" && | |
2363 | verbose test -z "$__gitcomp_builtin_notes_edit" | |
2364 | ' | |
2365 | ||
5c293a6b | 2366 | test_done |