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