Implement parent branching. Track who a branch comes from and only allow merging...
[socialgit.git] / bin / newbranch
blob6d20da85e786129a99327b8ff1a55008cce0f6a5
1 #!/bin/sh
2 # newbranch
4 echo $1 | grep "^[A-Za-z0-9_]*$" &> /dev/null
5 if [ "$?" != "0" ]; then
6 echo "Invalid branch name. Must be letters, digits, and underscores."
7 exit 1
8 fi
10 PARENT_BRANCH=`currentbranchname`
12 if ( git branch|grep "[^ ]$1$" ); then
13 echo "This branch already exists locally."
14 exit -1
17 if ( git branch -r |grep "[^ ]origin/$1$" ); then
18 echo "This branch already exists remotely."
19 exit -1
22 # Change to master, stashing any dirty working copy files
23 changebranch master
25 # Create the new branch, pull in any existing commits for it from the central server
26 git branch $1
27 changebranch $1
28 git tag -m "parent:$PARENT_BRANCH" branch-created.$1
30 # Look for hooks
31 HOOK_POST_CREATE_BRANCH=./`git rev-parse --show-cdup`.socialgit/hooks/post-create-branch
32 $(ls $HOOK_POST_CREATE_BRANCH 2>/dev/null) && $HOOK_POST_CREATE_BRANCH
34 commitbranch