git-config-set: Properly terminate strings with '\0'
[git.git] / git-checkout.sh
index 73652fa..4c08f36 100755 (executable)
@@ -1,6 +1,10 @@
 #!/bin/sh
 . git-sh-setup || die "Not a git archive"
 
+usage () {
+    die "usage: git checkout [-f] [-b <new_branch>] [<branch>] [<paths>...]"
+}
+
 old=$(git-rev-parse HEAD)
 new=
 force=
@@ -26,6 +30,9 @@ while [ "$#" != "0" ]; do
        --)
                break
                ;;
+       -*)
+               usage
+               ;;
        *)
                if rev=$(git-rev-parse --verify "$arg^0" 2>/dev/null)
                then
@@ -119,7 +126,9 @@ fi
 #
 if [ "$?" -eq 0 ]; then
        if [ "$newbranch" ]; then
-               echo $new > "$GIT_DIR/refs/heads/$newbranch"
+               leading=`expr "refs/heads/$newbranch" : '\(.*\)/'` &&
+               mkdir -p "$GIT_DIR/$leading" &&
+               echo $new >"$GIT_DIR/refs/heads/$newbranch" || exit
                branch="$newbranch"
        fi
        [ "$branch" ] &&