This commit is contained in:
David Heinemeier Hansson
2025-09-17 10:43:52 +02:00
parent e14d58fe54
commit d92e13143f
2 changed files with 19 additions and 6 deletions

View File

@@ -7,14 +7,27 @@ if (($# == 0)); then
exit 1
fi
new_branch="$1"
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
if ! git -C "$OMARCHY_PATH" diff --quiet || ! git -C "$OMARCHY_PATH" diff --cached --quiet; then
stashed=true
git -C "$OMARCHY_PATH" stash push -u -m "Autostash before switching to $branch"
else
stashed=false
fi
# Switch branches
git -C "$OMARCHY_PATH" switch "$branch"
# Reapply stash if we made one
if [[ $stashed == true ]]; then
if ! git -C "$OMARCHY_PATH" stash pop; then
echo "⚠️ Conflicts when applying stash — stash kept"
fi
fi
# Update the system from the new branch
omarchy-update-perform