#!/bin/bash

set -e

if (($# == 0)); then
  echo "Usage: omarchy-verion-branch-set [master|dev]"
  exit 1
fi

new_branch="$1"

# Snapshot before switching branch
omarchy-snapshot create || [ $? -eq 127 ]

# Checkout the new branch
git -C $OMARCHY_PATH checkout $new_branch --autostash
git -C $OMARCHY_PATH diff --check || git -C $OMARCHY_PATH reset --merge

# Update the system from the new branch
omarchy-update-perform
