1#!/bin/sh 2 3. git-sh-setup 4 5usage () { 6echo>&2"usage:$(basename $0)"' [-d <branch>] | [[-f] <branch> [start-point]] 7 8If no arguments, show available branches and mark current branch with a star. 9If one argument, create a new branch <branchname> based off of current HEAD. 10If two arguments, create a new branch <branchname> based off of <start-point>. 11' 12exit1 13} 14 15headref=$(GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD | 16sed-e's|^refs/heads/||') 17 18delete_branch () { 19 option="$1" 20shift 21for branch_name 22do 23case",$headref,"in 24",$branch_name,") 25 die "Cannot delete the branch you are on.";; 26,,) 27 die "What branch are you on anyway?";; 28esac 29 branch=$(cat "$GIT_DIR/refs/heads/$branch_name")&& 30 branch=$(git-rev-parse --verify "$branch^0")|| 31 die "Seriously, what branch are you talking about?" 32case"$option"in 33-D) 34;; 35*) 36 mbs=$(git-merge-base -a "$branch" HEAD | tr '\012' ' ') 37case"$mbs"in 38*' '$branch' '*) 39# the merge base of branch and HEAD contains branch -- 40# which means that the HEAD contains everything in the HEAD. 41;; 42*) 43echo>&2"The branch '$branch_name' is not a strict subset of your current HEAD. 44 If you are sure you want to delete it, run 'git branch -D$branch_name'." 45exit1 46;; 47esac 48;; 49esac 50rm-f"$GIT_DIR/refs/heads/$branch_name" 51echo"Deleted branch$branch_name." 52done 53exit0 54} 55 56force= 57while case"$#,$1"in0,*)break;; *,-*) ;; *)break;;esac 58do 59case"$1"in 60-d|-D) 61 delete_branch "$@" 62exit 63;; 64-f) 65 force="$1" 66;; 67--) 68shift 69break 70;; 71-*) 72 usage 73;; 74esac 75shift 76done 77 78case"$#"in 790) 80 git-rev-parse --symbolic --all| 81sed-ne's|^refs/heads/||p'| 82sort| 83whileread ref 84do 85iftest"$headref"="$ref" 86then 87 pfx='*' 88else 89 pfx=' ' 90fi 91echo"$pfx$ref" 92done 93exit0;; 941) 95head=HEAD ;; 962) 97head="$2^0";; 98esac 99branchname="$1" 100 101rev=$(git-rev-parse --verify "$head")||exit 102 103git-check-ref-format"heads/$branchname"|| 104 die "we do not like '$branchname' as a branch name." 105 106if[-e"$GIT_DIR/refs/heads/$branchname"] 107then 108iftest''="$force" 109then 110 die "$branchnamealready exists." 111eliftest"$branchname"="$headref" 112then 113 die "cannot force-update the current branch." 114fi 115fi 116git update-ref"refs/heads/$branchname"$rev 117