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