@matheusbsbs / matheus-bagliano / commits / c09d1280f7
Fork 0

completion: use "prev" variable instead of introducing "prevword"

In both _git_checkout and _git_switch a new "prevword" variable were introduced, however the "prev" variable already contains the last word. The "prevword" variable is replaced with "prev", and the case is moved to the beginning of the function, like it's done in many other places (e.g. _git_commit). Also the indentaion of the case is fixed. Signed-off-by: Ákos Uzonyi <uzonyi.akos@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ákos Uzonyi committed Sep 25, 2020 at 23:11 UTC c09d1280f7787020e28844e8fd615d973d2a811e
1 file changed +32 -34
contrib/completion/git-completion.bash
+32 -34
@@ -1508,6 +1508,22 @@ _git_checkout ()
1508 {
1509 __git_has_doubledash && return
1510
1511 + local dwim_opt="$(__git_checkout_default_dwim_mode)"
1512 +
1513 + case "$prev" in
1514 + -b|-B|--orphan)
1515 + # Complete local branches (and DWIM branch
1516 + # remote branch names) for an option argument
1517 + # specifying a new branch name. This is for
1518 + # convenience, assuming new branches are
1519 + # possibly based on pre-existing branch names.
1520 + __git_complete_refs $dwim_opt --mode="heads"
1521 + return
1522 + ;;
1523 + *)
1524 + ;;
1525 + esac
1526 +
1527 case "$cur" in
1528 --conflict=*)
1529 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
@@ -1516,23 +1532,6 @@ _git_checkout ()
1532 __gitcomp_builtin checkout
1533 ;;
1534 *)
1519 - local dwim_opt="$(__git_checkout_default_dwim_mode)"
1520 - local prevword prevword="${words[cword-1]}"
1521 -
1522 - case "$prevword" in
1523 - -b|-B|--orphan)
1524 - # Complete local branches (and DWIM branch
1525 - # remote branch names) for an option argument
1526 - # specifying a new branch name. This is for
1527 - # convenience, assuming new branches are
1528 - # possibly based on pre-existing branch names.
1529 - __git_complete_refs $dwim_opt --mode="heads"
1530 - return
1531 - ;;
1532 - *)
1533 - ;;
1534 - esac
1535 -
1535 # At this point, we've already handled special completion for
1536 # the arguments to -b/-B, and --orphan. There are 3 main
1537 # things left we can possibly complete:
@@ -2392,6 +2391,22 @@ _git_status ()
2391
2392 _git_switch ()
2393 {
2394 + local dwim_opt="$(__git_checkout_default_dwim_mode)"
2395 +
2396 + case "$prev" in
2397 + -c|-C|--orphan)
2398 + # Complete local branches (and DWIM branch
2399 + # remote branch names) for an option argument
2400 + # specifying a new branch name. This is for
2401 + # convenience, assuming new branches are
2402 + # possibly based on pre-existing branch names.
2403 + __git_complete_refs $dwim_opt --mode="heads"
2404 + return
2405 + ;;
2406 + *)
2407 + ;;
2408 + esac
2409 +
2410 case "$cur" in
2411 --conflict=*)
2412 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
@@ -2400,23 +2415,6 @@ _git_switch ()
2415 __gitcomp_builtin switch
2416 ;;
2417 *)
2403 - local dwim_opt="$(__git_checkout_default_dwim_mode)"
2404 - local prevword prevword="${words[cword-1]}"
2405 -
2406 - case "$prevword" in
2407 - -c|-C|--orphan)
2408 - # Complete local branches (and DWIM branch
2409 - # remote branch names) for an option argument
2410 - # specifying a new branch name. This is for
2411 - # convenience, assuming new branches are
2412 - # possibly based on pre-existing branch names.
2413 - __git_complete_refs $dwim_opt --mode="heads"
2414 - return
2415 - ;;
2416 - *)
2417 - ;;
2418 - esac
2419 -
2418 # Unlike in git checkout, git switch --orphan does not take
2419 # a start point. Thus we really have nothing to complete after
2420 # the branch name.