Skip to content

Commit

Permalink
rebase: use explicit "--" with checkout
Browse files Browse the repository at this point in the history
In the case of a ref/pathname conflict, checkout will
already do the right thing and checkout the ref. However,
for a non-existant ref, this has two advantages:

  1. If a file with that pathname exists, rebase will
     refresh the file from the index and then rebase the
     current branch instead of producing an error.

  2. If no such file exists, the error message using an
     explicit "--" is better:

       # before
       $ git rebase -i origin bogus
       error: pathspec 'bogus' did not match any file(s) known to git.
       Could not checkout bogus

       # after
       $ git rebase -i origin bogus
       fatal: invalid reference: bogus
       Could not checkout bogus

The problems seem to be trigger-able only through "git
rebase -i", as regular git-rebase checks the validity of the
branch parameter as a ref very early on. However, it doesn't
hurt to be defensive.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jan 27, 2011
1 parent b312b41 commit 3b21a43
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion git-rebase--interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ first and then run 'git rebase --continue' again."

if test ! -z "$1"
then
output git checkout "$1" ||
output git checkout "$1" -- ||
die "Could not checkout $1"
fi

Expand Down
2 changes: 1 addition & 1 deletion git-rebase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ then
if test -z "$force_rebase"
then
# Lazily switch to the target branch if needed...
test -z "$switch_to" || git checkout "$switch_to"
test -z "$switch_to" || git checkout "$switch_to" --
say "Current branch $branch_name is up to date."
exit 0
else
Expand Down

0 comments on commit 3b21a43

Please sign in to comment.