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