Skip to content

Commit

Permalink
checkout_branch: support "-" argument (#322)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
carlfriedrich committed Aug 13, 2023
1 parent b663d22 commit e8e3083
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion bin/git-forgit
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
Expand Down

0 comments on commit e8e3083

Please sign in to comment.