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