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