{"thread":{"id":"1750","subject":"[PATCH] Do not create bogus branch from flag to git branch","startedAt":"2005-09-08T02:13:26Z","lastAt":"2005-09-08T02:13:26Z","messageCount":1,"participants":["Amos Waterland"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"8187","messageId":"20050908021326.GA18776@rossby.metr.ou.edu","threadId":"1750","inReplyTo":null,"subject":"[PATCH] Do not create bogus branch from flag to git branch","fromName":"Amos Waterland","fromEmail":"apw@rossby.metr.ou.edu","sentAt":"2005-09-08T02:13:26Z","receivedAt":"2005-09-08T02:13:26Z","isPatch":true,"sender":{"key":"apw@debian.org","avatar":null},"body":"If you run `git branch --help', you will unexpectedly have created a new\nbranch named \"--help\".  This simple patch adds logic and a usage\nstatement to catch this and similar problems, and adds a testcase for it.\n\nSigned-off-by: Amos Waterland <apw@rossby.metr.ou.edu>\n\n---\n\n git-branch-script |   16 ++++++++++++++++\n t/t3200-branch.sh |   27 +++++++++++++++++++++++++++\n 2 files changed, 43 insertions(+), 0 deletions(-)\n create mode 100755 t/t3200-branch.sh\n\n09dc220283888eabd4dbb3ca647d13de6d6c876e\ndiff --git a/git-branch-script b/git-branch-script\n--- a/git-branch-script\n+++ b/git-branch-script\n@@ -2,6 +2,16 @@\n \n . git-sh-setup-script || die \"Not a git archive\"\n \n+usage () {\n+    echo >&2 \"usage: $(basename $0)\"' [<branchname> [start-point]]\n+\n+If no arguments, show available branches and mark current branch with a star.\n+If one argument, create a new branch <branchname> based off of current HEAD.\n+If two arguments, create a new branch <branchname> based off of <start-point>.\n+'\n+    exit 1\n+}\n+\n case \"$#\" in\n 0)\n \theadref=$(readlink \"$GIT_DIR/HEAD\" | sed -e 's|^refs/heads/||')\n@@ -25,6 +35,12 @@ case \"$#\" in\n \thead=\"$2^0\" ;;\n esac\n branchname=\"$1\"\n+\n+case \"$branchname\" in\n+-*)\n+\tusage;;\n+esac\n+\n rev=$(git-rev-parse --verify \"$head\") || exit\n \n [ -e \"$GIT_DIR/refs/heads/$branchname\" ] && die \"$branchname already exists\"\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nnew file mode 100755\n--- /dev/null\n+++ b/t/t3200-branch.sh\n@@ -0,0 +1,27 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2005 Amos Waterland\n+#\n+\n+test_description='git branch --foo should not create bogus branch\n+\n+This test runs git branch --help and checks that the argument is properly\n+handled.  Specifically, that a bogus branch is not created.\n+'\n+. ./test-lib.sh\n+\n+test_expect_success \\\n+    'prepare an trivial repository' \\\n+    'echo Hello > A &&\n+     git update-cache --add A &&\n+     git commit -m \"Initial commit.\"'\n+\n+test_expect_failure \\\n+    'git branch --help should return error code' \\\n+    'git branch --help'\n+\n+test_expect_failure \\\n+    'git branch --help should not have created a bogus branch' \\\n+    'test -f .git/refs/heads/--help'\n+\n+test_done\n"}]}