{"thread":{"id":"1308","subject":"[PATCH] git-branch: avoid getting confused by empty or nonexisting branches.","startedAt":"2005-07-23T02:08:47Z","lastAt":"2005-07-23T02:08:47Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"6360","messageId":"7vzmse6zps.fsf@assigned-by-dhcp.cox.net","threadId":"1308","inReplyTo":null,"subject":"[PATCH] git-branch: avoid getting confused by empty or nonexisting branches.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-07-23T02:08:47Z","receivedAt":"2005-07-23T02:08:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When not specifying the start point explicitly, we ended up\nemitting ^0 in addition to the default HEAD.  Be careful to see\nif we have \"$2\" before finding out which commit to base the new\nbranch on.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n git-branch-script |    8 +++++++-\n 1 files changed, 7 insertions(+), 1 deletions(-)\n\nbaf3c4ffceae925d836f19382611968699414cd6\ndiff --git a/git-branch-script b/git-branch-script\n--- a/git-branch-script\n+++ b/git-branch-script\n@@ -3,7 +3,13 @@\n . git-sh-setup-script || die \"Not a git archive\"\n \n branchname=\"$1\"\n-rev=$(git-rev-parse --verify --default HEAD \"$2\"^0) || exit\n+case \"$2\" in\n+'')\n+\thead=HEAD ;;\n+*)\n+\thead=\"$2^0\" ;;\n+esac\n+rev=$(git-rev-parse --revs-only --verify \"$head\") || exit\n \n [ -z \"$branchname\" ] && die \"git branch: I want a branch name\"\n [ -e \"$GIT_DIR/refs/heads/$branchname\" ] && die \"$branchname already exists\"\n"}]}