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

[PATCH] git-branch: avoid getting confused by empty or nonexisting branches.

From
Junio C Hamano <junkio@cox.net>
Date
Jul 23, 2005, 02:08 UTC
Message-ID
<7vzmse6zps.fsf@assigned-by-dhcp.cox.net>

When not specifying the start point explicitly, we ended up emitting ^0 in addition to the default HEAD. Be careful to see if we have "$2" before finding out which commit to base the new branch on.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 git-branch-script |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
baf3c4ffceae925d836f19382611968699414cd6
diff --git a/git-branch-script b/git-branch-script
--- a/git-branch-script
+++ b/git-branch-script
@@ -3,7 +3,13 @@
 . git-sh-setup-script || die "Not a git archive"
 
 branchname="$1"
-rev=$(git-rev-parse --verify --default HEAD "$2"^0) || exit
+case "$2" in
+'')
+	head=HEAD ;;
+*)
+	head="$2^0" ;;
+esac
+rev=$(git-rev-parse --revs-only --verify "$head") || exit
 
 [ -z "$branchname" ] && die "git branch: I want a branch name"
 [ -e "$GIT_DIR/refs/heads/$branchname" ] && die "$branchname already exists"
Message 1 of 1 in “git-branch: avoid getting confused by empty or nonexisting branches.”
  1. git-branch: avoid getting confused by empty or nonexisting branches.Junio C Hamano, Jul 23, 2005

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.