Merge branch 'mob' of git://repo.or.cz/guilt/mob
[guilt.git] / guilt-branch
blobb2a71e2449f2121703b3007e08a115d10352cab1
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2007-2011
6 USAGE="[<new_name>]"
7 if [ -z "$GUILT_VERSION" ]; then
8 echo "Invoking $GUILT directly is no longer supported." >&2
9 exit 1
12 if [ $# -gt 1 ]; then
13 usage
16 _main() {
18 # make sure that there are no unapplied changes
19 if ! must_commit_first; then
20 die "Uncommited changes detected. Refresh first."
23 if [ $# -eq 0 ]; then
24 newbranch="$branch-`date +%Y-%m-%d`"
25 else
26 newbranch="$1"
29 if [ -e "$GUILT_DIR/$newbranch" ]; then
30 die "Patch directory for branch \"$newbranch\" already exists."
33 cat "$applied" | while read n; do
34 git update-ref "refs/patches/$newbranch/$n" \
35 `git rev-parse "refs/patches/$branch/$n"` ""
36 done
38 if $old_style_prefix || [ -z "`get_top 2>/dev/null`" ]
39 then
40 newgitbranch="$newbranch"
41 else
42 git update-ref "refs/heads/$newbranch" "refs/heads/$branch" ""
43 newgitbranch="$GUILT_PREFIX$newbranch"
46 git branch "$newgitbranch"
47 git checkout "$newgitbranch"
49 mkdir -p "$GUILT_DIR/`dirname $newbranch`"
51 # copy the patch dir
52 cp_a "$GUILT_DIR/$branch" "$GUILT_DIR/$newbranch"
54 # copy the refs