Skip to content

Commit c09d128

Browse files
AkosUzonyigitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9bc233a commit c09d128

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

contrib/completion/git-completion.bash

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,22 @@ _git_checkout ()
15081508
{
15091509
__git_has_doubledash && return
15101510

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+
15111527
case "$cur" in
15121528
--conflict=*)
15131529
__gitcomp "diff3 merge" "" "${cur##--conflict=}"
@@ -1516,23 +1532,6 @@ _git_checkout ()
15161532
__gitcomp_builtin checkout
15171533
;;
15181534
*)
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-
15361535
# At this point, we've already handled special completion for
15371536
# the arguments to -b/-B, and --orphan. There are 3 main
15381537
# things left we can possibly complete:
@@ -2392,6 +2391,22 @@ _git_status ()
23922391

23932392
_git_switch ()
23942393
{
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+
23952410
case "$cur" in
23962411
--conflict=*)
23972412
__gitcomp "diff3 merge" "" "${cur##--conflict=}"
@@ -2400,23 +2415,6 @@ _git_switch ()
24002415
__gitcomp_builtin switch
24012416
;;
24022417
*)
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-
24202418
# Unlike in git checkout, git switch --orphan does not take
24212419
# a start point. Thus we really have nothing to complete after
24222420
# the branch name.

0 commit comments

Comments
 (0)