]>
Commit | Line | Data |
---|---|---|
5c293a6b FC |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2012 Felipe Contreras | |
4 | # | |
5 | ||
5c293a6b FC |
6 | test_description='test bash completion' |
7 | ||
f8891cfa | 8 | . ./lib-bash.sh |
5c293a6b FC |
9 | |
10 | complete () | |
11 | { | |
12 | # do nothing | |
13 | return 0 | |
14 | } | |
15 | ||
50478223 JH |
16 | # Be careful when updating this list: |
17 | # | |
18 | # (1) The build tree may have build artifact from different branch, or | |
19 | # the user's $PATH may have a random executable that may begin | |
20 | # with "git-check" that are not part of the subcommands this build | |
21 | # will ship, e.g. "check-ignore". The tests for completion for | |
22 | # subcommand names tests how "check" is expanded; we limit the | |
23 | # possible candidates to "checkout" and "check-attr" to make sure | |
24 | # "check-attr", which is known by the filter function as a | |
25 | # subcommand to be thrown out, while excluding other random files | |
26 | # that happen to begin with "check" to avoid letting them get in | |
27 | # the way. | |
28 | # | |
29 | # (2) A test makes sure that common subcommands are included in the | |
30 | # completion for "git <TAB>", and a plumbing is excluded. "add", | |
31 | # "filter-branch" and "ls-files" are listed for this. | |
32 | ||
33 | GIT_TESTING_COMMAND_COMPLETION='add checkout check-attr filter-branch ls-files' | |
34 | ||
5c293a6b FC |
35 | . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" |
36 | ||
37 | # We don't need this function to actually join words or do anything special. | |
38 | # Also, it's cleaner to avoid touching bash's internal completion variables. | |
39 | # So let's override it with a minimal version for testing purposes. | |
40 | _get_comp_words_by_ref () | |
41 | { | |
42 | while [ $# -gt 0 ]; do | |
43 | case "$1" in | |
44 | cur) | |
45 | cur=${_words[_cword]} | |
46 | ;; | |
47 | prev) | |
48 | prev=${_words[_cword-1]} | |
49 | ;; | |
50 | words) | |
51 | words=("${_words[@]}") | |
52 | ;; | |
53 | cword) | |
54 | cword=$_cword | |
55 | ;; | |
56 | esac | |
57 | shift | |
58 | done | |
59 | } | |
60 | ||
61 | print_comp () | |
62 | { | |
63 | local IFS=$'\n' | |
64 | echo "${COMPREPLY[*]}" > out | |
65 | } | |
66 | ||
67 | run_completion () | |
68 | { | |
69 | local -a COMPREPLY _words | |
70 | local _cword | |
71 | _words=( $1 ) | |
0ef09702 | 72 | test "${1: -1}" = ' ' && _words[${#_words[@]}+1]='' |
5c293a6b | 73 | (( _cword = ${#_words[@]} - 1 )) |
93b291e0 | 74 | __git_wrap__git_main && print_comp |
5c293a6b FC |
75 | } |
76 | ||
701ecdf1 FC |
77 | # Test high-level completion |
78 | # Arguments are: | |
79 | # 1: typed text so far (cur) | |
80 | # 2: expected completion | |
5c293a6b FC |
81 | test_completion () |
82 | { | |
2fbaf813 FC |
83 | if test $# -gt 1 |
84 | then | |
85 | printf '%s\n' "$2" >expected | |
86 | else | |
87 | sed -e 's/Z$//' >expected | |
88 | fi && | |
701ecdf1 | 89 | run_completion "$1" && |
5c293a6b FC |
90 | test_cmp expected out |
91 | } | |
92 | ||
e4615238 FC |
93 | # Test __gitcomp. |
94 | # The first argument is the typed text so far (cur); the rest are | |
95 | # passed to __gitcomp. Expected output comes is read from the | |
96 | # standard input, like test_completion(). | |
97 | test_gitcomp () | |
49ba92b4 | 98 | { |
17393033 | 99 | local -a COMPREPLY && |
e4615238 | 100 | sed -e 's/Z$//' >expected && |
eac90623 | 101 | local cur="$1" && |
17393033 FC |
102 | shift && |
103 | __gitcomp "$@" && | |
104 | print_comp && | |
74a8c849 | 105 | test_cmp expected out |
49ba92b4 JK |
106 | } |
107 | ||
43369a22 FC |
108 | # Test __gitcomp_nl |
109 | # Arguments are: | |
110 | # 1: current word (cur) | |
111 | # -: the rest are passed to __gitcomp_nl | |
112 | test_gitcomp_nl () | |
113 | { | |
114 | local -a COMPREPLY && | |
115 | sed -e 's/Z$//' >expected && | |
eac90623 | 116 | local cur="$1" && |
43369a22 FC |
117 | shift && |
118 | __gitcomp_nl "$@" && | |
119 | print_comp && | |
120 | test_cmp expected out | |
121 | } | |
122 | ||
123 | invalid_variable_name='${foo.bar}' | |
124 | ||
c9a102e8 SG |
125 | actual="$TRASH_DIRECTORY/actual" |
126 | ||
f6114408 SG |
127 | if test_have_prereq MINGW |
128 | then | |
129 | ROOT="$(pwd -W)" | |
130 | else | |
131 | ROOT="$(pwd)" | |
132 | fi | |
133 | ||
fad9484f | 134 | test_expect_success 'setup for __git_find_repo_path/__gitdir tests' ' |
c9a102e8 | 135 | mkdir -p subdir/subsubdir && |
fad9484f | 136 | mkdir -p non-repo && |
c9a102e8 SG |
137 | git init otherrepo |
138 | ' | |
139 | ||
fad9484f | 140 | test_expect_success '__git_find_repo_path - from command line (through $__git_dir)' ' |
f6114408 | 141 | echo "$ROOT/otherrepo/.git" >expected && |
c9a102e8 | 142 | ( |
f6114408 | 143 | __git_dir="$ROOT/otherrepo/.git" && |
fad9484f SG |
144 | __git_find_repo_path && |
145 | echo "$__git_repo_path" >"$actual" | |
beb6ee71 | 146 | ) && |
c9a102e8 SG |
147 | test_cmp expected "$actual" |
148 | ' | |
149 | ||
fad9484f | 150 | test_expect_success '__git_find_repo_path - .git directory in cwd' ' |
c9a102e8 | 151 | echo ".git" >expected && |
beb6ee71 | 152 | ( |
fad9484f SG |
153 | __git_find_repo_path && |
154 | echo "$__git_repo_path" >"$actual" | |
beb6ee71 | 155 | ) && |
c9a102e8 SG |
156 | test_cmp expected "$actual" |
157 | ' | |
158 | ||
fad9484f | 159 | test_expect_success '__git_find_repo_path - .git directory in parent' ' |
f6114408 | 160 | echo "$ROOT/.git" >expected && |
c9a102e8 SG |
161 | ( |
162 | cd subdir/subsubdir && | |
fad9484f SG |
163 | __git_find_repo_path && |
164 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
165 | ) && |
166 | test_cmp expected "$actual" | |
167 | ' | |
168 | ||
fad9484f | 169 | test_expect_success '__git_find_repo_path - cwd is a .git directory' ' |
c9a102e8 SG |
170 | echo "." >expected && |
171 | ( | |
172 | cd .git && | |
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 - parent is a .git directory' ' |
f6114408 | 180 | echo "$ROOT/.git" >expected && |
c9a102e8 SG |
181 | ( |
182 | cd .git/refs/heads && | |
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 - $GIT_DIR set while .git directory in cwd' ' |
f6114408 | 190 | echo "$ROOT/otherrepo/.git" >expected && |
c9a102e8 | 191 | ( |
f6114408 | 192 | GIT_DIR="$ROOT/otherrepo/.git" && |
c9a102e8 | 193 | export GIT_DIR && |
fad9484f SG |
194 | __git_find_repo_path && |
195 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
196 | ) && |
197 | test_cmp expected "$actual" | |
198 | ' | |
199 | ||
fad9484f | 200 | test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in parent' ' |
f6114408 | 201 | echo "$ROOT/otherrepo/.git" >expected && |
c9a102e8 | 202 | ( |
f6114408 | 203 | GIT_DIR="$ROOT/otherrepo/.git" && |
c9a102e8 SG |
204 | export GIT_DIR && |
205 | cd subdir && | |
fad9484f SG |
206 | __git_find_repo_path && |
207 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
208 | ) && |
209 | test_cmp expected "$actual" | |
210 | ' | |
211 | ||
fad9484f | 212 | test_expect_success '__git_find_repo_path - from command line while "git -C"' ' |
80ac0744 SG |
213 | echo "$ROOT/.git" >expected && |
214 | ( | |
215 | __git_dir="$ROOT/.git" && | |
216 | __git_C_args=(-C otherrepo) && | |
fad9484f SG |
217 | __git_find_repo_path && |
218 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
219 | ) && |
220 | test_cmp expected "$actual" | |
221 | ' | |
222 | ||
fad9484f | 223 | test_expect_success '__git_find_repo_path - relative dir from command line and "git -C"' ' |
80ac0744 SG |
224 | echo "$ROOT/otherrepo/.git" >expected && |
225 | ( | |
226 | cd subdir && | |
227 | __git_dir="otherrepo/.git" && | |
228 | __git_C_args=(-C ..) && | |
fad9484f SG |
229 | __git_find_repo_path && |
230 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
231 | ) && |
232 | test_cmp expected "$actual" | |
233 | ' | |
234 | ||
fad9484f | 235 | test_expect_success '__git_find_repo_path - $GIT_DIR set while "git -C"' ' |
80ac0744 SG |
236 | echo "$ROOT/.git" >expected && |
237 | ( | |
238 | GIT_DIR="$ROOT/.git" && | |
239 | export GIT_DIR && | |
240 | __git_C_args=(-C otherrepo) && | |
fad9484f SG |
241 | __git_find_repo_path && |
242 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
243 | ) && |
244 | test_cmp expected "$actual" | |
245 | ' | |
246 | ||
fad9484f | 247 | test_expect_success '__git_find_repo_path - relative dir in $GIT_DIR and "git -C"' ' |
80ac0744 SG |
248 | echo "$ROOT/otherrepo/.git" >expected && |
249 | ( | |
250 | cd subdir && | |
251 | GIT_DIR="otherrepo/.git" && | |
252 | export GIT_DIR && | |
253 | __git_C_args=(-C ..) && | |
fad9484f SG |
254 | __git_find_repo_path && |
255 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
256 | ) && |
257 | test_cmp expected "$actual" | |
258 | ' | |
259 | ||
fad9484f | 260 | test_expect_success '__git_find_repo_path - "git -C" while .git directory in cwd' ' |
80ac0744 SG |
261 | echo "$ROOT/otherrepo/.git" >expected && |
262 | ( | |
263 | __git_C_args=(-C otherrepo) && | |
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 cwd is a .git directory' ' |
80ac0744 SG |
271 | echo "$ROOT/otherrepo/.git" >expected && |
272 | ( | |
273 | cd .git && | |
274 | __git_C_args=(-C .. -C otherrepo) && | |
fad9484f SG |
275 | __git_find_repo_path && |
276 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
277 | ) && |
278 | test_cmp expected "$actual" | |
279 | ' | |
280 | ||
fad9484f | 281 | test_expect_success '__git_find_repo_path - "git -C" while .git directory in parent' ' |
80ac0744 SG |
282 | echo "$ROOT/otherrepo/.git" >expected && |
283 | ( | |
284 | cd subdir && | |
285 | __git_C_args=(-C .. -C otherrepo) && | |
fad9484f SG |
286 | __git_find_repo_path && |
287 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
288 | ) && |
289 | test_cmp expected "$actual" | |
290 | ' | |
291 | ||
fad9484f | 292 | test_expect_success '__git_find_repo_path - non-existing path in "git -C"' ' |
80ac0744 SG |
293 | ( |
294 | __git_C_args=(-C non-existing) && | |
fad9484f SG |
295 | test_must_fail __git_find_repo_path && |
296 | printf "$__git_repo_path" >"$actual" | |
80ac0744 SG |
297 | ) && |
298 | test_must_be_empty "$actual" | |
299 | ' | |
300 | ||
fad9484f | 301 | test_expect_success '__git_find_repo_path - non-existing path in $__git_dir' ' |
a2f03b0e SG |
302 | ( |
303 | __git_dir="non-existing" && | |
fad9484f SG |
304 | test_must_fail __git_find_repo_path && |
305 | printf "$__git_repo_path" >"$actual" | |
a2f03b0e SG |
306 | ) && |
307 | test_must_be_empty "$actual" | |
308 | ' | |
309 | ||
fad9484f | 310 | test_expect_success '__git_find_repo_path - non-existing $GIT_DIR' ' |
c9a102e8 | 311 | ( |
f6114408 | 312 | GIT_DIR="$ROOT/non-existing" && |
c9a102e8 | 313 | export GIT_DIR && |
fad9484f SG |
314 | test_must_fail __git_find_repo_path && |
315 | printf "$__git_repo_path" >"$actual" | |
8f0fa85d SG |
316 | ) && |
317 | test_must_be_empty "$actual" | |
c9a102e8 SG |
318 | ' |
319 | ||
fad9484f | 320 | test_expect_success '__git_find_repo_path - gitfile in cwd' ' |
f6114408 SG |
321 | echo "$ROOT/otherrepo/.git" >expected && |
322 | echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git && | |
c9a102e8 SG |
323 | test_when_finished "rm -f subdir/.git" && |
324 | ( | |
325 | cd subdir && | |
fad9484f SG |
326 | __git_find_repo_path && |
327 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
328 | ) && |
329 | test_cmp expected "$actual" | |
330 | ' | |
331 | ||
fad9484f | 332 | test_expect_success '__git_find_repo_path - gitfile in parent' ' |
f6114408 SG |
333 | echo "$ROOT/otherrepo/.git" >expected && |
334 | echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git && | |
c9a102e8 SG |
335 | test_when_finished "rm -f subdir/.git" && |
336 | ( | |
337 | cd subdir/subsubdir && | |
fad9484f SG |
338 | __git_find_repo_path && |
339 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
340 | ) && |
341 | test_cmp expected "$actual" | |
342 | ' | |
343 | ||
fad9484f | 344 | test_expect_success SYMLINKS '__git_find_repo_path - resulting path avoids symlinks' ' |
f6114408 | 345 | echo "$ROOT/otherrepo/.git" >expected && |
c9a102e8 SG |
346 | mkdir otherrepo/dir && |
347 | test_when_finished "rm -rf otherrepo/dir" && | |
348 | ln -s otherrepo/dir link && | |
349 | test_when_finished "rm -f link" && | |
350 | ( | |
351 | cd link && | |
fad9484f SG |
352 | __git_find_repo_path && |
353 | echo "$__git_repo_path" >"$actual" | |
354 | ) && | |
355 | test_cmp expected "$actual" | |
356 | ' | |
357 | ||
358 | test_expect_success '__git_find_repo_path - not a git repository' ' | |
359 | ( | |
360 | cd non-repo && | |
361 | GIT_CEILING_DIRECTORIES="$ROOT" && | |
362 | export GIT_CEILING_DIRECTORIES && | |
363 | test_must_fail __git_find_repo_path && | |
364 | printf "$__git_repo_path" >"$actual" | |
365 | ) && | |
366 | test_must_be_empty "$actual" | |
367 | ' | |
368 | ||
369 | test_expect_success '__gitdir - finds repo' ' | |
370 | echo "$ROOT/.git" >expected && | |
371 | ( | |
372 | cd subdir/subsubdir && | |
c9a102e8 SG |
373 | __gitdir >"$actual" |
374 | ) && | |
375 | test_cmp expected "$actual" | |
376 | ' | |
377 | ||
fad9484f SG |
378 | |
379 | test_expect_success '__gitdir - returns error when cant find repo' ' | |
380 | ( | |
381 | __git_dir="non-existing" && | |
382 | test_must_fail __gitdir >"$actual" | |
383 | ) && | |
8f0fa85d | 384 | test_must_be_empty "$actual" |
c9a102e8 SG |
385 | ' |
386 | ||
fad9484f SG |
387 | test_expect_success '__gitdir - repo as argument' ' |
388 | echo "otherrepo/.git" >expected && | |
389 | ( | |
390 | __gitdir "otherrepo" >"$actual" | |
391 | ) && | |
392 | test_cmp expected "$actual" | |
393 | ' | |
394 | ||
395 | test_expect_success '__gitdir - remote as argument' ' | |
396 | echo "remote" >expected && | |
397 | ( | |
398 | __gitdir "remote" >"$actual" | |
399 | ) && | |
400 | test_cmp expected "$actual" | |
401 | ' | |
402 | ||
fef56eb0 SG |
403 | test_expect_success '__gitcomp_direct - puts everything into COMPREPLY as-is' ' |
404 | sed -e "s/Z$//g" >expected <<-EOF && | |
405 | with-trailing-space Z | |
406 | without-trailing-spaceZ | |
407 | --option Z | |
408 | --option=Z | |
409 | $invalid_variable_name Z | |
410 | EOF | |
411 | ( | |
412 | cur=should_be_ignored && | |
413 | __gitcomp_direct "$(cat expected)" && | |
414 | print_comp | |
415 | ) && | |
416 | test_cmp expected out | |
417 | ' | |
418 | ||
74a8c849 | 419 | test_expect_success '__gitcomp - trailing space - options' ' |
e4615238 FC |
420 | test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message= |
421 | --reset-author" <<-EOF | |
74a8c849 SG |
422 | --reuse-message=Z |
423 | --reedit-message=Z | |
424 | --reset-author Z | |
425 | EOF | |
74a8c849 SG |
426 | ' |
427 | ||
428 | test_expect_success '__gitcomp - trailing space - config keys' ' | |
e4615238 FC |
429 | test_gitcomp "br" "branch. branch.autosetupmerge |
430 | branch.autosetuprebase browser." <<-\EOF | |
74a8c849 SG |
431 | branch.Z |
432 | branch.autosetupmerge Z | |
433 | branch.autosetuprebase Z | |
434 | browser.Z | |
435 | EOF | |
74a8c849 SG |
436 | ' |
437 | ||
438 | test_expect_success '__gitcomp - option parameter' ' | |
e4615238 FC |
439 | test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \ |
440 | "" "re" <<-\EOF | |
74a8c849 SG |
441 | recursive Z |
442 | resolve Z | |
443 | EOF | |
74a8c849 SG |
444 | ' |
445 | ||
446 | test_expect_success '__gitcomp - prefix' ' | |
e4615238 FC |
447 | test_gitcomp "branch.me" "remote merge mergeoptions rebase" \ |
448 | "branch.maint." "me" <<-\EOF | |
74a8c849 SG |
449 | branch.maint.merge Z |
450 | branch.maint.mergeoptions Z | |
451 | EOF | |
74a8c849 SG |
452 | ' |
453 | ||
454 | test_expect_success '__gitcomp - suffix' ' | |
e4615238 FC |
455 | test_gitcomp "branch.me" "master maint next pu" "branch." \ |
456 | "ma" "." <<-\EOF | |
74a8c849 SG |
457 | branch.master.Z |
458 | branch.maint.Z | |
459 | EOF | |
74a8c849 SG |
460 | ' |
461 | ||
7d13e0a3 | 462 | test_expect_success '__gitcomp - doesnt fail because of invalid variable name' ' |
43369a22 FC |
463 | __gitcomp "$invalid_variable_name" |
464 | ' | |
465 | ||
466 | read -r -d "" refs <<-\EOF | |
467 | maint | |
468 | master | |
469 | next | |
470 | pu | |
471 | EOF | |
472 | ||
473 | test_expect_success '__gitcomp_nl - trailing space' ' | |
474 | test_gitcomp_nl "m" "$refs" <<-EOF | |
475 | maint Z | |
476 | master Z | |
477 | EOF | |
478 | ' | |
479 | ||
480 | test_expect_success '__gitcomp_nl - prefix' ' | |
481 | test_gitcomp_nl "--fixup=m" "$refs" "--fixup=" "m" <<-EOF | |
482 | --fixup=maint Z | |
483 | --fixup=master Z | |
484 | EOF | |
485 | ' | |
486 | ||
487 | test_expect_success '__gitcomp_nl - suffix' ' | |
488 | test_gitcomp_nl "branch.ma" "$refs" "branch." "ma" "." <<-\EOF | |
489 | branch.maint.Z | |
490 | branch.master.Z | |
491 | EOF | |
492 | ' | |
493 | ||
494 | test_expect_success '__gitcomp_nl - no suffix' ' | |
495 | test_gitcomp_nl "ma" "$refs" "" "ma" "" <<-\EOF | |
496 | maintZ | |
497 | masterZ | |
498 | EOF | |
499 | ' | |
500 | ||
7d13e0a3 | 501 | test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name' ' |
43369a22 FC |
502 | __gitcomp_nl "$invalid_variable_name" |
503 | ' | |
504 | ||
2acc1940 SG |
505 | test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from config file' ' |
506 | cat >expect <<-EOF && | |
507 | remote_from_file_1 | |
508 | remote_from_file_2 | |
509 | remote_in_config_1 | |
510 | remote_in_config_2 | |
511 | EOF | |
512 | test_when_finished "rm -rf .git/remotes" && | |
513 | mkdir -p .git/remotes && | |
514 | >.git/remotes/remote_from_file_1 && | |
515 | >.git/remotes/remote_from_file_2 && | |
516 | test_when_finished "git remote remove remote_in_config_1" && | |
517 | git remote add remote_in_config_1 git://remote_1 && | |
518 | test_when_finished "git remote remove remote_in_config_2" && | |
519 | git remote add remote_in_config_2 git://remote_2 && | |
beb6ee71 SG |
520 | ( |
521 | __git_remotes >actual | |
522 | ) && | |
2acc1940 SG |
523 | test_cmp expect actual |
524 | ' | |
525 | ||
69a77596 SG |
526 | test_expect_success '__git_is_configured_remote' ' |
527 | test_when_finished "git remote remove remote_1" && | |
528 | git remote add remote_1 git://remote_1 && | |
529 | test_when_finished "git remote remove remote_2" && | |
530 | git remote add remote_2 git://remote_2 && | |
beb6ee71 SG |
531 | ( |
532 | verbose __git_is_configured_remote remote_2 && | |
533 | test_must_fail __git_is_configured_remote non-existent | |
534 | ) | |
69a77596 SG |
535 | ' |
536 | ||
fb9cd420 SG |
537 | test_expect_success 'setup for ref completion' ' |
538 | git commit --allow-empty -m initial && | |
539 | git branch matching-branch && | |
540 | git tag matching-tag && | |
541 | ( | |
542 | cd otherrepo && | |
543 | git commit --allow-empty -m initial && | |
544 | git branch -m master master-in-other && | |
545 | git branch branch-in-other && | |
546 | git tag tag-in-other | |
547 | ) && | |
548 | git remote add other "$ROOT/otherrepo/.git" && | |
549 | git fetch --no-tags other && | |
550 | rm -f .git/FETCH_HEAD && | |
551 | git init thirdrepo | |
552 | ' | |
553 | ||
554 | test_expect_success '__git_refs - simple' ' | |
555 | cat >expected <<-EOF && | |
556 | HEAD | |
557 | master | |
558 | matching-branch | |
559 | other/branch-in-other | |
560 | other/master-in-other | |
561 | matching-tag | |
562 | EOF | |
563 | ( | |
564 | cur= && | |
565 | __git_refs >"$actual" | |
566 | ) && | |
567 | test_cmp expected "$actual" | |
568 | ' | |
569 | ||
570 | test_expect_success '__git_refs - full refs' ' | |
571 | cat >expected <<-EOF && | |
572 | refs/heads/master | |
573 | refs/heads/matching-branch | |
e896369b SG |
574 | refs/remotes/other/branch-in-other |
575 | refs/remotes/other/master-in-other | |
576 | refs/tags/matching-tag | |
fb9cd420 SG |
577 | EOF |
578 | ( | |
579 | cur=refs/heads/ && | |
580 | __git_refs >"$actual" | |
581 | ) && | |
582 | test_cmp expected "$actual" | |
583 | ' | |
584 | ||
585 | test_expect_success '__git_refs - repo given on the command line' ' | |
586 | cat >expected <<-EOF && | |
587 | HEAD | |
588 | branch-in-other | |
589 | master-in-other | |
590 | tag-in-other | |
591 | EOF | |
592 | ( | |
593 | __git_dir="$ROOT/otherrepo/.git" && | |
594 | cur= && | |
595 | __git_refs >"$actual" | |
596 | ) && | |
597 | test_cmp expected "$actual" | |
598 | ' | |
599 | ||
600 | test_expect_success '__git_refs - remote on local file system' ' | |
601 | cat >expected <<-EOF && | |
602 | HEAD | |
603 | branch-in-other | |
604 | master-in-other | |
605 | tag-in-other | |
606 | EOF | |
607 | ( | |
608 | cur= && | |
609 | __git_refs otherrepo >"$actual" | |
610 | ) && | |
611 | test_cmp expected "$actual" | |
612 | ' | |
613 | ||
614 | test_expect_success '__git_refs - remote on local file system - full refs' ' | |
615 | cat >expected <<-EOF && | |
616 | refs/heads/branch-in-other | |
617 | refs/heads/master-in-other | |
618 | refs/tags/tag-in-other | |
619 | EOF | |
620 | ( | |
621 | cur=refs/ && | |
622 | __git_refs otherrepo >"$actual" | |
623 | ) && | |
624 | test_cmp expected "$actual" | |
625 | ' | |
626 | ||
627 | test_expect_success '__git_refs - configured remote' ' | |
628 | cat >expected <<-EOF && | |
629 | HEAD | |
630 | branch-in-other | |
631 | master-in-other | |
632 | EOF | |
633 | ( | |
634 | cur= && | |
635 | __git_refs other >"$actual" | |
636 | ) && | |
637 | test_cmp expected "$actual" | |
638 | ' | |
639 | ||
640 | test_expect_success '__git_refs - configured remote - full refs' ' | |
641 | cat >expected <<-EOF && | |
e896369b | 642 | HEAD |
fb9cd420 SG |
643 | refs/heads/branch-in-other |
644 | refs/heads/master-in-other | |
645 | refs/tags/tag-in-other | |
646 | EOF | |
647 | ( | |
648 | cur=refs/ && | |
649 | __git_refs other >"$actual" | |
650 | ) && | |
651 | test_cmp expected "$actual" | |
652 | ' | |
653 | ||
5c12f642 | 654 | test_expect_success '__git_refs - configured remote - repo given on the command line' ' |
fb9cd420 SG |
655 | cat >expected <<-EOF && |
656 | HEAD | |
657 | branch-in-other | |
658 | master-in-other | |
659 | EOF | |
660 | ( | |
661 | cd thirdrepo && | |
662 | __git_dir="$ROOT/.git" && | |
663 | cur= && | |
664 | __git_refs other >"$actual" | |
665 | ) && | |
666 | test_cmp expected "$actual" | |
667 | ' | |
668 | ||
5c12f642 | 669 | test_expect_success '__git_refs - configured remote - full refs - repo given on the command line' ' |
fb9cd420 | 670 | cat >expected <<-EOF && |
e896369b | 671 | HEAD |
fb9cd420 SG |
672 | refs/heads/branch-in-other |
673 | refs/heads/master-in-other | |
674 | refs/tags/tag-in-other | |
675 | EOF | |
676 | ( | |
677 | cd thirdrepo && | |
678 | __git_dir="$ROOT/.git" && | |
679 | cur=refs/ && | |
680 | __git_refs other >"$actual" | |
681 | ) && | |
682 | test_cmp expected "$actual" | |
683 | ' | |
684 | ||
69a77596 | 685 | test_expect_success '__git_refs - configured remote - remote name matches a directory' ' |
fb9cd420 SG |
686 | cat >expected <<-EOF && |
687 | HEAD | |
688 | branch-in-other | |
689 | master-in-other | |
690 | EOF | |
691 | mkdir other && | |
692 | test_when_finished "rm -rf other" && | |
693 | ( | |
694 | cur= && | |
695 | __git_refs other >"$actual" | |
696 | ) && | |
697 | test_cmp expected "$actual" | |
698 | ' | |
699 | ||
91b7ea81 | 700 | test_expect_success '__git_refs - URL remote' ' |
fb9cd420 SG |
701 | cat >expected <<-EOF && |
702 | HEAD | |
703 | branch-in-other | |
704 | master-in-other | |
705 | tag-in-other | |
706 | EOF | |
707 | ( | |
708 | cur= && | |
709 | __git_refs "file://$ROOT/otherrepo/.git" >"$actual" | |
710 | ) && | |
711 | test_cmp expected "$actual" | |
712 | ' | |
713 | ||
714 | test_expect_success '__git_refs - URL remote - full refs' ' | |
715 | cat >expected <<-EOF && | |
e896369b | 716 | HEAD |
fb9cd420 SG |
717 | refs/heads/branch-in-other |
718 | refs/heads/master-in-other | |
719 | refs/tags/tag-in-other | |
720 | EOF | |
721 | ( | |
722 | cur=refs/ && | |
723 | __git_refs "file://$ROOT/otherrepo/.git" >"$actual" | |
724 | ) && | |
725 | test_cmp expected "$actual" | |
726 | ' | |
727 | ||
91b7ea81 | 728 | test_expect_success '__git_refs - non-existing remote' ' |
fb9cd420 SG |
729 | ( |
730 | cur= && | |
731 | __git_refs non-existing >"$actual" | |
732 | ) && | |
733 | test_must_be_empty "$actual" | |
734 | ' | |
735 | ||
736 | test_expect_success '__git_refs - non-existing remote - full refs' ' | |
737 | ( | |
738 | cur=refs/ && | |
739 | __git_refs non-existing >"$actual" | |
740 | ) && | |
741 | test_must_be_empty "$actual" | |
742 | ' | |
743 | ||
91b7ea81 | 744 | test_expect_success '__git_refs - non-existing URL remote' ' |
fb9cd420 SG |
745 | ( |
746 | cur= && | |
747 | __git_refs "file://$ROOT/non-existing" >"$actual" | |
748 | ) && | |
749 | test_must_be_empty "$actual" | |
750 | ' | |
751 | ||
752 | test_expect_success '__git_refs - non-existing URL remote - full refs' ' | |
753 | ( | |
754 | cur=refs/ && | |
755 | __git_refs "file://$ROOT/non-existing" >"$actual" | |
756 | ) && | |
757 | test_must_be_empty "$actual" | |
758 | ' | |
759 | ||
62a1b732 | 760 | test_expect_success '__git_refs - not in a git repository' ' |
fb9cd420 SG |
761 | ( |
762 | GIT_CEILING_DIRECTORIES="$ROOT" && | |
763 | export GIT_CEILING_DIRECTORIES && | |
764 | cd subdir && | |
765 | cur= && | |
766 | __git_refs >"$actual" | |
767 | ) && | |
768 | test_must_be_empty "$actual" | |
769 | ' | |
770 | ||
771 | test_expect_success '__git_refs - unique remote branches for git checkout DWIMery' ' | |
772 | cat >expected <<-EOF && | |
773 | HEAD | |
774 | master | |
775 | matching-branch | |
776 | other/ambiguous | |
777 | other/branch-in-other | |
778 | other/master-in-other | |
779 | remote/ambiguous | |
780 | remote/branch-in-remote | |
781 | matching-tag | |
782 | branch-in-other | |
783 | branch-in-remote | |
784 | master-in-other | |
785 | EOF | |
786 | for remote_ref in refs/remotes/other/ambiguous \ | |
787 | refs/remotes/remote/ambiguous \ | |
788 | refs/remotes/remote/branch-in-remote | |
789 | do | |
790 | git update-ref $remote_ref master && | |
791 | test_when_finished "git update-ref -d $remote_ref" | |
792 | done && | |
793 | ( | |
794 | cur= && | |
795 | __git_refs "" 1 >"$actual" | |
796 | ) && | |
797 | test_cmp expected "$actual" | |
798 | ' | |
799 | ||
2ea328a1 SG |
800 | test_expect_success '__git_refs - after --opt=' ' |
801 | cat >expected <<-EOF && | |
802 | HEAD | |
803 | master | |
804 | matching-branch | |
805 | other/branch-in-other | |
806 | other/master-in-other | |
807 | matching-tag | |
808 | EOF | |
809 | ( | |
810 | cur="--opt=" && | |
811 | __git_refs "" "" "" "" >"$actual" | |
812 | ) && | |
813 | test_cmp expected "$actual" | |
814 | ' | |
815 | ||
816 | test_expect_success '__git_refs - after --opt= - full refs' ' | |
817 | cat >expected <<-EOF && | |
818 | refs/heads/master | |
819 | refs/heads/matching-branch | |
820 | refs/remotes/other/branch-in-other | |
821 | refs/remotes/other/master-in-other | |
822 | refs/tags/matching-tag | |
823 | EOF | |
824 | ( | |
825 | cur="--opt=refs/" && | |
826 | __git_refs "" "" "" refs/ >"$actual" | |
827 | ) && | |
828 | test_cmp expected "$actual" | |
829 | ' | |
830 | ||
aed38813 SG |
831 | test_expect_success '__git refs - exluding refs' ' |
832 | cat >expected <<-EOF && | |
833 | ^HEAD | |
834 | ^master | |
835 | ^matching-branch | |
836 | ^other/branch-in-other | |
837 | ^other/master-in-other | |
838 | ^matching-tag | |
839 | EOF | |
840 | ( | |
841 | cur=^ && | |
842 | __git_refs >"$actual" | |
843 | ) && | |
844 | test_cmp expected "$actual" | |
845 | ' | |
846 | ||
847 | test_expect_success '__git refs - exluding full refs' ' | |
848 | cat >expected <<-EOF && | |
849 | ^refs/heads/master | |
850 | ^refs/heads/matching-branch | |
851 | ^refs/remotes/other/branch-in-other | |
852 | ^refs/remotes/other/master-in-other | |
853 | ^refs/tags/matching-tag | |
854 | EOF | |
855 | ( | |
856 | cur=^refs/ && | |
857 | __git_refs >"$actual" | |
858 | ) && | |
859 | test_cmp expected "$actual" | |
860 | ' | |
861 | ||
e896369b SG |
862 | test_expect_success 'setup for filtering matching refs' ' |
863 | git branch matching/branch && | |
864 | git tag matching/tag && | |
865 | git -C otherrepo branch matching/branch-in-other && | |
866 | git fetch --no-tags other && | |
867 | rm -f .git/FETCH_HEAD | |
868 | ' | |
869 | ||
870 | test_expect_success '__git_refs - dont filter refs unless told so' ' | |
871 | cat >expected <<-EOF && | |
872 | HEAD | |
873 | master | |
874 | matching-branch | |
875 | matching/branch | |
876 | other/branch-in-other | |
877 | other/master-in-other | |
878 | other/matching/branch-in-other | |
879 | matching-tag | |
880 | matching/tag | |
881 | EOF | |
882 | ( | |
883 | cur=master && | |
884 | __git_refs >"$actual" | |
885 | ) && | |
886 | test_cmp expected "$actual" | |
887 | ' | |
888 | ||
889 | test_expect_success '__git_refs - only matching refs' ' | |
890 | cat >expected <<-EOF && | |
891 | matching-branch | |
892 | matching/branch | |
893 | matching-tag | |
894 | matching/tag | |
895 | EOF | |
896 | ( | |
897 | cur=mat && | |
898 | __git_refs "" "" "" "$cur" >"$actual" | |
899 | ) && | |
900 | test_cmp expected "$actual" | |
901 | ' | |
902 | ||
903 | test_expect_success '__git_refs - only matching refs - full refs' ' | |
904 | cat >expected <<-EOF && | |
905 | refs/heads/matching-branch | |
906 | refs/heads/matching/branch | |
907 | EOF | |
908 | ( | |
909 | cur=refs/heads/mat && | |
910 | __git_refs "" "" "" "$cur" >"$actual" | |
911 | ) && | |
912 | test_cmp expected "$actual" | |
913 | ' | |
914 | ||
915 | test_expect_success '__git_refs - only matching refs - remote on local file system' ' | |
916 | cat >expected <<-EOF && | |
917 | master-in-other | |
918 | matching/branch-in-other | |
919 | EOF | |
920 | ( | |
921 | cur=ma && | |
922 | __git_refs otherrepo "" "" "$cur" >"$actual" | |
923 | ) && | |
924 | test_cmp expected "$actual" | |
925 | ' | |
926 | ||
927 | test_expect_success '__git_refs - only matching refs - configured remote' ' | |
928 | cat >expected <<-EOF && | |
929 | master-in-other | |
930 | matching/branch-in-other | |
931 | EOF | |
932 | ( | |
933 | cur=ma && | |
934 | __git_refs other "" "" "$cur" >"$actual" | |
935 | ) && | |
936 | test_cmp expected "$actual" | |
937 | ' | |
938 | ||
939 | test_expect_success '__git_refs - only matching refs - remote - full refs' ' | |
940 | cat >expected <<-EOF && | |
941 | refs/heads/master-in-other | |
942 | refs/heads/matching/branch-in-other | |
943 | EOF | |
944 | ( | |
945 | cur=refs/heads/ma && | |
946 | __git_refs other "" "" "$cur" >"$actual" | |
947 | ) && | |
948 | test_cmp expected "$actual" | |
949 | ' | |
950 | ||
951 | test_expect_success '__git_refs - only matching refs - checkout DWIMery' ' | |
952 | cat >expected <<-EOF && | |
953 | matching-branch | |
954 | matching/branch | |
955 | matching-tag | |
956 | matching/tag | |
957 | matching/branch-in-other | |
958 | EOF | |
959 | for remote_ref in refs/remotes/other/ambiguous \ | |
960 | refs/remotes/remote/ambiguous \ | |
961 | refs/remotes/remote/branch-in-remote | |
962 | do | |
963 | git update-ref $remote_ref master && | |
964 | test_when_finished "git update-ref -d $remote_ref" | |
965 | done && | |
966 | ( | |
967 | cur=mat && | |
968 | __git_refs "" 1 "" "$cur" >"$actual" | |
969 | ) && | |
970 | test_cmp expected "$actual" | |
971 | ' | |
972 | ||
973 | test_expect_success 'teardown after filtering matching refs' ' | |
974 | git branch -d matching/branch && | |
975 | git tag -d matching/tag && | |
976 | git update-ref -d refs/remotes/other/matching/branch-in-other && | |
977 | git -C otherrepo branch -D matching/branch-in-other | |
978 | ' | |
979 | ||
fef56eb0 SG |
980 | test_expect_success '__git_refs - for-each-ref format specifiers in prefix' ' |
981 | cat >expected <<-EOF && | |
982 | evil-%%-%42-%(refname)..master | |
983 | EOF | |
984 | ( | |
985 | cur="evil-%%-%42-%(refname)..mas" && | |
986 | __git_refs "" "" "evil-%%-%42-%(refname).." mas >"$actual" | |
987 | ) && | |
988 | test_cmp expected "$actual" | |
989 | ' | |
990 | ||
15b4a163 SG |
991 | test_expect_success '__git_complete_refs - simple' ' |
992 | sed -e "s/Z$//" >expected <<-EOF && | |
993 | HEAD Z | |
994 | master Z | |
995 | matching-branch Z | |
996 | other/branch-in-other Z | |
997 | other/master-in-other Z | |
998 | matching-tag Z | |
999 | EOF | |
1000 | ( | |
1001 | cur= && | |
1002 | __git_complete_refs && | |
1003 | print_comp | |
1004 | ) && | |
1005 | test_cmp expected out | |
1006 | ' | |
1007 | ||
1008 | test_expect_success '__git_complete_refs - matching' ' | |
1009 | sed -e "s/Z$//" >expected <<-EOF && | |
1010 | matching-branch Z | |
1011 | matching-tag Z | |
1012 | EOF | |
1013 | ( | |
1014 | cur=mat && | |
1015 | __git_complete_refs && | |
1016 | print_comp | |
1017 | ) && | |
1018 | test_cmp expected out | |
1019 | ' | |
1020 | ||
1021 | test_expect_success '__git_complete_refs - remote' ' | |
1022 | sed -e "s/Z$//" >expected <<-EOF && | |
1023 | HEAD Z | |
1024 | branch-in-other Z | |
1025 | master-in-other Z | |
1026 | EOF | |
1027 | ( | |
1028 | cur= | |
1029 | __git_complete_refs --remote=other && | |
1030 | print_comp | |
1031 | ) && | |
1032 | test_cmp expected out | |
1033 | ' | |
1034 | ||
1035 | test_expect_success '__git_complete_refs - track' ' | |
1036 | sed -e "s/Z$//" >expected <<-EOF && | |
1037 | HEAD Z | |
1038 | master Z | |
1039 | matching-branch Z | |
1040 | other/branch-in-other Z | |
1041 | other/master-in-other Z | |
1042 | matching-tag Z | |
1043 | branch-in-other Z | |
1044 | master-in-other Z | |
1045 | EOF | |
1046 | ( | |
1047 | cur= | |
1048 | __git_complete_refs --track && | |
1049 | print_comp | |
1050 | ) && | |
1051 | test_cmp expected out | |
1052 | ' | |
1053 | ||
1054 | test_expect_success '__git_complete_refs - current word' ' | |
1055 | sed -e "s/Z$//" >expected <<-EOF && | |
1056 | matching-branch Z | |
1057 | matching-tag Z | |
1058 | EOF | |
1059 | ( | |
1060 | cur="--option=mat" && | |
1061 | __git_complete_refs --cur="${cur#*=}" && | |
1062 | print_comp | |
1063 | ) && | |
1064 | test_cmp expected out | |
1065 | ' | |
1066 | ||
1067 | test_expect_success '__git_complete_refs - prefix' ' | |
1068 | sed -e "s/Z$//" >expected <<-EOF && | |
1069 | v1.0..matching-branch Z | |
1070 | v1.0..matching-tag Z | |
1071 | EOF | |
1072 | ( | |
1073 | cur=v1.0..mat && | |
1074 | __git_complete_refs --pfx=v1.0.. --cur=mat && | |
1075 | print_comp | |
1076 | ) && | |
1077 | test_cmp expected out | |
1078 | ' | |
1079 | ||
1080 | test_expect_success '__git_complete_refs - suffix' ' | |
1081 | cat >expected <<-EOF && | |
1082 | HEAD. | |
1083 | master. | |
1084 | matching-branch. | |
1085 | other/branch-in-other. | |
1086 | other/master-in-other. | |
1087 | matching-tag. | |
1088 | EOF | |
1089 | ( | |
1090 | cur= && | |
1091 | __git_complete_refs --sfx=. && | |
1092 | print_comp | |
1093 | ) && | |
1094 | test_cmp expected out | |
1095 | ' | |
1096 | ||
aa0644f7 SG |
1097 | test_expect_success '__git_complete_fetch_refspecs - simple' ' |
1098 | sed -e "s/Z$//" >expected <<-EOF && | |
1099 | HEAD:HEAD Z | |
1100 | branch-in-other:branch-in-other Z | |
1101 | master-in-other:master-in-other Z | |
1102 | EOF | |
1103 | ( | |
1104 | cur= && | |
1105 | __git_complete_fetch_refspecs other && | |
1106 | print_comp | |
1107 | ) && | |
1108 | test_cmp expected out | |
1109 | ' | |
1110 | ||
1111 | test_expect_success '__git_complete_fetch_refspecs - matching' ' | |
1112 | sed -e "s/Z$//" >expected <<-EOF && | |
1113 | branch-in-other:branch-in-other Z | |
1114 | EOF | |
1115 | ( | |
1116 | cur=br && | |
1117 | __git_complete_fetch_refspecs other "" br && | |
1118 | print_comp | |
1119 | ) && | |
1120 | test_cmp expected out | |
1121 | ' | |
1122 | ||
1123 | test_expect_success '__git_complete_fetch_refspecs - prefix' ' | |
1124 | sed -e "s/Z$//" >expected <<-EOF && | |
1125 | +HEAD:HEAD Z | |
1126 | +branch-in-other:branch-in-other Z | |
1127 | +master-in-other:master-in-other Z | |
1128 | EOF | |
1129 | ( | |
1130 | cur="+" && | |
1131 | __git_complete_fetch_refspecs other "+" "" && | |
1132 | print_comp | |
1133 | ) && | |
1134 | test_cmp expected out | |
1135 | ' | |
1136 | ||
1137 | test_expect_success '__git_complete_fetch_refspecs - fully qualified' ' | |
1138 | sed -e "s/Z$//" >expected <<-EOF && | |
1139 | refs/heads/branch-in-other:refs/heads/branch-in-other Z | |
1140 | refs/heads/master-in-other:refs/heads/master-in-other Z | |
1141 | refs/tags/tag-in-other:refs/tags/tag-in-other Z | |
1142 | EOF | |
1143 | ( | |
1144 | cur=refs/ && | |
1145 | __git_complete_fetch_refspecs other "" refs/ && | |
1146 | print_comp | |
1147 | ) && | |
1148 | test_cmp expected out | |
1149 | ' | |
1150 | ||
1151 | test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' ' | |
1152 | sed -e "s/Z$//" >expected <<-EOF && | |
1153 | +refs/heads/branch-in-other:refs/heads/branch-in-other Z | |
1154 | +refs/heads/master-in-other:refs/heads/master-in-other Z | |
1155 | +refs/tags/tag-in-other:refs/tags/tag-in-other Z | |
1156 | EOF | |
1157 | ( | |
1158 | cur=+refs/ && | |
1159 | __git_complete_fetch_refspecs other + refs/ && | |
1160 | print_comp | |
1161 | ) && | |
1162 | test_cmp expected out | |
1163 | ' | |
1164 | ||
fb9cd420 SG |
1165 | test_expect_success 'teardown after ref completion' ' |
1166 | git branch -d matching-branch && | |
1167 | git tag -d matching-tag && | |
1168 | git remote remove other | |
1169 | ' | |
1170 | ||
12bdc880 SG |
1171 | test_expect_success '__git_get_config_variables' ' |
1172 | cat >expect <<-EOF && | |
1173 | name-1 | |
1174 | name-2 | |
1175 | EOF | |
1176 | test_config interesting.name-1 good && | |
1177 | test_config interesting.name-2 good && | |
1178 | test_config subsection.interesting.name-3 bad && | |
1179 | __git_get_config_variables interesting >actual && | |
1180 | test_cmp expect actual | |
1181 | ' | |
1182 | ||
e8f9e428 SG |
1183 | test_expect_success '__git_pretty_aliases' ' |
1184 | cat >expect <<-EOF && | |
1185 | author | |
1186 | hash | |
1187 | EOF | |
1188 | test_config pretty.author "%an %ae" && | |
1189 | test_config pretty.hash %H && | |
1190 | __git_pretty_aliases >actual && | |
1191 | test_cmp expect actual | |
1192 | ' | |
1193 | ||
1194 | test_expect_success '__git_aliases' ' | |
1195 | cat >expect <<-EOF && | |
1196 | ci | |
1197 | co | |
1198 | EOF | |
1199 | test_config alias.ci commit && | |
1200 | test_config alias.co checkout && | |
1201 | __git_aliases >actual && | |
1202 | test_cmp expect actual | |
1203 | ' | |
1204 | ||
5c293a6b | 1205 | test_expect_success 'basic' ' |
cdbff7d6 | 1206 | run_completion "git " && |
5c293a6b FC |
1207 | # built-in |
1208 | grep -q "^add \$" out && | |
1209 | # script | |
1210 | grep -q "^filter-branch \$" out && | |
1211 | # plumbing | |
1212 | ! grep -q "^ls-files \$" out && | |
1213 | ||
1214 | run_completion "git f" && | |
1215 | ! grep -q -v "^f" out | |
1216 | ' | |
1217 | ||
1218 | test_expect_success 'double dash "git" itself' ' | |
2fbaf813 | 1219 | test_completion "git --" <<-\EOF |
5c293a6b FC |
1220 | --paginate Z |
1221 | --no-pager Z | |
1222 | --git-dir= | |
1223 | --bare Z | |
1224 | --version Z | |
1225 | --exec-path Z | |
3ffcd086 | 1226 | --exec-path= |
5c293a6b | 1227 | --html-path Z |
66fb37d0 | 1228 | --man-path Z |
69ef3c02 | 1229 | --info-path Z |
5c293a6b FC |
1230 | --work-tree= |
1231 | --namespace= | |
69ef3c02 | 1232 | --no-replace-objects Z |
5c293a6b FC |
1233 | --help Z |
1234 | EOF | |
5c293a6b FC |
1235 | ' |
1236 | ||
1237 | test_expect_success 'double dash "git checkout"' ' | |
2fbaf813 | 1238 | test_completion "git checkout --" <<-\EOF |
5c293a6b | 1239 | --quiet Z |
2b1c01d2 | 1240 | --no-quiet Z |
77afafb2 | 1241 | --detach Z |
2b1c01d2 | 1242 | --no-detach Z |
77afafb2 | 1243 | --track Z |
2b1c01d2 | 1244 | --no-track Z |
77afafb2 | 1245 | --orphan=Z |
2b1c01d2 | 1246 | --no-orphan Z |
5c293a6b | 1247 | --ours Z |
2b1c01d2 | 1248 | --no-ours Z |
5c293a6b | 1249 | --theirs Z |
2b1c01d2 | 1250 | --no-theirs Z |
5c293a6b | 1251 | --merge Z |
2b1c01d2 | 1252 | --no-merge Z |
77afafb2 | 1253 | --conflict=Z |
2b1c01d2 | 1254 | --no-conflict Z |
5c293a6b | 1255 | --patch Z |
2b1c01d2 | 1256 | --no-patch Z |
6357d9d0 | 1257 | --ignore-skip-worktree-bits Z |
2b1c01d2 | 1258 | --no-ignore-skip-worktree-bits Z |
77afafb2 | 1259 | --ignore-other-worktrees Z |
2b1c01d2 | 1260 | --no-ignore-other-worktrees Z |
6357d9d0 TB |
1261 | --recurse-submodules Z |
1262 | --no-recurse-submodules Z | |
2b1c01d2 NTND |
1263 | --progress Z |
1264 | --no-progress Z | |
5c293a6b | 1265 | EOF |
5c293a6b FC |
1266 | ' |
1267 | ||
69ef3c02 FC |
1268 | test_expect_success 'general options' ' |
1269 | test_completion "git --ver" "--version " && | |
1270 | test_completion "git --hel" "--help " && | |
2fbaf813 | 1271 | test_completion "git --exe" <<-\EOF && |
3ffcd086 JN |
1272 | --exec-path Z |
1273 | --exec-path= | |
1274 | EOF | |
69ef3c02 FC |
1275 | test_completion "git --htm" "--html-path " && |
1276 | test_completion "git --pag" "--paginate " && | |
1277 | test_completion "git --no-p" "--no-pager " && | |
1278 | test_completion "git --git" "--git-dir=" && | |
1279 | test_completion "git --wor" "--work-tree=" && | |
1280 | test_completion "git --nam" "--namespace=" && | |
1281 | test_completion "git --bar" "--bare " && | |
1282 | test_completion "git --inf" "--info-path " && | |
1283 | test_completion "git --no-r" "--no-replace-objects " | |
1284 | ' | |
911d5da6 SG |
1285 | |
1286 | test_expect_success 'general options plus command' ' | |
1287 | test_completion "git --version check" "checkout " && | |
1288 | test_completion "git --paginate check" "checkout " && | |
1289 | test_completion "git --git-dir=foo check" "checkout " && | |
1290 | test_completion "git --bare check" "checkout " && | |
911d5da6 SG |
1291 | test_completion "git --exec-path=foo check" "checkout " && |
1292 | test_completion "git --html-path check" "checkout " && | |
1293 | test_completion "git --no-pager check" "checkout " && | |
1294 | test_completion "git --work-tree=foo check" "checkout " && | |
1295 | test_completion "git --namespace=foo check" "checkout " && | |
1296 | test_completion "git --paginate check" "checkout " && | |
1297 | test_completion "git --info-path check" "checkout " && | |
336d694c SG |
1298 | test_completion "git --no-replace-objects check" "checkout " && |
1299 | test_completion "git --git-dir some/path check" "checkout " && | |
1300 | test_completion "git -c conf.var=value check" "checkout " && | |
1301 | test_completion "git -C some/path check" "checkout " && | |
1302 | test_completion "git --work-tree some/path check" "checkout " && | |
1303 | test_completion "git --namespace name/space check" "checkout " | |
911d5da6 SG |
1304 | ' |
1305 | ||
50478223 JH |
1306 | test_expect_success 'git --help completion' ' |
1307 | test_completion "git --help ad" "add " && | |
1308 | test_completion "git --help core" "core-tutorial " | |
1309 | ' | |
1310 | ||
fb9cd420 | 1311 | test_expect_success 'setup for integration tests' ' |
49ba92b4 JK |
1312 | echo content >file1 && |
1313 | echo more >file2 && | |
e5edbef4 | 1314 | git add file1 file2 && |
49ba92b4 JK |
1315 | git commit -m one && |
1316 | git branch mybranch && | |
1317 | git tag mytag | |
1318 | ' | |
1319 | ||
1320 | test_expect_success 'checkout completes ref names' ' | |
2fbaf813 | 1321 | test_completion "git checkout m" <<-\EOF |
43ea0812 FC |
1322 | master Z |
1323 | mybranch Z | |
1324 | mytag Z | |
49ba92b4 JK |
1325 | EOF |
1326 | ' | |
1327 | ||
80ac0744 SG |
1328 | test_expect_success 'git -C <path> checkout uses the right repo' ' |
1329 | test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF | |
1330 | branch-in-other Z | |
1331 | EOF | |
1332 | ' | |
1333 | ||
49ba92b4 | 1334 | test_expect_success 'show completes all refs' ' |
2fbaf813 | 1335 | test_completion "git show m" <<-\EOF |
43ea0812 FC |
1336 | master Z |
1337 | mybranch Z | |
1338 | mytag Z | |
49ba92b4 JK |
1339 | EOF |
1340 | ' | |
1341 | ||
1342 | test_expect_success '<ref>: completes paths' ' | |
2fbaf813 | 1343 | test_completion "git show mytag:f" <<-\EOF |
43ea0812 FC |
1344 | file1 Z |
1345 | file2 Z | |
49ba92b4 JK |
1346 | EOF |
1347 | ' | |
1348 | ||
bafed0df JK |
1349 | test_expect_success 'complete tree filename with spaces' ' |
1350 | echo content >"name with spaces" && | |
e5edbef4 | 1351 | git add "name with spaces" && |
bafed0df | 1352 | git commit -m spaces && |
2fbaf813 | 1353 | test_completion "git show HEAD:nam" <<-\EOF |
43ea0812 | 1354 | name with spaces Z |
bafed0df JK |
1355 | EOF |
1356 | ' | |
1357 | ||
7d13e0a3 | 1358 | test_expect_success 'complete tree filename with metacharacters' ' |
bafed0df | 1359 | echo content >"name with \${meta}" && |
e5edbef4 | 1360 | git add "name with \${meta}" && |
bafed0df | 1361 | git commit -m meta && |
2fbaf813 | 1362 | test_completion "git show HEAD:nam" <<-\EOF |
43ea0812 FC |
1363 | name with ${meta} Z |
1364 | name with spaces Z | |
bafed0df JK |
1365 | EOF |
1366 | ' | |
1367 | ||
2f65494d FC |
1368 | test_expect_success 'send-email' ' |
1369 | test_completion "git send-email --cov" "--cover-letter " && | |
1370 | test_completion "git send-email ma" "master " | |
1371 | ' | |
1372 | ||
ddf07bdd FC |
1373 | test_expect_success 'complete files' ' |
1374 | git init tmp && cd tmp && | |
1375 | test_when_finished "cd .. && rm -rf tmp" && | |
1376 | ||
1377 | echo "expected" > .gitignore && | |
1378 | echo "out" >> .gitignore && | |
1379 | ||
1380 | git add .gitignore && | |
1381 | test_completion "git commit " ".gitignore" && | |
1382 | ||
1383 | git commit -m ignore && | |
1384 | ||
1385 | touch new && | |
1386 | test_completion "git add " "new" && | |
1387 | ||
1388 | git add new && | |
1389 | git commit -a -m new && | |
1390 | test_completion "git add " "" && | |
1391 | ||
1392 | git mv new modified && | |
1393 | echo modify > modified && | |
1394 | test_completion "git add " "modified" && | |
1395 | ||
1396 | touch untracked && | |
1397 | ||
1398 | : TODO .gitignore should not be here && | |
1399 | test_completion "git rm " <<-\EOF && | |
1400 | .gitignore | |
1401 | modified | |
1402 | EOF | |
1403 | ||
1404 | test_completion "git clean " "untracked" && | |
1405 | ||
1406 | : TODO .gitignore should not be here && | |
1407 | test_completion "git mv " <<-\EOF && | |
1408 | .gitignore | |
1409 | modified | |
1410 | EOF | |
1411 | ||
1412 | mkdir dir && | |
1413 | touch dir/file-in-dir && | |
1414 | git add dir/file-in-dir && | |
1415 | git commit -m dir && | |
1416 | ||
1417 | mkdir untracked-dir && | |
1418 | ||
1419 | : TODO .gitignore should not be here && | |
1420 | test_completion "git mv modified " <<-\EOF && | |
1421 | .gitignore | |
1422 | dir | |
1423 | modified | |
1424 | untracked | |
1425 | untracked-dir | |
1426 | EOF | |
1427 | ||
1428 | test_completion "git commit " "modified" && | |
1429 | ||
1430 | : TODO .gitignore should not be here && | |
8fb26872 | 1431 | test_completion "git ls-files " <<-\EOF && |
ddf07bdd FC |
1432 | .gitignore |
1433 | dir | |
1434 | modified | |
1435 | EOF | |
1436 | ||
1437 | touch momified && | |
1438 | test_completion "git add mom" "momified" | |
1439 | ' | |
1440 | ||
56f24e80 SP |
1441 | test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" ' |
1442 | test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" && | |
1443 | test_completion "git co m" <<-\EOF | |
1444 | master Z | |
1445 | mybranch Z | |
1446 | mytag Z | |
1447 | EOF | |
1448 | ' | |
1449 | ||
1450 | test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' ' | |
1451 | test_config alias.co "!f () { VAR=val git checkout ... ; } f" && | |
1452 | test_completion "git co m" <<-\EOF | |
1453 | master Z | |
1454 | mybranch Z | |
1455 | mytag Z | |
1456 | EOF | |
1457 | ' | |
1458 | ||
1459 | test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' ' | |
1460 | test_config alias.co "!f() { : git checkout ; if ... } f" && | |
1461 | test_completion "git co m" <<-\EOF | |
1462 | master Z | |
1463 | mybranch Z | |
1464 | mytag Z | |
1465 | EOF | |
1466 | ' | |
1467 | ||
9f642a71 NTND |
1468 | test_expect_success 'completion without explicit _git_xxx function' ' |
1469 | test_completion "git version --" <<-\EOF | |
1470 | --build-options Z | |
2b1c01d2 | 1471 | --no-build-options Z |
9f642a71 NTND |
1472 | EOF |
1473 | ' | |
1474 | ||
f03efba4 FC |
1475 | test_expect_failure 'complete with tilde expansion' ' |
1476 | git init tmp && cd tmp && | |
1477 | test_when_finished "cd .. && rm -rf tmp" && | |
1478 | ||
1479 | touch ~/tmp/file && | |
1480 | ||
1481 | test_completion "git add ~/tmp/" "~/tmp/file" | |
1482 | ' | |
1483 | ||
723c1d52 ÆAB |
1484 | test_expect_success 'setup other remote for remote reference completion' ' |
1485 | git remote add other otherrepo && | |
1486 | git fetch other | |
1487 | ' | |
1488 | ||
1489 | for flag in -d --delete | |
1490 | do | |
1491 | test_expect_success "__git_complete_remote_or_refspec - push $flag other" ' | |
1492 | sed -e "s/Z$//" >expected <<-EOF && | |
1493 | master-in-other Z | |
1494 | EOF | |
1495 | ( | |
1496 | words=(git push '$flag' other ma) && | |
1497 | cword=${#words[@]} cur=${words[cword-1]} && | |
1498 | __git_complete_remote_or_refspec && | |
1499 | print_comp | |
1500 | ) && | |
1501 | test_cmp expected out | |
1502 | ' | |
1503 | ||
1504 | test_expect_failure "__git_complete_remote_or_refspec - push other $flag" ' | |
1505 | sed -e "s/Z$//" >expected <<-EOF && | |
1506 | master-in-other Z | |
1507 | EOF | |
1508 | ( | |
1509 | words=(git push other '$flag' ma) && | |
1510 | cword=${#words[@]} cur=${words[cword-1]} && | |
1511 | __git_complete_remote_or_refspec && | |
1512 | print_comp | |
1513 | ) && | |
1514 | test_cmp expected out | |
1515 | ' | |
1516 | done | |
1517 | ||
8b0eaa41 SG |
1518 | test_expect_success 'sourcing the completion script clears cached commands' ' |
1519 | __git_compute_all_commands && | |
1520 | verbose test -n "$__git_all_commands" && | |
1521 | . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && | |
1522 | verbose test -z "$__git_all_commands" | |
1523 | ' | |
1524 | ||
1525 | test_expect_success 'sourcing the completion script clears cached porcelain commands' ' | |
1526 | __git_compute_porcelain_commands && | |
1527 | verbose test -n "$__git_porcelain_commands" && | |
1528 | . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && | |
1529 | verbose test -z "$__git_porcelain_commands" | |
1530 | ' | |
1531 | ||
b60e88cc | 1532 | test_expect_success !GETTEXT_POISON 'sourcing the completion script clears cached merge strategies' ' |
8b0eaa41 SG |
1533 | __git_compute_merge_strategies && |
1534 | verbose test -n "$__git_merge_strategies" && | |
1535 | . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && | |
1536 | verbose test -z "$__git_merge_strategies" | |
1537 | ' | |
1538 | ||
1539 | test_expect_success 'sourcing the completion script clears cached --options' ' | |
1540 | __gitcomp_builtin checkout && | |
1541 | verbose test -n "$__gitcomp_builtin_checkout" && | |
1542 | __gitcomp_builtin notes_edit && | |
1543 | verbose test -n "$__gitcomp_builtin_notes_edit" && | |
1544 | . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && | |
1545 | verbose test -z "$__gitcomp_builtin_checkout" && | |
1546 | verbose test -z "$__gitcomp_builtin_notes_edit" | |
1547 | ' | |
1548 | ||
5c293a6b | 1549 | test_done |