#!/bin/bash
# updates a formula on a masterless or master server

set -e # everything must pass
set -x # output interpolated
set -u # no unbound variables

pname=$1
formula=$2
revision=${3:-""}

formula_root="/opt/formulas"
if [ "$pname" = "builder-private" ]; then
    formula_root="/opt"
fi
formula_path="$formula_root/$pname"

mkdir -p "$formula_root"

if [ -d "$formula_path" ]; then
    # formula exists, bring it back into a known state
    cd "$formula_path"
    git reset --hard # undo any changes
    git clean -d --force # wipe any unknown files
    git checkout master # switch to master branch

    # pull down any changes
    git pull --rebase
else
    cd "$formula_root"
    git clone "$formula" "$pname"
fi

cd "$formula_path"

if [ "$revision" != "" ]; then
    # switch to a specific revision or branch
    git checkout "$revision"
fi

#!/bin/bash
# updates a formula on a masterless or master server

set -e # everything must pass
set -u # no unbound variables

pname=$1
formula=$2
revision=${3:-""}

formula_root="/opt/formulas"
if [ "$pname" == "builder-private" ]; then
    formula_root="/opt"
fi
formula_path="$formula_root/$pname"

mkdir -p "$formula_root"

if [ -d "$formula_path" ]; then
    cd "$formula_path"
    git reset --hard
    git clean -d --force
    git pull --rebase
else
    cd "$formula_root"
    git clone "$formula" "$pname"
fi

cd "$formula_path"

if [ "$revision" != "" ]; then
    git checkout "$revision"
fi

Revert "formula is fully reset before a specific revision/branch is checked out"
Revert "formula is fully reset before a specific revision/branch is checked out"

This reverts commit 3629bfb108aad4363d0dc70685ef5d86374cf6f8.
