git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] rebase: use explicit "--" with checkout

From
Jeff King <peff@peff.net>
Date
Jan 27, 2011, 00:26 UTC
Message-ID
<20110127002658.GA32711@sigill.intra.peff.net>

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>
---
 git-rebase--interactive.sh |    2 +-
 git-rebase.sh              |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index a5ffd9a..7bd5602 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -894,7 +894,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
 
diff --git a/git-rebase.sh b/git-rebase.sh
index d8e1903..345b18c 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -513,7 +513,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
-- 
1.7.4.rc3.5.g8354b
Message 1 of 1 in “rebase: use explicit "--" with checkout”
  1. 1/2 rebase: use explicit "--" with checkoutJeff King, Jan 27, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.