]>
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 && |
00076181 | 142 | git init -b main otherrepo |
c9a102e8 SG |
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 && | |
00076181 | 620 | git branch -M main && |
fb9cd420 SG |
621 | git branch matching-branch && |
622 | git tag matching-tag && | |
623 | ( | |
624 | cd otherrepo && | |
625 | git commit --allow-empty -m initial && | |
00076181 | 626 | git branch -m main main-in-other && |
fb9cd420 SG |
627 | git branch branch-in-other && |
628 | git tag tag-in-other | |
629 | ) && | |
630 | git remote add other "$ROOT/otherrepo/.git" && | |
631 | git fetch --no-tags other && | |
632 | rm -f .git/FETCH_HEAD && | |
633 | git init thirdrepo | |
634 | ' | |
635 | ||
636 | test_expect_success '__git_refs - simple' ' | |
637 | cat >expected <<-EOF && | |
638 | HEAD | |
00076181 | 639 | main |
fb9cd420 SG |
640 | matching-branch |
641 | other/branch-in-other | |
00076181 | 642 | other/main-in-other |
fb9cd420 SG |
643 | matching-tag |
644 | EOF | |
645 | ( | |
646 | cur= && | |
647 | __git_refs >"$actual" | |
648 | ) && | |
649 | test_cmp expected "$actual" | |
650 | ' | |
651 | ||
652 | test_expect_success '__git_refs - full refs' ' | |
653 | cat >expected <<-EOF && | |
00076181 | 654 | refs/heads/main |
fb9cd420 | 655 | refs/heads/matching-branch |
e896369b | 656 | refs/remotes/other/branch-in-other |
00076181 | 657 | refs/remotes/other/main-in-other |
e896369b | 658 | refs/tags/matching-tag |
fb9cd420 SG |
659 | EOF |
660 | ( | |
661 | cur=refs/heads/ && | |
662 | __git_refs >"$actual" | |
663 | ) && | |
664 | test_cmp expected "$actual" | |
665 | ' | |
666 | ||
667 | test_expect_success '__git_refs - repo given on the command line' ' | |
668 | cat >expected <<-EOF && | |
669 | HEAD | |
670 | branch-in-other | |
00076181 | 671 | main-in-other |
fb9cd420 SG |
672 | tag-in-other |
673 | EOF | |
674 | ( | |
675 | __git_dir="$ROOT/otherrepo/.git" && | |
676 | cur= && | |
677 | __git_refs >"$actual" | |
678 | ) && | |
679 | test_cmp expected "$actual" | |
680 | ' | |
681 | ||
682 | test_expect_success '__git_refs - remote on local file system' ' | |
683 | cat >expected <<-EOF && | |
684 | HEAD | |
685 | branch-in-other | |
00076181 | 686 | main-in-other |
fb9cd420 SG |
687 | tag-in-other |
688 | EOF | |
689 | ( | |
690 | cur= && | |
691 | __git_refs otherrepo >"$actual" | |
692 | ) && | |
693 | test_cmp expected "$actual" | |
694 | ' | |
695 | ||
696 | test_expect_success '__git_refs - remote on local file system - full refs' ' | |
697 | cat >expected <<-EOF && | |
698 | refs/heads/branch-in-other | |
00076181 | 699 | refs/heads/main-in-other |
fb9cd420 SG |
700 | refs/tags/tag-in-other |
701 | EOF | |
702 | ( | |
703 | cur=refs/ && | |
704 | __git_refs otherrepo >"$actual" | |
705 | ) && | |
706 | test_cmp expected "$actual" | |
707 | ' | |
708 | ||
709 | test_expect_success '__git_refs - configured remote' ' | |
710 | cat >expected <<-EOF && | |
711 | HEAD | |
712 | branch-in-other | |
00076181 | 713 | main-in-other |
fb9cd420 SG |
714 | EOF |
715 | ( | |
716 | cur= && | |
717 | __git_refs other >"$actual" | |
718 | ) && | |
719 | test_cmp expected "$actual" | |
720 | ' | |
721 | ||
722 | test_expect_success '__git_refs - configured remote - full refs' ' | |
723 | cat >expected <<-EOF && | |
e896369b | 724 | HEAD |
fb9cd420 | 725 | refs/heads/branch-in-other |
00076181 | 726 | refs/heads/main-in-other |
fb9cd420 SG |
727 | refs/tags/tag-in-other |
728 | EOF | |
729 | ( | |
730 | cur=refs/ && | |
731 | __git_refs other >"$actual" | |
732 | ) && | |
733 | test_cmp expected "$actual" | |
734 | ' | |
735 | ||
5c12f642 | 736 | test_expect_success '__git_refs - configured remote - repo given on the command line' ' |
fb9cd420 SG |
737 | cat >expected <<-EOF && |
738 | HEAD | |
739 | branch-in-other | |
00076181 | 740 | main-in-other |
fb9cd420 SG |
741 | EOF |
742 | ( | |
743 | cd thirdrepo && | |
744 | __git_dir="$ROOT/.git" && | |
745 | cur= && | |
746 | __git_refs other >"$actual" | |
747 | ) && | |
748 | test_cmp expected "$actual" | |
749 | ' | |
750 | ||
5c12f642 | 751 | test_expect_success '__git_refs - configured remote - full refs - repo given on the command line' ' |
fb9cd420 | 752 | cat >expected <<-EOF && |
e896369b | 753 | HEAD |
fb9cd420 | 754 | refs/heads/branch-in-other |
00076181 | 755 | refs/heads/main-in-other |
fb9cd420 SG |
756 | refs/tags/tag-in-other |
757 | EOF | |
758 | ( | |
759 | cd thirdrepo && | |
760 | __git_dir="$ROOT/.git" && | |
761 | cur=refs/ && | |
762 | __git_refs other >"$actual" | |
763 | ) && | |
764 | test_cmp expected "$actual" | |
765 | ' | |
766 | ||
69a77596 | 767 | test_expect_success '__git_refs - configured remote - remote name matches a directory' ' |
fb9cd420 SG |
768 | cat >expected <<-EOF && |
769 | HEAD | |
770 | branch-in-other | |
00076181 | 771 | main-in-other |
fb9cd420 SG |
772 | EOF |
773 | mkdir other && | |
774 | test_when_finished "rm -rf other" && | |
775 | ( | |
776 | cur= && | |
777 | __git_refs other >"$actual" | |
778 | ) && | |
779 | test_cmp expected "$actual" | |
780 | ' | |
781 | ||
91b7ea81 | 782 | test_expect_success '__git_refs - URL remote' ' |
fb9cd420 SG |
783 | cat >expected <<-EOF && |
784 | HEAD | |
785 | branch-in-other | |
00076181 | 786 | main-in-other |
fb9cd420 SG |
787 | tag-in-other |
788 | EOF | |
789 | ( | |
790 | cur= && | |
791 | __git_refs "file://$ROOT/otherrepo/.git" >"$actual" | |
792 | ) && | |
793 | test_cmp expected "$actual" | |
794 | ' | |
795 | ||
796 | test_expect_success '__git_refs - URL remote - full refs' ' | |
797 | cat >expected <<-EOF && | |
e896369b | 798 | HEAD |
fb9cd420 | 799 | refs/heads/branch-in-other |
00076181 | 800 | refs/heads/main-in-other |
fb9cd420 SG |
801 | refs/tags/tag-in-other |
802 | EOF | |
803 | ( | |
804 | cur=refs/ && | |
805 | __git_refs "file://$ROOT/otherrepo/.git" >"$actual" | |
806 | ) && | |
807 | test_cmp expected "$actual" | |
808 | ' | |
809 | ||
91b7ea81 | 810 | test_expect_success '__git_refs - non-existing remote' ' |
fb9cd420 SG |
811 | ( |
812 | cur= && | |
813 | __git_refs non-existing >"$actual" | |
814 | ) && | |
815 | test_must_be_empty "$actual" | |
816 | ' | |
817 | ||
818 | test_expect_success '__git_refs - non-existing remote - full refs' ' | |
819 | ( | |
820 | cur=refs/ && | |
821 | __git_refs non-existing >"$actual" | |
822 | ) && | |
823 | test_must_be_empty "$actual" | |
824 | ' | |
825 | ||
91b7ea81 | 826 | test_expect_success '__git_refs - non-existing URL remote' ' |
fb9cd420 SG |
827 | ( |
828 | cur= && | |
829 | __git_refs "file://$ROOT/non-existing" >"$actual" | |
830 | ) && | |
831 | test_must_be_empty "$actual" | |
832 | ' | |
833 | ||
834 | test_expect_success '__git_refs - non-existing URL remote - full refs' ' | |
835 | ( | |
836 | cur=refs/ && | |
837 | __git_refs "file://$ROOT/non-existing" >"$actual" | |
838 | ) && | |
839 | test_must_be_empty "$actual" | |
840 | ' | |
841 | ||
62a1b732 | 842 | test_expect_success '__git_refs - not in a git repository' ' |
fb9cd420 SG |
843 | ( |
844 | GIT_CEILING_DIRECTORIES="$ROOT" && | |
845 | export GIT_CEILING_DIRECTORIES && | |
846 | cd subdir && | |
847 | cur= && | |
848 | __git_refs >"$actual" | |
849 | ) && | |
850 | test_must_be_empty "$actual" | |
851 | ' | |
852 | ||
853 | test_expect_success '__git_refs - unique remote branches for git checkout DWIMery' ' | |
854 | cat >expected <<-EOF && | |
855 | HEAD | |
00076181 | 856 | main |
fb9cd420 SG |
857 | matching-branch |
858 | other/ambiguous | |
859 | other/branch-in-other | |
00076181 | 860 | other/main-in-other |
fb9cd420 SG |
861 | remote/ambiguous |
862 | remote/branch-in-remote | |
863 | matching-tag | |
864 | branch-in-other | |
865 | branch-in-remote | |
00076181 | 866 | main-in-other |
fb9cd420 SG |
867 | EOF |
868 | for remote_ref in refs/remotes/other/ambiguous \ | |
869 | refs/remotes/remote/ambiguous \ | |
870 | refs/remotes/remote/branch-in-remote | |
871 | do | |
00076181 | 872 | git update-ref $remote_ref main && |
fb9cd420 SG |
873 | test_when_finished "git update-ref -d $remote_ref" |
874 | done && | |
875 | ( | |
876 | cur= && | |
877 | __git_refs "" 1 >"$actual" | |
878 | ) && | |
879 | test_cmp expected "$actual" | |
880 | ' | |
881 | ||
2ea328a1 SG |
882 | test_expect_success '__git_refs - after --opt=' ' |
883 | cat >expected <<-EOF && | |
884 | HEAD | |
00076181 | 885 | main |
2ea328a1 SG |
886 | matching-branch |
887 | other/branch-in-other | |
00076181 | 888 | other/main-in-other |
2ea328a1 SG |
889 | matching-tag |
890 | EOF | |
891 | ( | |
892 | cur="--opt=" && | |
893 | __git_refs "" "" "" "" >"$actual" | |
894 | ) && | |
895 | test_cmp expected "$actual" | |
896 | ' | |
897 | ||
898 | test_expect_success '__git_refs - after --opt= - full refs' ' | |
899 | cat >expected <<-EOF && | |
00076181 | 900 | refs/heads/main |
2ea328a1 SG |
901 | refs/heads/matching-branch |
902 | refs/remotes/other/branch-in-other | |
00076181 | 903 | refs/remotes/other/main-in-other |
2ea328a1 SG |
904 | refs/tags/matching-tag |
905 | EOF | |
906 | ( | |
907 | cur="--opt=refs/" && | |
908 | __git_refs "" "" "" refs/ >"$actual" | |
909 | ) && | |
910 | test_cmp expected "$actual" | |
911 | ' | |
912 | ||
b64b43d2 | 913 | test_expect_success '__git refs - excluding refs' ' |
aed38813 SG |
914 | cat >expected <<-EOF && |
915 | ^HEAD | |
00076181 | 916 | ^main |
aed38813 SG |
917 | ^matching-branch |
918 | ^other/branch-in-other | |
00076181 | 919 | ^other/main-in-other |
aed38813 SG |
920 | ^matching-tag |
921 | EOF | |
922 | ( | |
923 | cur=^ && | |
924 | __git_refs >"$actual" | |
925 | ) && | |
926 | test_cmp expected "$actual" | |
927 | ' | |
928 | ||
b64b43d2 | 929 | test_expect_success '__git refs - excluding full refs' ' |
aed38813 | 930 | cat >expected <<-EOF && |
00076181 | 931 | ^refs/heads/main |
aed38813 SG |
932 | ^refs/heads/matching-branch |
933 | ^refs/remotes/other/branch-in-other | |
00076181 | 934 | ^refs/remotes/other/main-in-other |
aed38813 SG |
935 | ^refs/tags/matching-tag |
936 | EOF | |
937 | ( | |
938 | cur=^refs/ && | |
939 | __git_refs >"$actual" | |
940 | ) && | |
941 | test_cmp expected "$actual" | |
942 | ' | |
943 | ||
e896369b SG |
944 | test_expect_success 'setup for filtering matching refs' ' |
945 | git branch matching/branch && | |
946 | git tag matching/tag && | |
947 | git -C otherrepo branch matching/branch-in-other && | |
948 | git fetch --no-tags other && | |
949 | rm -f .git/FETCH_HEAD | |
950 | ' | |
951 | ||
4dc8b1c1 | 952 | test_expect_success '__git_refs - do not filter refs unless told so' ' |
e896369b SG |
953 | cat >expected <<-EOF && |
954 | HEAD | |
00076181 | 955 | main |
e896369b SG |
956 | matching-branch |
957 | matching/branch | |
958 | other/branch-in-other | |
00076181 | 959 | other/main-in-other |
e896369b SG |
960 | other/matching/branch-in-other |
961 | matching-tag | |
962 | matching/tag | |
963 | EOF | |
964 | ( | |
00076181 | 965 | cur=main && |
e896369b SG |
966 | __git_refs >"$actual" |
967 | ) && | |
968 | test_cmp expected "$actual" | |
969 | ' | |
970 | ||
971 | test_expect_success '__git_refs - only matching refs' ' | |
972 | cat >expected <<-EOF && | |
973 | matching-branch | |
974 | matching/branch | |
975 | matching-tag | |
976 | matching/tag | |
977 | EOF | |
978 | ( | |
979 | cur=mat && | |
980 | __git_refs "" "" "" "$cur" >"$actual" | |
981 | ) && | |
982 | test_cmp expected "$actual" | |
983 | ' | |
984 | ||
985 | test_expect_success '__git_refs - only matching refs - full refs' ' | |
986 | cat >expected <<-EOF && | |
987 | refs/heads/matching-branch | |
988 | refs/heads/matching/branch | |
989 | EOF | |
990 | ( | |
991 | cur=refs/heads/mat && | |
992 | __git_refs "" "" "" "$cur" >"$actual" | |
993 | ) && | |
994 | test_cmp expected "$actual" | |
995 | ' | |
996 | ||
997 | test_expect_success '__git_refs - only matching refs - remote on local file system' ' | |
998 | cat >expected <<-EOF && | |
00076181 | 999 | main-in-other |
e896369b SG |
1000 | matching/branch-in-other |
1001 | EOF | |
1002 | ( | |
1003 | cur=ma && | |
1004 | __git_refs otherrepo "" "" "$cur" >"$actual" | |
1005 | ) && | |
1006 | test_cmp expected "$actual" | |
1007 | ' | |
1008 | ||
1009 | test_expect_success '__git_refs - only matching refs - configured remote' ' | |
1010 | cat >expected <<-EOF && | |
00076181 | 1011 | main-in-other |
e896369b SG |
1012 | matching/branch-in-other |
1013 | EOF | |
1014 | ( | |
1015 | cur=ma && | |
1016 | __git_refs other "" "" "$cur" >"$actual" | |
1017 | ) && | |
1018 | test_cmp expected "$actual" | |
1019 | ' | |
1020 | ||
1021 | test_expect_success '__git_refs - only matching refs - remote - full refs' ' | |
1022 | cat >expected <<-EOF && | |
00076181 | 1023 | refs/heads/main-in-other |
e896369b SG |
1024 | refs/heads/matching/branch-in-other |
1025 | EOF | |
1026 | ( | |
1027 | cur=refs/heads/ma && | |
1028 | __git_refs other "" "" "$cur" >"$actual" | |
1029 | ) && | |
1030 | test_cmp expected "$actual" | |
1031 | ' | |
1032 | ||
1033 | test_expect_success '__git_refs - only matching refs - checkout DWIMery' ' | |
1034 | cat >expected <<-EOF && | |
1035 | matching-branch | |
1036 | matching/branch | |
1037 | matching-tag | |
1038 | matching/tag | |
1039 | matching/branch-in-other | |
1040 | EOF | |
1041 | for remote_ref in refs/remotes/other/ambiguous \ | |
1042 | refs/remotes/remote/ambiguous \ | |
1043 | refs/remotes/remote/branch-in-remote | |
1044 | do | |
00076181 | 1045 | git update-ref $remote_ref main && |
e896369b SG |
1046 | test_when_finished "git update-ref -d $remote_ref" |
1047 | done && | |
1048 | ( | |
1049 | cur=mat && | |
1050 | __git_refs "" 1 "" "$cur" >"$actual" | |
1051 | ) && | |
1052 | test_cmp expected "$actual" | |
1053 | ' | |
1054 | ||
1055 | test_expect_success 'teardown after filtering matching refs' ' | |
1056 | git branch -d matching/branch && | |
1057 | git tag -d matching/tag && | |
1058 | git update-ref -d refs/remotes/other/matching/branch-in-other && | |
1059 | git -C otherrepo branch -D matching/branch-in-other | |
1060 | ' | |
1061 | ||
00076181 | 1062 | test_expect_success '__git_refs - for-each-ref format specifiers in prefix' ' |
fef56eb0 | 1063 | cat >expected <<-EOF && |
00076181 | 1064 | evil-%%-%42-%(refname)..main |
fef56eb0 SG |
1065 | EOF |
1066 | ( | |
8164360f JS |
1067 | cur="evil-%%-%42-%(refname)..mai" && |
1068 | __git_refs "" "" "evil-%%-%42-%(refname).." mai >"$actual" | |
fef56eb0 SG |
1069 | ) && |
1070 | test_cmp expected "$actual" | |
1071 | ' | |
1072 | ||
15b4a163 SG |
1073 | test_expect_success '__git_complete_refs - simple' ' |
1074 | sed -e "s/Z$//" >expected <<-EOF && | |
1075 | HEAD Z | |
00076181 | 1076 | main Z |
15b4a163 SG |
1077 | matching-branch Z |
1078 | other/branch-in-other Z | |
00076181 | 1079 | other/main-in-other Z |
15b4a163 SG |
1080 | matching-tag Z |
1081 | EOF | |
1082 | ( | |
1083 | cur= && | |
1084 | __git_complete_refs && | |
1085 | print_comp | |
1086 | ) && | |
1087 | test_cmp expected out | |
1088 | ' | |
1089 | ||
1090 | test_expect_success '__git_complete_refs - matching' ' | |
1091 | sed -e "s/Z$//" >expected <<-EOF && | |
1092 | matching-branch Z | |
1093 | matching-tag Z | |
1094 | EOF | |
1095 | ( | |
1096 | cur=mat && | |
1097 | __git_complete_refs && | |
1098 | print_comp | |
1099 | ) && | |
1100 | test_cmp expected out | |
1101 | ' | |
1102 | ||
1103 | test_expect_success '__git_complete_refs - remote' ' | |
1104 | sed -e "s/Z$//" >expected <<-EOF && | |
1105 | HEAD Z | |
1106 | branch-in-other Z | |
00076181 | 1107 | main-in-other Z |
15b4a163 SG |
1108 | EOF |
1109 | ( | |
cff4243d | 1110 | cur= && |
15b4a163 SG |
1111 | __git_complete_refs --remote=other && |
1112 | print_comp | |
1113 | ) && | |
1114 | test_cmp expected out | |
1115 | ' | |
1116 | ||
1117 | test_expect_success '__git_complete_refs - track' ' | |
1118 | sed -e "s/Z$//" >expected <<-EOF && | |
1119 | HEAD Z | |
00076181 | 1120 | main Z |
15b4a163 SG |
1121 | matching-branch Z |
1122 | other/branch-in-other Z | |
00076181 | 1123 | other/main-in-other Z |
15b4a163 SG |
1124 | matching-tag Z |
1125 | branch-in-other Z | |
00076181 | 1126 | main-in-other Z |
15b4a163 SG |
1127 | EOF |
1128 | ( | |
cff4243d | 1129 | cur= && |
15b4a163 SG |
1130 | __git_complete_refs --track && |
1131 | print_comp | |
1132 | ) && | |
1133 | test_cmp expected out | |
1134 | ' | |
1135 | ||
1136 | test_expect_success '__git_complete_refs - current word' ' | |
1137 | sed -e "s/Z$//" >expected <<-EOF && | |
1138 | matching-branch Z | |
1139 | matching-tag Z | |
1140 | EOF | |
1141 | ( | |
1142 | cur="--option=mat" && | |
1143 | __git_complete_refs --cur="${cur#*=}" && | |
1144 | print_comp | |
1145 | ) && | |
1146 | test_cmp expected out | |
1147 | ' | |
1148 | ||
1149 | test_expect_success '__git_complete_refs - prefix' ' | |
1150 | sed -e "s/Z$//" >expected <<-EOF && | |
1151 | v1.0..matching-branch Z | |
1152 | v1.0..matching-tag Z | |
1153 | EOF | |
1154 | ( | |
1155 | cur=v1.0..mat && | |
1156 | __git_complete_refs --pfx=v1.0.. --cur=mat && | |
1157 | print_comp | |
1158 | ) && | |
1159 | test_cmp expected out | |
1160 | ' | |
1161 | ||
1162 | test_expect_success '__git_complete_refs - suffix' ' | |
1163 | cat >expected <<-EOF && | |
1164 | HEAD. | |
00076181 | 1165 | main. |
15b4a163 SG |
1166 | matching-branch. |
1167 | other/branch-in-other. | |
00076181 | 1168 | other/main-in-other. |
15b4a163 SG |
1169 | matching-tag. |
1170 | EOF | |
1171 | ( | |
1172 | cur= && | |
1173 | __git_complete_refs --sfx=. && | |
1174 | print_comp | |
1175 | ) && | |
1176 | test_cmp expected out | |
1177 | ' | |
1178 | ||
aa0644f7 SG |
1179 | test_expect_success '__git_complete_fetch_refspecs - simple' ' |
1180 | sed -e "s/Z$//" >expected <<-EOF && | |
1181 | HEAD:HEAD Z | |
1182 | branch-in-other:branch-in-other Z | |
00076181 | 1183 | main-in-other:main-in-other Z |
aa0644f7 SG |
1184 | EOF |
1185 | ( | |
1186 | cur= && | |
1187 | __git_complete_fetch_refspecs other && | |
1188 | print_comp | |
1189 | ) && | |
1190 | test_cmp expected out | |
1191 | ' | |
1192 | ||
1193 | test_expect_success '__git_complete_fetch_refspecs - matching' ' | |
1194 | sed -e "s/Z$//" >expected <<-EOF && | |
1195 | branch-in-other:branch-in-other Z | |
1196 | EOF | |
1197 | ( | |
1198 | cur=br && | |
1199 | __git_complete_fetch_refspecs other "" br && | |
1200 | print_comp | |
1201 | ) && | |
1202 | test_cmp expected out | |
1203 | ' | |
1204 | ||
1205 | test_expect_success '__git_complete_fetch_refspecs - prefix' ' | |
1206 | sed -e "s/Z$//" >expected <<-EOF && | |
1207 | +HEAD:HEAD Z | |
1208 | +branch-in-other:branch-in-other Z | |
00076181 | 1209 | +main-in-other:main-in-other Z |
aa0644f7 SG |
1210 | EOF |
1211 | ( | |
1212 | cur="+" && | |
1213 | __git_complete_fetch_refspecs other "+" "" && | |
1214 | print_comp | |
1215 | ) && | |
1216 | test_cmp expected out | |
1217 | ' | |
1218 | ||
1219 | test_expect_success '__git_complete_fetch_refspecs - fully qualified' ' | |
1220 | sed -e "s/Z$//" >expected <<-EOF && | |
1221 | refs/heads/branch-in-other:refs/heads/branch-in-other Z | |
00076181 | 1222 | refs/heads/main-in-other:refs/heads/main-in-other Z |
aa0644f7 SG |
1223 | refs/tags/tag-in-other:refs/tags/tag-in-other Z |
1224 | EOF | |
1225 | ( | |
1226 | cur=refs/ && | |
1227 | __git_complete_fetch_refspecs other "" refs/ && | |
1228 | print_comp | |
1229 | ) && | |
1230 | test_cmp expected out | |
1231 | ' | |
1232 | ||
1233 | test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' ' | |
1234 | sed -e "s/Z$//" >expected <<-EOF && | |
1235 | +refs/heads/branch-in-other:refs/heads/branch-in-other Z | |
00076181 | 1236 | +refs/heads/main-in-other:refs/heads/main-in-other Z |
aa0644f7 SG |
1237 | +refs/tags/tag-in-other:refs/tags/tag-in-other Z |
1238 | EOF | |
1239 | ( | |
1240 | cur=+refs/ && | |
1241 | __git_complete_fetch_refspecs other + refs/ && | |
1242 | print_comp | |
1243 | ) && | |
1244 | test_cmp expected out | |
1245 | ' | |
1246 | ||
68d97c7f | 1247 | test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' ' |
fab466f9 JK |
1248 | test_completion "git switch " <<-\EOF |
1249 | branch-in-other Z | |
00076181 JS |
1250 | main Z |
1251 | main-in-other Z | |
fab466f9 JK |
1252 | matching-branch Z |
1253 | EOF | |
1254 | ' | |
1255 | ||
1256 | test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' ' | |
1257 | test_completion "git checkout " <<-\EOF | |
1258 | HEAD Z | |
1259 | branch-in-other Z | |
00076181 JS |
1260 | main Z |
1261 | main-in-other Z | |
fab466f9 JK |
1262 | matching-branch Z |
1263 | matching-tag Z | |
1264 | other/branch-in-other Z | |
00076181 | 1265 | other/main-in-other Z |
fab466f9 JK |
1266 | EOF |
1267 | ' | |
1268 | ||
ab58e90f JK |
1269 | test_expect_success 'git switch - with --no-guess, complete only local branches' ' |
1270 | test_completion "git switch --no-guess " <<-\EOF | |
00076181 | 1271 | main Z |
ab58e90f JK |
1272 | matching-branch Z |
1273 | EOF | |
1274 | ' | |
1275 | ||
1276 | test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete only local branches' ' | |
1277 | GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch " <<-\EOF | |
00076181 | 1278 | main Z |
ab58e90f JK |
1279 | matching-branch Z |
1280 | EOF | |
1281 | ' | |
1282 | ||
68d97c7f | 1283 | 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 |
1284 | GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch --guess " <<-\EOF |
1285 | branch-in-other Z | |
00076181 JS |
1286 | main Z |
1287 | main-in-other Z | |
ab58e90f JK |
1288 | matching-branch Z |
1289 | EOF | |
1290 | ' | |
1291 | ||
68d97c7f | 1292 | test_expect_success 'git switch - a later --guess overrides previous --no-guess, complete local and remote unique branches for DWIM' ' |
ab58e90f JK |
1293 | test_completion "git switch --no-guess --guess " <<-\EOF |
1294 | branch-in-other Z | |
00076181 JS |
1295 | main Z |
1296 | main-in-other Z | |
ab58e90f JK |
1297 | matching-branch Z |
1298 | EOF | |
1299 | ' | |
1300 | ||
4e79adf4 | 1301 | test_expect_success 'git switch - a later --no-guess overrides previous --guess, complete only local branches' ' |
ab58e90f | 1302 | test_completion "git switch --guess --no-guess " <<-\EOF |
00076181 | 1303 | main Z |
ab58e90f JK |
1304 | matching-branch Z |
1305 | EOF | |
1306 | ' | |
1307 | ||
1308 | test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS=1 only completes refs' ' | |
1309 | GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout " <<-\EOF | |
1310 | HEAD Z | |
00076181 | 1311 | main Z |
ab58e90f JK |
1312 | matching-branch Z |
1313 | matching-tag Z | |
1314 | other/branch-in-other Z | |
00076181 | 1315 | other/main-in-other Z |
ab58e90f JK |
1316 | EOF |
1317 | ' | |
1318 | ||
4e79adf4 | 1319 | test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS=1, complete refs and unique remote branches for DWIM' ' |
ab58e90f JK |
1320 | GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout --guess " <<-\EOF |
1321 | HEAD Z | |
1322 | branch-in-other Z | |
00076181 JS |
1323 | main Z |
1324 | main-in-other Z | |
ab58e90f JK |
1325 | matching-branch Z |
1326 | matching-tag Z | |
1327 | other/branch-in-other Z | |
00076181 | 1328 | other/main-in-other Z |
ab58e90f JK |
1329 | EOF |
1330 | ' | |
1331 | ||
1332 | test_expect_success 'git checkout - with --no-guess, only completes refs' ' | |
1333 | test_completion "git checkout --no-guess " <<-\EOF | |
1334 | HEAD Z | |
00076181 | 1335 | main Z |
ab58e90f JK |
1336 | matching-branch Z |
1337 | matching-tag Z | |
1338 | other/branch-in-other Z | |
00076181 | 1339 | other/main-in-other Z |
ab58e90f JK |
1340 | EOF |
1341 | ' | |
1342 | ||
4e79adf4 | 1343 | test_expect_success 'git checkout - a later --guess overrides previous --no-guess, complete refs and unique remote branches for DWIM' ' |
ab58e90f JK |
1344 | test_completion "git checkout --no-guess --guess " <<-\EOF |
1345 | HEAD Z | |
1346 | branch-in-other Z | |
00076181 JS |
1347 | main Z |
1348 | main-in-other Z | |
ab58e90f JK |
1349 | matching-branch Z |
1350 | matching-tag Z | |
1351 | other/branch-in-other Z | |
00076181 | 1352 | other/main-in-other Z |
ab58e90f JK |
1353 | EOF |
1354 | ' | |
1355 | ||
1356 | test_expect_success 'git checkout - a later --no-guess overrides previous --guess, complete only refs' ' | |
1357 | test_completion "git checkout --guess --no-guess " <<-\EOF | |
1358 | HEAD Z | |
00076181 | 1359 | main Z |
ab58e90f JK |
1360 | matching-branch Z |
1361 | matching-tag Z | |
1362 | other/branch-in-other Z | |
00076181 | 1363 | other/main-in-other Z |
ab58e90f JK |
1364 | EOF |
1365 | ' | |
1366 | ||
64f1f58f DL |
1367 | test_expect_success 'git checkout - with checkout.guess = false, only completes refs' ' |
1368 | test_config checkout.guess false && | |
1369 | test_completion "git checkout " <<-\EOF | |
1370 | HEAD Z | |
00076181 | 1371 | main Z |
64f1f58f DL |
1372 | matching-branch Z |
1373 | matching-tag Z | |
1374 | other/branch-in-other Z | |
00076181 | 1375 | other/main-in-other Z |
64f1f58f DL |
1376 | EOF |
1377 | ' | |
1378 | ||
1379 | test_expect_success 'git checkout - with checkout.guess = true, completes refs and unique remote branches for DWIM' ' | |
1380 | test_config checkout.guess true && | |
1381 | test_completion "git checkout " <<-\EOF | |
1382 | HEAD Z | |
1383 | branch-in-other Z | |
00076181 JS |
1384 | main Z |
1385 | main-in-other Z | |
64f1f58f DL |
1386 | matching-branch Z |
1387 | matching-tag Z | |
1388 | other/branch-in-other Z | |
00076181 | 1389 | other/main-in-other Z |
64f1f58f DL |
1390 | EOF |
1391 | ' | |
1392 | ||
1393 | test_expect_success 'git checkout - a later --guess overrides previous checkout.guess = false, complete refs and unique remote branches for DWIM' ' | |
1394 | test_config checkout.guess false && | |
1395 | test_completion "git checkout --guess " <<-\EOF | |
1396 | HEAD Z | |
1397 | branch-in-other Z | |
00076181 JS |
1398 | main Z |
1399 | main-in-other Z | |
64f1f58f DL |
1400 | matching-branch Z |
1401 | matching-tag Z | |
1402 | other/branch-in-other Z | |
00076181 | 1403 | other/main-in-other Z |
64f1f58f DL |
1404 | EOF |
1405 | ' | |
1406 | ||
1407 | test_expect_success 'git checkout - a later --no-guess overrides previous checkout.guess = true, complete only refs' ' | |
1408 | test_config checkout.guess true && | |
1409 | test_completion "git checkout --no-guess " <<-\EOF | |
1410 | HEAD Z | |
00076181 | 1411 | main Z |
64f1f58f DL |
1412 | matching-branch Z |
1413 | matching-tag Z | |
1414 | other/branch-in-other Z | |
00076181 | 1415 | other/main-in-other Z |
64f1f58f DL |
1416 | EOF |
1417 | ' | |
1418 | ||
e69fb0a1 JK |
1419 | test_expect_success 'git switch - with --detach, complete all references' ' |
1420 | test_completion "git switch --detach " <<-\EOF | |
1421 | HEAD Z | |
00076181 | 1422 | main Z |
e69fb0a1 JK |
1423 | matching-branch Z |
1424 | matching-tag Z | |
1425 | other/branch-in-other Z | |
00076181 | 1426 | other/main-in-other Z |
e69fb0a1 JK |
1427 | EOF |
1428 | ' | |
1429 | ||
6d76a5cc | 1430 | test_expect_success 'git checkout - with --detach, complete only references' ' |
e69fb0a1 JK |
1431 | test_completion "git checkout --detach " <<-\EOF |
1432 | HEAD Z | |
00076181 | 1433 | main Z |
e69fb0a1 JK |
1434 | matching-branch Z |
1435 | matching-tag Z | |
1436 | other/branch-in-other Z | |
00076181 | 1437 | other/main-in-other Z |
e69fb0a1 JK |
1438 | EOF |
1439 | ' | |
1440 | ||
1441 | test_expect_success 'git switch - with -d, complete all references' ' | |
1442 | test_completion "git switch -d " <<-\EOF | |
1443 | HEAD Z | |
00076181 | 1444 | main Z |
e69fb0a1 JK |
1445 | matching-branch Z |
1446 | matching-tag Z | |
1447 | other/branch-in-other Z | |
00076181 | 1448 | other/main-in-other Z |
e69fb0a1 JK |
1449 | EOF |
1450 | ' | |
1451 | ||
6d76a5cc | 1452 | test_expect_success 'git checkout - with -d, complete only references' ' |
e69fb0a1 JK |
1453 | test_completion "git checkout -d " <<-\EOF |
1454 | HEAD Z | |
00076181 | 1455 | main Z |
e69fb0a1 JK |
1456 | matching-branch Z |
1457 | matching-tag Z | |
1458 | other/branch-in-other Z | |
00076181 | 1459 | other/main-in-other Z |
e69fb0a1 JK |
1460 | EOF |
1461 | ' | |
1462 | ||
00e7bd2b | 1463 | test_expect_success 'git switch - with --track, complete only remote branches' ' |
c55b99c3 JK |
1464 | test_completion "git switch --track " <<-\EOF |
1465 | other/branch-in-other Z | |
00076181 | 1466 | other/main-in-other Z |
c55b99c3 JK |
1467 | EOF |
1468 | ' | |
1469 | ||
00e7bd2b | 1470 | test_expect_success 'git checkout - with --track, complete only remote branches' ' |
c55b99c3 JK |
1471 | test_completion "git checkout --track " <<-\EOF |
1472 | other/branch-in-other Z | |
00076181 | 1473 | other/main-in-other Z |
c55b99c3 JK |
1474 | EOF |
1475 | ' | |
1476 | ||
1477 | test_expect_success 'git switch - with --no-track, complete only local branch names' ' | |
1478 | test_completion "git switch --no-track " <<-\EOF | |
00076181 | 1479 | main Z |
c55b99c3 JK |
1480 | matching-branch Z |
1481 | EOF | |
1482 | ' | |
1483 | ||
1484 | test_expect_success 'git checkout - with --no-track, complete only local references' ' | |
1485 | test_completion "git checkout --no-track " <<-\EOF | |
1486 | HEAD Z | |
00076181 | 1487 | main Z |
c55b99c3 JK |
1488 | matching-branch Z |
1489 | matching-tag Z | |
1490 | other/branch-in-other Z | |
00076181 | 1491 | other/main-in-other Z |
c55b99c3 JK |
1492 | EOF |
1493 | ' | |
1494 | ||
acb658fe | 1495 | test_expect_success 'git switch - with -c, complete all references' ' |
b07d77a2 JK |
1496 | test_completion "git switch -c new-branch " <<-\EOF |
1497 | HEAD Z | |
00076181 | 1498 | main Z |
b07d77a2 JK |
1499 | matching-branch Z |
1500 | matching-tag Z | |
1501 | other/branch-in-other Z | |
00076181 | 1502 | other/main-in-other Z |
b07d77a2 JK |
1503 | EOF |
1504 | ' | |
1505 | ||
acb658fe | 1506 | test_expect_success 'git switch - with -C, complete all references' ' |
b07d77a2 JK |
1507 | test_completion "git switch -C new-branch " <<-\EOF |
1508 | HEAD Z | |
00076181 | 1509 | main Z |
b07d77a2 JK |
1510 | matching-branch Z |
1511 | matching-tag Z | |
1512 | other/branch-in-other Z | |
00076181 | 1513 | other/main-in-other Z |
b07d77a2 JK |
1514 | EOF |
1515 | ' | |
1516 | ||
acb658fe | 1517 | test_expect_success 'git switch - with -c and --track, complete all references' ' |
b07d77a2 JK |
1518 | test_completion "git switch -c new-branch --track " <<-EOF |
1519 | HEAD Z | |
00076181 | 1520 | main Z |
b07d77a2 JK |
1521 | matching-branch Z |
1522 | matching-tag Z | |
1523 | other/branch-in-other Z | |
00076181 | 1524 | other/main-in-other Z |
b07d77a2 JK |
1525 | EOF |
1526 | ' | |
1527 | ||
acb658fe | 1528 | test_expect_success 'git switch - with -C and --track, complete all references' ' |
b07d77a2 JK |
1529 | test_completion "git switch -C new-branch --track " <<-EOF |
1530 | HEAD Z | |
00076181 | 1531 | main Z |
b07d77a2 JK |
1532 | matching-branch Z |
1533 | matching-tag Z | |
1534 | other/branch-in-other Z | |
00076181 | 1535 | other/main-in-other Z |
b07d77a2 JK |
1536 | EOF |
1537 | ' | |
1538 | ||
acb658fe | 1539 | test_expect_success 'git switch - with -c and --no-track, complete all references' ' |
b07d77a2 JK |
1540 | test_completion "git switch -c new-branch --no-track " <<-\EOF |
1541 | HEAD Z | |
00076181 | 1542 | main Z |
b07d77a2 JK |
1543 | matching-branch Z |
1544 | matching-tag Z | |
1545 | other/branch-in-other Z | |
00076181 | 1546 | other/main-in-other Z |
b07d77a2 JK |
1547 | EOF |
1548 | ' | |
1549 | ||
acb658fe | 1550 | test_expect_success 'git switch - with -C and --no-track, complete all references' ' |
b07d77a2 JK |
1551 | test_completion "git switch -C new-branch --no-track " <<-\EOF |
1552 | HEAD Z | |
00076181 | 1553 | main Z |
b07d77a2 JK |
1554 | matching-branch Z |
1555 | matching-tag Z | |
1556 | other/branch-in-other Z | |
00076181 | 1557 | other/main-in-other Z |
b07d77a2 JK |
1558 | EOF |
1559 | ' | |
1560 | ||
acb658fe | 1561 | test_expect_success 'git checkout - with -b, complete all references' ' |
b07d77a2 JK |
1562 | test_completion "git checkout -b new-branch " <<-\EOF |
1563 | HEAD Z | |
00076181 | 1564 | main Z |
b07d77a2 JK |
1565 | matching-branch Z |
1566 | matching-tag Z | |
1567 | other/branch-in-other Z | |
00076181 | 1568 | other/main-in-other Z |
b07d77a2 JK |
1569 | EOF |
1570 | ' | |
1571 | ||
acb658fe | 1572 | test_expect_success 'git checkout - with -B, complete all references' ' |
b07d77a2 JK |
1573 | test_completion "git checkout -B new-branch " <<-\EOF |
1574 | HEAD Z | |
00076181 | 1575 | main Z |
b07d77a2 JK |
1576 | matching-branch Z |
1577 | matching-tag Z | |
1578 | other/branch-in-other Z | |
00076181 | 1579 | other/main-in-other Z |
b07d77a2 JK |
1580 | EOF |
1581 | ' | |
1582 | ||
acb658fe | 1583 | test_expect_success 'git checkout - with -b and --track, complete all references' ' |
b07d77a2 JK |
1584 | test_completion "git checkout -b new-branch --track " <<-EOF |
1585 | HEAD Z | |
00076181 | 1586 | main Z |
b07d77a2 JK |
1587 | matching-branch Z |
1588 | matching-tag Z | |
1589 | other/branch-in-other Z | |
00076181 | 1590 | other/main-in-other Z |
b07d77a2 JK |
1591 | EOF |
1592 | ' | |
1593 | ||
acb658fe | 1594 | test_expect_success 'git checkout - with -B and --track, complete all references' ' |
b07d77a2 JK |
1595 | test_completion "git checkout -B new-branch --track " <<-EOF |
1596 | HEAD Z | |
00076181 | 1597 | main Z |
b07d77a2 JK |
1598 | matching-branch Z |
1599 | matching-tag Z | |
1600 | other/branch-in-other Z | |
00076181 | 1601 | other/main-in-other Z |
b07d77a2 JK |
1602 | EOF |
1603 | ' | |
1604 | ||
1605 | test_expect_success 'git checkout - with -b and --no-track, complete all references' ' | |
1606 | test_completion "git checkout -b new-branch --no-track " <<-\EOF | |
1607 | HEAD Z | |
00076181 | 1608 | main Z |
b07d77a2 JK |
1609 | matching-branch Z |
1610 | matching-tag Z | |
1611 | other/branch-in-other Z | |
00076181 | 1612 | other/main-in-other Z |
b07d77a2 JK |
1613 | EOF |
1614 | ' | |
1615 | ||
1616 | test_expect_success 'git checkout - with -B and --no-track, complete all references' ' | |
1617 | test_completion "git checkout -B new-branch --no-track " <<-\EOF | |
1618 | HEAD Z | |
00076181 | 1619 | main Z |
b07d77a2 JK |
1620 | matching-branch Z |
1621 | matching-tag Z | |
1622 | other/branch-in-other Z | |
00076181 | 1623 | other/main-in-other Z |
b07d77a2 JK |
1624 | EOF |
1625 | ' | |
1626 | ||
68d97c7f | 1627 | test_expect_success 'git switch - for -c, complete local branches and unique remote branches' ' |
7f59d604 JK |
1628 | test_completion "git switch -c " <<-\EOF |
1629 | branch-in-other Z | |
00076181 JS |
1630 | main Z |
1631 | main-in-other Z | |
7f59d604 JK |
1632 | matching-branch Z |
1633 | EOF | |
1634 | ' | |
1635 | ||
68d97c7f | 1636 | test_expect_success 'git switch - for -C, complete local branches and unique remote branches' ' |
7f59d604 JK |
1637 | test_completion "git switch -C " <<-\EOF |
1638 | branch-in-other Z | |
00076181 JS |
1639 | main Z |
1640 | main-in-other Z | |
7f59d604 JK |
1641 | matching-branch Z |
1642 | EOF | |
1643 | ' | |
1644 | ||
1645 | test_expect_success 'git switch - for -c with --no-guess, complete local branches only' ' | |
1646 | test_completion "git switch --no-guess -c " <<-\EOF | |
00076181 | 1647 | main Z |
7f59d604 JK |
1648 | matching-branch Z |
1649 | EOF | |
1650 | ' | |
1651 | ||
1652 | test_expect_success 'git switch - for -C with --no-guess, complete local branches only' ' | |
1653 | test_completion "git switch --no-guess -C " <<-\EOF | |
00076181 | 1654 | main Z |
7f59d604 JK |
1655 | matching-branch Z |
1656 | EOF | |
1657 | ' | |
1658 | ||
1659 | test_expect_success 'git switch - for -c with --no-track, complete local branches only' ' | |
1660 | test_completion "git switch --no-track -c " <<-\EOF | |
00076181 | 1661 | main Z |
7f59d604 JK |
1662 | matching-branch Z |
1663 | EOF | |
1664 | ' | |
1665 | ||
1666 | test_expect_success 'git switch - for -C with --no-track, complete local branches only' ' | |
1667 | test_completion "git switch --no-track -C " <<-\EOF | |
00076181 | 1668 | main Z |
7f59d604 JK |
1669 | matching-branch Z |
1670 | EOF | |
1671 | ' | |
1672 | ||
acb658fe | 1673 | test_expect_success 'git checkout - for -b, complete local branches and unique remote branches' ' |
7f59d604 JK |
1674 | test_completion "git checkout -b " <<-\EOF |
1675 | branch-in-other Z | |
00076181 JS |
1676 | main Z |
1677 | main-in-other Z | |
7f59d604 JK |
1678 | matching-branch Z |
1679 | EOF | |
1680 | ' | |
1681 | ||
acb658fe | 1682 | test_expect_success 'git checkout - for -B, complete local branches and unique remote branches' ' |
7f59d604 JK |
1683 | test_completion "git checkout -B " <<-\EOF |
1684 | branch-in-other Z | |
00076181 JS |
1685 | main Z |
1686 | main-in-other Z | |
7f59d604 JK |
1687 | matching-branch Z |
1688 | EOF | |
1689 | ' | |
1690 | ||
acb658fe | 1691 | test_expect_success 'git checkout - for -b with --no-guess, complete local branches only' ' |
7f59d604 | 1692 | test_completion "git checkout --no-guess -b " <<-\EOF |
00076181 | 1693 | main Z |
7f59d604 JK |
1694 | matching-branch Z |
1695 | EOF | |
1696 | ' | |
1697 | ||
acb658fe | 1698 | test_expect_success 'git checkout - for -B with --no-guess, complete local branches only' ' |
7f59d604 | 1699 | test_completion "git checkout --no-guess -B " <<-\EOF |
00076181 | 1700 | main Z |
7f59d604 JK |
1701 | matching-branch Z |
1702 | EOF | |
1703 | ' | |
1704 | ||
acb658fe | 1705 | test_expect_success 'git checkout - for -b with --no-track, complete local branches only' ' |
7f59d604 | 1706 | test_completion "git checkout --no-track -b " <<-\EOF |
00076181 | 1707 | main Z |
7f59d604 JK |
1708 | matching-branch Z |
1709 | EOF | |
1710 | ' | |
1711 | ||
acb658fe | 1712 | test_expect_success 'git checkout - for -B with --no-track, complete local branches only' ' |
7f59d604 | 1713 | test_completion "git checkout --no-track -B " <<-\EOF |
00076181 | 1714 | main Z |
7f59d604 JK |
1715 | matching-branch Z |
1716 | EOF | |
1717 | ' | |
1718 | ||
68d97c7f | 1719 | test_expect_success 'git switch - with --orphan completes local branch names and unique remote branch names' ' |
c81ca56b JK |
1720 | test_completion "git switch --orphan " <<-\EOF |
1721 | branch-in-other Z | |
00076181 JS |
1722 | main Z |
1723 | main-in-other Z | |
c81ca56b JK |
1724 | matching-branch Z |
1725 | EOF | |
1726 | ' | |
1727 | ||
91439928 | 1728 | test_expect_success 'git switch - --orphan with branch already provided completes nothing else' ' |
00076181 | 1729 | test_completion "git switch --orphan main " <<-\EOF |
c81ca56b JK |
1730 | |
1731 | EOF | |
1732 | ' | |
1733 | ||
91439928 | 1734 | test_expect_success 'git checkout - with --orphan completes local branch names and unique remote branch names' ' |
c81ca56b JK |
1735 | test_completion "git checkout --orphan " <<-\EOF |
1736 | branch-in-other Z | |
00076181 JS |
1737 | main Z |
1738 | main-in-other Z | |
c81ca56b JK |
1739 | matching-branch Z |
1740 | EOF | |
1741 | ' | |
1742 | ||
91439928 | 1743 | test_expect_success 'git checkout - --orphan with branch already provided completes local refs for a start-point' ' |
00076181 | 1744 | test_completion "git checkout --orphan main " <<-\EOF |
c81ca56b | 1745 | HEAD Z |
00076181 | 1746 | main Z |
c81ca56b JK |
1747 | matching-branch Z |
1748 | matching-tag Z | |
1749 | other/branch-in-other Z | |
00076181 | 1750 | other/main-in-other Z |
c81ca56b JK |
1751 | EOF |
1752 | ' | |
1753 | ||
fb9cd420 SG |
1754 | test_expect_success 'teardown after ref completion' ' |
1755 | git branch -d matching-branch && | |
1756 | git tag -d matching-tag && | |
1757 | git remote remove other | |
1758 | ' | |
1759 | ||
7d314073 SG |
1760 | |
1761 | test_path_completion () | |
1762 | { | |
165293af | 1763 | test $# = 2 || BUG "not 2 parameters to test_path_completion" |
7d314073 SG |
1764 | |
1765 | local cur="$1" expected="$2" | |
1766 | echo "$expected" >expected && | |
1767 | ( | |
1768 | # In the following tests calling this function we only | |
1769 | # care about how __git_complete_index_file() deals with | |
1770 | # unusual characters in path names. By requesting only | |
7a40cf15 | 1771 | # untracked files we do not have to bother adding any |
7d314073 SG |
1772 | # paths to the index in those tests. |
1773 | __git_complete_index_file --others && | |
1774 | print_comp | |
1775 | ) && | |
1776 | test_cmp expected out | |
1777 | } | |
1778 | ||
1779 | test_expect_success 'setup for path completion tests' ' | |
1780 | mkdir simple-dir \ | |
1781 | "spaces in dir" \ | |
1782 | árvíztűrő && | |
1783 | touch simple-dir/simple-file \ | |
1784 | "spaces in dir/spaces in file" \ | |
1785 | "árvíztűrő/Сайн яваарай" && | |
1786 | if test_have_prereq !MINGW && | |
1787 | mkdir BS\\dir \ | |
1788 | '$'separators\034in\035dir'' && | |
1789 | touch BS\\dir/DQ\"file \ | |
1790 | '$'separators\034in\035dir/sep\036in\037file'' | |
1791 | then | |
6ec63305 | 1792 | test_set_prereq FUNNIERNAMES |
7d314073 SG |
1793 | else |
1794 | rm -rf BS\\dir '$'separators\034in\035dir'' | |
1795 | fi | |
1796 | ' | |
1797 | ||
1798 | test_expect_success '__git_complete_index_file - simple' ' | |
1799 | test_path_completion simple simple-dir && # Bash is supposed to | |
1800 | # add the trailing /. | |
1801 | test_path_completion simple-dir/simple simple-dir/simple-file | |
1802 | ' | |
1803 | ||
1804 | test_expect_success \ | |
1805 | '__git_complete_index_file - escaped characters on cmdline' ' | |
1806 | test_path_completion spac "spaces in dir" && # Bash will turn this | |
1807 | # into "spaces\ in\ dir" | |
1808 | test_path_completion "spaces\\ i" \ | |
1809 | "spaces in dir" && | |
1810 | test_path_completion "spaces\\ in\\ dir/s" \ | |
1811 | "spaces in dir/spaces in file" && | |
1812 | test_path_completion "spaces\\ in\\ dir/spaces\\ i" \ | |
1813 | "spaces in dir/spaces in file" | |
1814 | ' | |
1815 | ||
1816 | test_expect_success \ | |
1817 | '__git_complete_index_file - quoted characters on cmdline' ' | |
1818 | # Testing with an opening but without a corresponding closing | |
1819 | # double quote is important. | |
1820 | test_path_completion \"spac "spaces in dir" && | |
1821 | test_path_completion "\"spaces i" \ | |
1822 | "spaces in dir" && | |
1823 | test_path_completion "\"spaces in dir/s" \ | |
1824 | "spaces in dir/spaces in file" && | |
1825 | test_path_completion "\"spaces in dir/spaces i" \ | |
1826 | "spaces in dir/spaces in file" | |
1827 | ' | |
1828 | ||
1829 | test_expect_success '__git_complete_index_file - UTF-8 in ls-files output' ' | |
1830 | test_path_completion á árvíztűrő && | |
1831 | test_path_completion árvíztűrő/С "árvíztűrő/Сайн яваарай" | |
1832 | ' | |
1833 | ||
6ec63305 | 1834 | test_expect_success FUNNIERNAMES \ |
7d314073 SG |
1835 | '__git_complete_index_file - C-style escapes in ls-files output' ' |
1836 | test_path_completion BS \ | |
1837 | BS\\dir && | |
1838 | test_path_completion BS\\\\d \ | |
1839 | BS\\dir && | |
1840 | test_path_completion BS\\\\dir/DQ \ | |
1841 | BS\\dir/DQ\"file && | |
1842 | test_path_completion BS\\\\dir/DQ\\\"f \ | |
1843 | BS\\dir/DQ\"file | |
1844 | ' | |
1845 | ||
6ec63305 | 1846 | test_expect_success FUNNIERNAMES \ |
7d314073 SG |
1847 | '__git_complete_index_file - \nnn-escaped characters in ls-files output' ' |
1848 | test_path_completion sep '$'separators\034in\035dir'' && | |
1849 | test_path_completion '$'separators\034i'' \ | |
1850 | '$'separators\034in\035dir'' && | |
1851 | test_path_completion '$'separators\034in\035dir/sep'' \ | |
1852 | '$'separators\034in\035dir/sep\036in\037file'' && | |
1853 | test_path_completion '$'separators\034in\035dir/sep\036i'' \ | |
1854 | '$'separators\034in\035dir/sep\036in\037file'' | |
1855 | ' | |
1856 | ||
1857 | test_expect_success FUNNYNAMES \ | |
1858 | '__git_complete_index_file - removing repeated quoted path components' ' | |
1859 | test_when_finished rm -r repeated-quoted && | |
1860 | mkdir repeated-quoted && # A directory whose name in itself | |
1861 | # would not be quoted ... | |
1862 | >repeated-quoted/0-file && | |
1863 | >repeated-quoted/1\"file && # ... but here the file makes the | |
1864 | # dirname quoted ... | |
1865 | >repeated-quoted/2-file && | |
1866 | >repeated-quoted/3\"file && # ... and here, too. | |
1867 | ||
1868 | # Still, we shold only list the directory name only once. | |
1869 | test_path_completion repeated repeated-quoted | |
1870 | ' | |
1871 | ||
1872 | test_expect_success 'teardown after path completion tests' ' | |
1873 | rm -rf simple-dir "spaces in dir" árvíztűrő \ | |
1874 | BS\\dir '$'separators\034in\035dir'' | |
1875 | ' | |
1876 | ||
2712e915 SG |
1877 | test_expect_success '__git_find_on_cmdline - single match' ' |
1878 | echo list >expect && | |
1879 | ( | |
1880 | words=(git command --opt list) && | |
1881 | cword=${#words[@]} && | |
1882 | __git_find_on_cmdline "add list remove" >actual | |
1883 | ) && | |
1884 | test_cmp expect actual | |
1885 | ' | |
1886 | ||
1887 | test_expect_success '__git_find_on_cmdline - multiple matches' ' | |
1888 | echo remove >expect && | |
1889 | ( | |
1890 | words=(git command -o --opt remove list add) && | |
1891 | cword=${#words[@]} && | |
1892 | __git_find_on_cmdline "add list remove" >actual | |
1893 | ) && | |
1894 | test_cmp expect actual | |
1895 | ' | |
1896 | ||
1897 | test_expect_success '__git_find_on_cmdline - no match' ' | |
1898 | ( | |
1899 | words=(git command --opt branch) && | |
1900 | cword=${#words[@]} && | |
1901 | __git_find_on_cmdline "add list remove" >actual | |
1902 | ) && | |
1903 | test_must_be_empty actual | |
1904 | ' | |
7d314073 | 1905 | |
367efd54 SG |
1906 | test_expect_success '__git_find_on_cmdline - single match with index' ' |
1907 | echo "3 list" >expect && | |
1908 | ( | |
1909 | words=(git command --opt list) && | |
1910 | cword=${#words[@]} && | |
1911 | __git_find_on_cmdline --show-idx "add list remove" >actual | |
1912 | ) && | |
1913 | test_cmp expect actual | |
1914 | ' | |
1915 | ||
1916 | test_expect_success '__git_find_on_cmdline - multiple matches with index' ' | |
1917 | echo "4 remove" >expect && | |
1918 | ( | |
1919 | words=(git command -o --opt remove list add) && | |
1920 | cword=${#words[@]} && | |
1921 | __git_find_on_cmdline --show-idx "add list remove" >actual | |
1922 | ) && | |
1923 | test_cmp expect actual | |
1924 | ' | |
1925 | ||
1926 | test_expect_success '__git_find_on_cmdline - no match with index' ' | |
1927 | ( | |
1928 | words=(git command --opt branch) && | |
1929 | cword=${#words[@]} && | |
1930 | __git_find_on_cmdline --show-idx "add list remove" >actual | |
1931 | ) && | |
1932 | test_must_be_empty actual | |
1933 | ' | |
7d314073 | 1934 | |
12bdc880 SG |
1935 | test_expect_success '__git_get_config_variables' ' |
1936 | cat >expect <<-EOF && | |
1937 | name-1 | |
1938 | name-2 | |
1939 | EOF | |
1940 | test_config interesting.name-1 good && | |
1941 | test_config interesting.name-2 good && | |
1942 | test_config subsection.interesting.name-3 bad && | |
1943 | __git_get_config_variables interesting >actual && | |
1944 | test_cmp expect actual | |
1945 | ' | |
1946 | ||
e8f9e428 SG |
1947 | test_expect_success '__git_pretty_aliases' ' |
1948 | cat >expect <<-EOF && | |
1949 | author | |
1950 | hash | |
1951 | EOF | |
1952 | test_config pretty.author "%an %ae" && | |
1953 | test_config pretty.hash %H && | |
1954 | __git_pretty_aliases >actual && | |
1955 | test_cmp expect actual | |
1956 | ' | |
1957 | ||
5c293a6b | 1958 | test_expect_success 'basic' ' |
cdbff7d6 | 1959 | run_completion "git " && |
5c293a6b FC |
1960 | # built-in |
1961 | grep -q "^add \$" out && | |
1962 | # script | |
483e8611 | 1963 | grep -q "^rebase \$" out && |
5c293a6b FC |
1964 | # plumbing |
1965 | ! grep -q "^ls-files \$" out && | |
1966 | ||
483e8611 EN |
1967 | run_completion "git r" && |
1968 | ! grep -q -v "^r" out | |
5c293a6b FC |
1969 | ' |
1970 | ||
1971 | test_expect_success 'double dash "git" itself' ' | |
2fbaf813 | 1972 | test_completion "git --" <<-\EOF |
5c293a6b FC |
1973 | --paginate Z |
1974 | --no-pager Z | |
1975 | --git-dir= | |
1976 | --bare Z | |
1977 | --version Z | |
1978 | --exec-path Z | |
3ffcd086 | 1979 | --exec-path= |
5c293a6b | 1980 | --html-path Z |
66fb37d0 | 1981 | --man-path Z |
69ef3c02 | 1982 | --info-path Z |
5c293a6b FC |
1983 | --work-tree= |
1984 | --namespace= | |
69ef3c02 | 1985 | --no-replace-objects Z |
5c293a6b FC |
1986 | --help Z |
1987 | EOF | |
5c293a6b FC |
1988 | ' |
1989 | ||
1990 | test_expect_success 'double dash "git checkout"' ' | |
2fbaf813 | 1991 | test_completion "git checkout --" <<-\EOF |
5c293a6b | 1992 | --quiet Z |
77afafb2 NTND |
1993 | --detach Z |
1994 | --track Z | |
1995 | --orphan=Z | |
5c293a6b FC |
1996 | --ours Z |
1997 | --theirs Z | |
5c293a6b | 1998 | --merge Z |
77afafb2 | 1999 | --conflict=Z |
5c293a6b | 2000 | --patch Z |
6357d9d0 | 2001 | --ignore-skip-worktree-bits Z |
77afafb2 | 2002 | --ignore-other-worktrees Z |
6357d9d0 | 2003 | --recurse-submodules Z |
77afafb2 | 2004 | --progress Z |
be4908f1 NTND |
2005 | --guess Z |
2006 | --no-guess Z | |
b221b5ab | 2007 | --no-... Z |
091e04bc | 2008 | --overlay Z |
a9aecc7a AM |
2009 | --pathspec-file-nul Z |
2010 | --pathspec-from-file=Z | |
5c293a6b | 2011 | EOF |
5c293a6b FC |
2012 | ' |
2013 | ||
69ef3c02 FC |
2014 | test_expect_success 'general options' ' |
2015 | test_completion "git --ver" "--version " && | |
2016 | test_completion "git --hel" "--help " && | |
2fbaf813 | 2017 | test_completion "git --exe" <<-\EOF && |
3ffcd086 JN |
2018 | --exec-path Z |
2019 | --exec-path= | |
2020 | EOF | |
69ef3c02 FC |
2021 | test_completion "git --htm" "--html-path " && |
2022 | test_completion "git --pag" "--paginate " && | |
2023 | test_completion "git --no-p" "--no-pager " && | |
2024 | test_completion "git --git" "--git-dir=" && | |
2025 | test_completion "git --wor" "--work-tree=" && | |
2026 | test_completion "git --nam" "--namespace=" && | |
2027 | test_completion "git --bar" "--bare " && | |
2028 | test_completion "git --inf" "--info-path " && | |
2029 | test_completion "git --no-r" "--no-replace-objects " | |
2030 | ' | |
911d5da6 SG |
2031 | |
2032 | test_expect_success 'general options plus command' ' | |
2033 | test_completion "git --version check" "checkout " && | |
2034 | test_completion "git --paginate check" "checkout " && | |
2035 | test_completion "git --git-dir=foo check" "checkout " && | |
2036 | test_completion "git --bare check" "checkout " && | |
911d5da6 SG |
2037 | test_completion "git --exec-path=foo check" "checkout " && |
2038 | test_completion "git --html-path check" "checkout " && | |
2039 | test_completion "git --no-pager check" "checkout " && | |
2040 | test_completion "git --work-tree=foo check" "checkout " && | |
2041 | test_completion "git --namespace=foo check" "checkout " && | |
2042 | test_completion "git --paginate check" "checkout " && | |
2043 | test_completion "git --info-path check" "checkout " && | |
336d694c SG |
2044 | test_completion "git --no-replace-objects check" "checkout " && |
2045 | test_completion "git --git-dir some/path check" "checkout " && | |
2046 | test_completion "git -c conf.var=value check" "checkout " && | |
2047 | test_completion "git -C some/path check" "checkout " && | |
2048 | test_completion "git --work-tree some/path check" "checkout " && | |
2049 | test_completion "git --namespace name/space check" "checkout " | |
911d5da6 SG |
2050 | ' |
2051 | ||
50478223 JH |
2052 | test_expect_success 'git --help completion' ' |
2053 | test_completion "git --help ad" "add " && | |
2054 | test_completion "git --help core" "core-tutorial " | |
2055 | ' | |
2056 | ||
057ab54b | 2057 | test_expect_success 'completion.commands removes multiple commands' ' |
402e3e15 TZ |
2058 | test_config completion.commands "-cherry -mergetool" && |
2059 | git --list-cmds=list-mainporcelain,list-complete,config >out && | |
2060 | ! grep -E "^(cherry|mergetool)$" out | |
2061 | ' | |
2062 | ||
fb9cd420 | 2063 | test_expect_success 'setup for integration tests' ' |
49ba92b4 JK |
2064 | echo content >file1 && |
2065 | echo more >file2 && | |
e5edbef4 | 2066 | git add file1 file2 && |
49ba92b4 JK |
2067 | git commit -m one && |
2068 | git branch mybranch && | |
2069 | git tag mytag | |
2070 | ' | |
2071 | ||
2072 | test_expect_success 'checkout completes ref names' ' | |
2fbaf813 | 2073 | test_completion "git checkout m" <<-\EOF |
00076181 | 2074 | main Z |
43ea0812 FC |
2075 | mybranch Z |
2076 | mytag Z | |
49ba92b4 JK |
2077 | EOF |
2078 | ' | |
2079 | ||
80ac0744 SG |
2080 | test_expect_success 'git -C <path> checkout uses the right repo' ' |
2081 | test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF | |
2082 | branch-in-other Z | |
2083 | EOF | |
2084 | ' | |
2085 | ||
49ba92b4 | 2086 | test_expect_success 'show completes all refs' ' |
2fbaf813 | 2087 | test_completion "git show m" <<-\EOF |
00076181 | 2088 | main Z |
43ea0812 FC |
2089 | mybranch Z |
2090 | mytag Z | |
49ba92b4 JK |
2091 | EOF |
2092 | ' | |
2093 | ||
2094 | test_expect_success '<ref>: completes paths' ' | |
2fbaf813 | 2095 | test_completion "git show mytag:f" <<-\EOF |
6d54f528 CY |
2096 | file1Z |
2097 | file2Z | |
49ba92b4 JK |
2098 | EOF |
2099 | ' | |
2100 | ||
bafed0df JK |
2101 | test_expect_success 'complete tree filename with spaces' ' |
2102 | echo content >"name with spaces" && | |
e5edbef4 | 2103 | git add "name with spaces" && |
bafed0df | 2104 | git commit -m spaces && |
2fbaf813 | 2105 | test_completion "git show HEAD:nam" <<-\EOF |
6d54f528 | 2106 | name with spacesZ |
bafed0df JK |
2107 | EOF |
2108 | ' | |
2109 | ||
7d13e0a3 | 2110 | test_expect_success 'complete tree filename with metacharacters' ' |
bafed0df | 2111 | echo content >"name with \${meta}" && |
e5edbef4 | 2112 | git add "name with \${meta}" && |
bafed0df | 2113 | git commit -m meta && |
2fbaf813 | 2114 | test_completion "git show HEAD:nam" <<-\EOF |
6d54f528 CY |
2115 | name with ${meta}Z |
2116 | name with spacesZ | |
bafed0df JK |
2117 | EOF |
2118 | ' | |
2119 | ||
0365b9ec | 2120 | test_expect_success PERL 'send-email' ' |
bf8e65b3 DL |
2121 | test_completion "git send-email --cov" <<-\EOF && |
2122 | --cover-from-description=Z | |
2123 | --cover-letter Z | |
2124 | EOF | |
00076181 | 2125 | test_completion "git send-email ma" "main " |
2f65494d FC |
2126 | ' |
2127 | ||
ddf07bdd FC |
2128 | test_expect_success 'complete files' ' |
2129 | git init tmp && cd tmp && | |
2130 | test_when_finished "cd .. && rm -rf tmp" && | |
2131 | ||
2132 | echo "expected" > .gitignore && | |
2133 | echo "out" >> .gitignore && | |
9703797c | 2134 | echo "out_sorted" >> .gitignore && |
ddf07bdd FC |
2135 | |
2136 | git add .gitignore && | |
2137 | test_completion "git commit " ".gitignore" && | |
2138 | ||
2139 | git commit -m ignore && | |
2140 | ||
2141 | touch new && | |
2142 | test_completion "git add " "new" && | |
2143 | ||
2144 | git add new && | |
2145 | git commit -a -m new && | |
2146 | test_completion "git add " "" && | |
2147 | ||
2148 | git mv new modified && | |
2149 | echo modify > modified && | |
2150 | test_completion "git add " "modified" && | |
2151 | ||
c0af173a EN |
2152 | mkdir -p some/deep && |
2153 | touch some/deep/path && | |
2154 | test_completion "git add some/" "some/deep" && | |
2155 | git clean -f some && | |
2156 | ||
ddf07bdd FC |
2157 | touch untracked && |
2158 | ||
2159 | : TODO .gitignore should not be here && | |
2160 | test_completion "git rm " <<-\EOF && | |
2161 | .gitignore | |
2162 | modified | |
2163 | EOF | |
2164 | ||
2165 | test_completion "git clean " "untracked" && | |
2166 | ||
2167 | : TODO .gitignore should not be here && | |
2168 | test_completion "git mv " <<-\EOF && | |
2169 | .gitignore | |
2170 | modified | |
2171 | EOF | |
2172 | ||
2173 | mkdir dir && | |
2174 | touch dir/file-in-dir && | |
2175 | git add dir/file-in-dir && | |
2176 | git commit -m dir && | |
2177 | ||
2178 | mkdir untracked-dir && | |
2179 | ||
2180 | : TODO .gitignore should not be here && | |
2181 | test_completion "git mv modified " <<-\EOF && | |
2182 | .gitignore | |
2183 | dir | |
2184 | modified | |
2185 | untracked | |
2186 | untracked-dir | |
2187 | EOF | |
2188 | ||
2189 | test_completion "git commit " "modified" && | |
2190 | ||
2191 | : TODO .gitignore should not be here && | |
8fb26872 | 2192 | test_completion "git ls-files " <<-\EOF && |
ddf07bdd FC |
2193 | .gitignore |
2194 | dir | |
2195 | modified | |
2196 | EOF | |
2197 | ||
2198 | touch momified && | |
2199 | test_completion "git add mom" "momified" | |
2200 | ' | |
2201 | ||
9414938c FC |
2202 | test_expect_success "simple alias" ' |
2203 | test_config alias.co checkout && | |
2204 | test_completion "git co m" <<-\EOF | |
00076181 | 2205 | main Z |
9414938c FC |
2206 | mybranch Z |
2207 | mytag Z | |
2208 | EOF | |
2209 | ' | |
2210 | ||
2211 | test_expect_success "recursive alias" ' | |
2212 | test_config alias.co checkout && | |
2213 | test_config alias.cod "co --detached" && | |
2214 | test_completion "git cod m" <<-\EOF | |
00076181 | 2215 | main Z |
9414938c FC |
2216 | mybranch Z |
2217 | mytag Z | |
2218 | EOF | |
2219 | ' | |
2220 | ||
56f24e80 SP |
2221 | test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" ' |
2222 | test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" && | |
2223 | test_completion "git co m" <<-\EOF | |
00076181 | 2224 | main Z |
56f24e80 SP |
2225 | mybranch Z |
2226 | mytag Z | |
2227 | EOF | |
2228 | ' | |
2229 | ||
2230 | test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' ' | |
2231 | test_config alias.co "!f () { VAR=val git checkout ... ; } f" && | |
2232 | test_completion "git co m" <<-\EOF | |
00076181 | 2233 | main Z |
56f24e80 SP |
2234 | mybranch Z |
2235 | mytag Z | |
2236 | EOF | |
2237 | ' | |
2238 | ||
2239 | test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' ' | |
2240 | test_config alias.co "!f() { : git checkout ; if ... } f" && | |
2241 | test_completion "git co m" <<-\EOF | |
00076181 | 2242 | main Z |
56f24e80 SP |
2243 | mybranch Z |
2244 | mytag Z | |
2245 | EOF | |
2246 | ' | |
2247 | ||
9f642a71 NTND |
2248 | test_expect_success 'completion without explicit _git_xxx function' ' |
2249 | test_completion "git version --" <<-\EOF | |
2250 | --build-options Z | |
2b1c01d2 | 2251 | --no-build-options Z |
9f642a71 NTND |
2252 | EOF |
2253 | ' | |
2254 | ||
f03efba4 FC |
2255 | test_expect_failure 'complete with tilde expansion' ' |
2256 | git init tmp && cd tmp && | |
2257 | test_when_finished "cd .. && rm -rf tmp" && | |
2258 | ||
2259 | touch ~/tmp/file && | |
2260 | ||
2261 | test_completion "git add ~/tmp/" "~/tmp/file" | |
2262 | ' | |
2263 | ||
723c1d52 ÆAB |
2264 | test_expect_success 'setup other remote for remote reference completion' ' |
2265 | git remote add other otherrepo && | |
2266 | git fetch other | |
2267 | ' | |
2268 | ||
2269 | for flag in -d --delete | |
2270 | do | |
2271 | test_expect_success "__git_complete_remote_or_refspec - push $flag other" ' | |
2272 | sed -e "s/Z$//" >expected <<-EOF && | |
00076181 | 2273 | main-in-other Z |
723c1d52 ÆAB |
2274 | EOF |
2275 | ( | |
2276 | words=(git push '$flag' other ma) && | |
2277 | cword=${#words[@]} cur=${words[cword-1]} && | |
2278 | __git_complete_remote_or_refspec && | |
2279 | print_comp | |
2280 | ) && | |
2281 | test_cmp expected out | |
2282 | ' | |
2283 | ||
2284 | test_expect_failure "__git_complete_remote_or_refspec - push other $flag" ' | |
2285 | sed -e "s/Z$//" >expected <<-EOF && | |
00076181 | 2286 | main-in-other Z |
723c1d52 ÆAB |
2287 | EOF |
2288 | ( | |
2289 | words=(git push other '$flag' ma) && | |
2290 | cword=${#words[@]} cur=${words[cword-1]} && | |
2291 | __git_complete_remote_or_refspec && | |
2292 | print_comp | |
2293 | ) && | |
2294 | test_cmp expected out | |
2295 | ' | |
2296 | done | |
2297 | ||
d9438873 | 2298 | test_expect_success 'git config - section' ' |
7a09a8f0 SG |
2299 | test_completion "git config br" <<-\EOF |
2300 | branch.Z | |
2301 | browser.Z | |
2302 | EOF | |
2303 | ' | |
2304 | ||
2305 | test_expect_success 'git config - variable name' ' | |
2306 | test_completion "git config log.d" <<-\EOF | |
2307 | log.date Z | |
2308 | log.decorate Z | |
2309 | EOF | |
2310 | ' | |
2311 | ||
2312 | test_expect_success 'git config - value' ' | |
2313 | test_completion "git config color.pager " <<-\EOF | |
2314 | false Z | |
2315 | true Z | |
2316 | EOF | |
2317 | ' | |
2318 | ||
e1e00089 SG |
2319 | test_expect_success 'git -c - section' ' |
2320 | test_completion "git -c br" <<-\EOF | |
2321 | branch.Z | |
2322 | browser.Z | |
2323 | EOF | |
2324 | ' | |
2325 | ||
2326 | test_expect_success 'git -c - variable name' ' | |
2327 | test_completion "git -c log.d" <<-\EOF | |
2328 | log.date=Z | |
2329 | log.decorate=Z | |
2330 | EOF | |
2331 | ' | |
2332 | ||
dd334728 SG |
2333 | test_expect_success 'git -c - value' ' |
2334 | test_completion "git -c color.pager=" <<-\EOF | |
5af9d5f6 SG |
2335 | false Z |
2336 | true Z | |
2337 | EOF | |
2338 | ' | |
2339 | ||
2340 | test_expect_success 'git clone --config= - section' ' | |
2341 | test_completion "git clone --config=br" <<-\EOF | |
2342 | branch.Z | |
2343 | browser.Z | |
2344 | EOF | |
2345 | ' | |
2346 | ||
2347 | test_expect_success 'git clone --config= - variable name' ' | |
2348 | test_completion "git clone --config=log.d" <<-\EOF | |
2349 | log.date=Z | |
2350 | log.decorate=Z | |
2351 | EOF | |
2352 | ' | |
2353 | ||
2354 | test_expect_success 'git clone --config= - value' ' | |
2355 | test_completion "git clone --config=color.pager=" <<-\EOF | |
dd334728 SG |
2356 | false Z |
2357 | true Z | |
2358 | EOF | |
2359 | ' | |
2360 | ||
8b0eaa41 SG |
2361 | test_expect_success 'sourcing the completion script clears cached commands' ' |
2362 | __git_compute_all_commands && | |
2363 | verbose test -n "$__git_all_commands" && | |
2364 | . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && | |
2365 | verbose test -z "$__git_all_commands" | |
2366 | ' | |
2367 | ||
6cdccfce | 2368 | test_expect_success 'sourcing the completion script clears cached merge strategies' ' |
8b0eaa41 SG |
2369 | __git_compute_merge_strategies && |
2370 | verbose test -n "$__git_merge_strategies" && | |
2371 | . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && | |
2372 | verbose test -z "$__git_merge_strategies" | |
2373 | ' | |
2374 | ||
2375 | test_expect_success 'sourcing the completion script clears cached --options' ' | |
2376 | __gitcomp_builtin checkout && | |
2377 | verbose test -n "$__gitcomp_builtin_checkout" && | |
2378 | __gitcomp_builtin notes_edit && | |
2379 | verbose test -n "$__gitcomp_builtin_notes_edit" && | |
2380 | . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && | |
2381 | verbose test -z "$__gitcomp_builtin_checkout" && | |
2382 | verbose test -z "$__gitcomp_builtin_notes_edit" | |
2383 | ' | |
2384 | ||
0e02bdc1 FC |
2385 | test_expect_success '__git_complete' ' |
2386 | unset -f __git_wrap__git_main && | |
5a067ba9 | 2387 | |
0e02bdc1 FC |
2388 | __git_complete foo __git_main && |
2389 | __git_have_func __git_wrap__git_main && | |
5a067ba9 FC |
2390 | unset -f __git_wrap__git_main && |
2391 | ||
0e02bdc1 | 2392 | __git_complete gf _git_fetch && |
5a067ba9 FC |
2393 | __git_have_func __git_wrap_git_fetch && |
2394 | ||
2395 | __git_complete foo git && | |
2396 | __git_have_func __git_wrap__git_main && | |
2397 | unset -f __git_wrap__git_main && | |
2398 | ||
2399 | __git_complete gd git_diff && | |
2400 | __git_have_func __git_wrap_git_diff && | |
2401 | ||
2402 | test_must_fail __git_complete ga missing | |
0e02bdc1 FC |
2403 | ' |
2404 | ||
5c293a6b | 2405 | test_done |