#!/bin/bash

# gitmk-branch -- like git-branch, but acts also on the parallel auxiliary branches.

# The principle difference between `gitmk-branch` and `gitmk-inherit` is
# that `gitmk-inherit` works on the currently checked out branch (extends it)
# whereas `gitmk-branch` creates the new branches, but stands on the old one.
# So in such form, they cannot be refactored into one command.


set -e # exit on any error immediately!

readonly GOAL="$1"
readonly NEWBRANCH="$2"

if [[ "$3" ]]; then
    readonly BASE="$3"
else
    readonly headref="$(git symbolic-ref HEAD)"
    readonly BASE="${headref##refs/heads/}"
fi

set -x

git branch "$NEWBRANCH" "$BASE"
git branch "$NEWBRANCH"_/AUTO/"$GOAL" "$BASE"_/AUTO/"$GOAL"
git branch "$NEWBRANCH"_/OUT/"$GOAL" "$BASE"_/OUT/"$GOAL"
