checkout_branch: support "-" argument

git natively supports `-` as an argument to `git switch` and `git
checkout`. It is shorthand for `@{-1}`, which is a way to refer to the
last branch you were on.

forgit used to interpret `-` as a branch name, detect that it does not
exist yet and create a new one with this name, which does not work.

Add a check whether `-` is passed on the command line and do not create
a new branch in this case
This commit is contained in:
carlfriedrich 2023-08-10 15:00:54 +02:00
parent b663d22f5b
commit 432b642a16

View file

@ -454,7 +454,7 @@ _forgit_checkout_branch() {
_forgit_inside_work_tree || return 1
# if called with arguments, check if branch exists, else create a new one
if [[ $# -ne 0 ]]; then
if git show-branch "$@" &>/dev/null; then
if [[ "$*" == "-" ]] || git show-branch "$@" &>/dev/null; then
git switch "$@"
else
git switch -c "$@"