354
# Can be the name of a configured remote, a path, or a URL.
355
# 2: In addition to local refs, list unique branches from refs/remotes/ for
356
# 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
357
+#
358
+# Use __git_complete_refs() instead.
359
__git_refs ()
360
{
361
local i hash dir track="${2-}"
448
esac
449
}
450
451
+# Completes refs, short and long, local and remote, symbolic and pseudo.
452
+#
453
+# Usage: __git_complete_refs [<option>]...
454
+# --remote=<remote>: The remote to list refs from, can be the name of a
455
+# configured remote, a path, or a URL.
456
+# --track: List unique remote branches for 'git checkout's tracking DWIMery.
457
+# --pfx=<prefix>: A prefix to be added to each ref.
458
+# --cur=<word>: The current ref to be completed. Defaults to the current
459
+# word to be completed.
460
+# --sfx=<suffix>: A suffix to be appended to each ref instead of the default
461
+# space.
462
+__git_complete_refs ()
463
+{
464
+ local remote track pfx cur_="$cur" sfx=" "
465
+
466
+ while test $# != 0; do
467
+ case "$1" in
468
+ --remote=*) remote="${1##--remote=}" ;;
469
+ --track) track="yes" ;;
470
+ --pfx=*) pfx="${1##--pfx=}" ;;
471
+ --cur=*) cur_="${1##--cur=}" ;;
472
+ --sfx=*) sfx="${1##--sfx=}" ;;
473
+ *) return 1 ;;
474
+ esac
475
+ shift
476
+ done
477
+
478
+ __gitcomp_nl "$(__git_refs "$remote" "$track")" "$pfx" "$cur_" "$sfx"
479
+}
480
+
481
# __git_refs2 requires 1 argument (to pass to __git_refs)
482
__git_refs2 ()
483
{
586
*...*)
587
pfx="${cur_%...*}..."
588
cur_="${cur_#*...}"
557
- __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
589
+ __git_complete_refs --pfx="$pfx" --cur="$cur_"
590
;;
591
*..*)
592
pfx="${cur_%..*}.."
593
cur_="${cur_#*..}"
562
- __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
594
+ __git_complete_refs --pfx="$pfx" --cur="$cur_"
595
;;
596
*)
565
- __gitcomp_nl "$(__git_refs)"
597
+ __git_complete_refs
598
;;
599
esac
600
}
681
if [ $lhs = 1 ]; then
682
__gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
683
else
652
- __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
684
+ __git_complete_refs --pfx="$pfx" --cur="$cur_"
685
fi
686
;;
687
pull|remote)
688
if [ $lhs = 1 ]; then
657
- __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
689
+ __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
690
else
659
- __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
691
+ __git_complete_refs --pfx="$pfx" --cur="$cur_"
692
fi
693
;;
694
push)
695
if [ $lhs = 1 ]; then
664
- __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
696
+ __git_complete_refs --pfx="$pfx" --cur="$cur_"
697
else
666
- __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
698
+ __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
699
fi
700
;;
701
esac
1093
1094
case "$subcommand" in
1095
bad|good|reset|skip|start)
1064
- __gitcomp_nl "$(__git_refs)"
1096
+ __git_complete_refs
1097
;;
1098
*)
1099
;;
1115
1116
case "$cur" in
1117
--set-upstream-to=*)
1086
- __gitcomp_nl "$(__git_refs)" "" "${cur##--set-upstream-to=}"
1118
+ __git_complete_refs --cur="${cur##--set-upstream-to=}"
1119
;;
1120
--*)
1121
__gitcomp "
1129
if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1130
__gitcomp_nl "$(__git_heads)"
1131
else
1100
- __gitcomp_nl "$(__git_refs)"
1132
+ __git_complete_refs
1133
fi
1134
;;
1135
esac
1172
*)
1173
# check if --track, --no-track, or --no-guess was specified
1174
# if so, disable DWIM mode
1143
- local flags="--track --no-track --no-guess" track=1
1175
+ local flags="--track --no-track --no-guess" track_opt="--track"
1176
if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1145
- track=''
1177
+ track_opt=''
1178
fi
1147
- __gitcomp_nl "$(__git_refs '' $track)"
1179
+ __git_complete_refs $track_opt
1180
;;
1181
esac
1182
}
1183
1184
_git_cherry ()
1185
{
1154
- __gitcomp_nl "$(__git_refs)"
1186
+ __git_complete_refs
1187
}
1188
1189
_git_cherry_pick ()
1198
__gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1199
;;
1200
*)
1169
- __gitcomp_nl "$(__git_refs)"
1201
+ __git_complete_refs
1202
;;
1203
esac
1204
}
1248
{
1249
case "$prev" in
1250
-c|-C)
1219
- __gitcomp_nl "$(__git_refs)"
1251
+ __git_complete_refs
1252
return
1253
;;
1254
esac
1261
;;
1262
--reuse-message=*|--reedit-message=*|\
1263
--fixup=*|--squash=*)
1232
- __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1264
+ __git_complete_refs --cur="${cur#*=}"
1265
return
1266
;;
1267
--untracked-files=*)
1299
"
1300
return
1301
esac
1270
- __gitcomp_nl "$(__git_refs)"
1302
+ __git_complete_refs
1303
}
1304
1305
__git_diff_algorithms="myers minimal patience histogram"
1485
;;
1486
esac
1487
1456
- __gitcomp_nl "$(__git_refs)"
1488
+ __git_complete_refs
1489
}
1490
1491
_git_help ()
1653
--rerere-autoupdate --no-rerere-autoupdate --abort --continue"
1654
return
1655
esac
1624
- __gitcomp_nl "$(__git_refs)"
1656
+ __git_complete_refs
1657
}
1658
1659
_git_mergetool ()
1678
return
1679
;;
1680
esac
1649
- __gitcomp_nl "$(__git_refs)"
1681
+ __git_complete_refs
1682
}
1683
1684
_git_mv ()
1716
,*)
1717
case "$prev" in
1718
--ref)
1687
- __gitcomp_nl "$(__git_refs)"
1719
+ __git_complete_refs
1720
;;
1721
*)
1722
__gitcomp "$subcommands --ref"
1725
;;
1726
add,--reuse-message=*|append,--reuse-message=*|\
1727
add,--reedit-message=*|append,--reedit-message=*)
1696
- __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1728
+ __git_complete_refs --cur="${cur#*=}"
1729
;;
1730
add,--*|append,--*)
1731
__gitcomp '--file= --message= --reedit-message=
1744
-m|-F)
1745
;;
1746
*)
1715
- __gitcomp_nl "$(__git_refs)"
1747
+ __git_complete_refs
1748
;;
1749
esac
1750
;;
1782
--*=)
1783
;;
1784
*:*)
1753
- __gitcomp_nl "$(__git_refs)" "" "${cur_#*:}"
1785
+ __git_complete_refs --cur="${cur_#*:}"
1786
;;
1787
*)
1756
- __gitcomp_nl "$(__git_refs)" "" "$cur_"
1788
+ __git_complete_refs --cur="$cur_"
1789
;;
1790
esac
1791
}
1861
1862
return
1863
esac
1832
- __gitcomp_nl "$(__git_refs)"
1864
+ __git_complete_refs
1865
}
1866
1867
_git_reflog ()
1872
if [ -z "$subcommand" ]; then
1873
__gitcomp "$subcommands"
1874
else
1843
- __gitcomp_nl "$(__git_refs)"
1875
+ __git_complete_refs
1876
fi
1877
}
1878
2018
return
2019
;;
2020
branch.*.merge)
1989
- __gitcomp_nl "$(__git_refs)"
2021
+ __git_complete_refs
2022
return
2023
;;
2024
branch.*.rebase)
2492
2493
_git_replace ()
2494
{
2463
- __gitcomp_nl "$(__git_refs)"
2495
+ __git_complete_refs
2496
}
2497
2498
_git_reset ()
2505
return
2506
;;
2507
esac
2476
- __gitcomp_nl "$(__git_refs)"
2508
+ __git_complete_refs
2509
}
2510
2511
_git_revert ()
2521
return
2522
;;
2523
esac
2492
- __gitcomp_nl "$(__git_refs)"
2524
+ __git_complete_refs
2525
}
2526
2527
_git_rm ()
2629
;;
2630
branch,*)
2631
if [ $cword -eq 3 ]; then
2600
- __gitcomp_nl "$(__git_refs)";
2632
+ __git_complete_refs
2633
else
2634
__gitcomp_nl "$(__git stash list \
2635
| sed -n -e 's/:.*//p')"
2787
fi
2788
;;
2789
*)
2758
- __gitcomp_nl "$(__git_refs)"
2790
+ __git_complete_refs
2791
;;
2792
esac
2793