Link dev channel to home checkout

This commit is contained in:
David Heinemeier Hansson
2026-07-23 14:01:36 -07:00
parent e68b0f025d
commit f911851319
3 changed files with 39 additions and 81 deletions
+16 -39
View File
@@ -23,46 +23,22 @@ WARNING
gum confirm --default=false "Enable Dev anyway?"
}
choose_dev_checkout() {
local default_path="$HOME/Work/omarchy"
local path="${OMARCHY_DEV_PATH:-}"
if [[ -z $path ]]; then
path=$(gum input --value "$default_path" --placeholder "$default_path" --header "Where should Dev checkout live? Existing non-checkout paths will not be overwritten.") || exit 1
fi
path="${path:-$default_path}"
case "$path" in
"~") path="$HOME" ;;
"~/"*) path="$HOME/${path#~/}" ;;
/*) ;;
*) path="$PWD/$path" ;;
esac
if [[ -e $path && ! -d $path/.git ]]; then
fail "$path already exists and is not a git checkout. Choose an empty path or an existing Omarchy checkout."
fi
if [[ -d $path/.git && ( ! -d $path/bin || ! -d $path/default || ! -d $path/shell ) ]]; then
fail "$path is a git checkout, but it does not look like Omarchy."
fi
printf '%s\n' "$path"
}
sync_dev_checkout() {
validate_dev_checkout() {
local checkout="$1"
if [[ -d $checkout/.git ]]; then
echo "Updating Dev checkout at $checkout"
git -C "$checkout" fetch origin quattro
git -C "$checkout" checkout quattro 2>/dev/null || git -C "$checkout" checkout --track origin/quattro
git -C "$checkout" pull --ff-only origin quattro
else
mkdir -p "$(dirname -- "$checkout")"
git clone --branch quattro --single-branch https://github.com/basecamp/omarchy.git "$checkout"
if [[ -e $checkout && ! -d $checkout/.git ]]; then
fail "$checkout already exists and is not a git checkout."
fi
if [[ -d $checkout/.git && ( ! -d $checkout/bin || ! -d $checkout/default || ! -d $checkout/shell ) ]]; then
fail "$checkout is a git checkout, but it does not look like Omarchy."
fi
}
link_dev_checkout() {
local checkout="$1"
[[ -d $checkout/.git ]] || git clone https://github.com/basecamp/omarchy.git "$checkout"
omarchy-dev-link "$checkout"
}
@@ -86,7 +62,8 @@ case "$channel" in
;;
dev)
confirm_dev || { echo "Cancelled."; exit 0; }
dev_checkout=$(choose_dev_checkout)
dev_checkout="$HOME/omarchy"
validate_dev_checkout "$dev_checkout"
pacman_channel=edge
packages=(omarchy-dev omarchy-settings-dev)
;;
@@ -101,7 +78,7 @@ omarchy-refresh-pacman "$pacman_channel"
# --ask 4 accepts omarchy <-> omarchy-dev replacement prompts without file overwrites.
sudo env OMARCHY_UPDATE_PACMAN=1 pacman -S --needed --noconfirm --ask 4 "${packages[@]}"
if [[ -z $dev_checkout ]] && omarchy-cmd-present omarchy-dev-unlink; then
if [[ -z $dev_checkout ]]; then
omarchy-dev-unlink
export OMARCHY_PATH=/usr/share/omarchy
fi
@@ -109,5 +86,5 @@ fi
omarchy-update -y
if [[ -n $dev_checkout ]]; then
sync_dev_checkout "$dev_checkout"
link_dev_checkout "$dev_checkout"
fi
+1 -1
View File
@@ -3,7 +3,7 @@
# omarchy:summary=Point Omarchy at a local checkout after reboot
# omarchy:group=dev
# omarchy:args=<path-to-checkout>
# omarchy:examples=omarchy dev link ~/Work/omarchy/omarchy-installer
# omarchy:examples=omarchy dev link ~/omarchy
set -euo pipefail
+22 -41
View File
@@ -47,22 +47,9 @@ write_stub gum '#!/bin/bash
printf "gum" >>"$OMARCHY_CHANNEL_TEST_LOG"
for arg in "$@"; do printf "\t%s" "$arg" >>"$OMARCHY_CHANNEL_TEST_LOG"; done
printf "\n" >>"$OMARCHY_CHANNEL_TEST_LOG"
if [[ $1 == "input" ]]; then
printf "%s\n" "${OMARCHY_TEST_GUM_INPUT:-$HOME/Work/omarchy}"
fi
exit 0
'
write_stub omarchy-cmd-missing '#!/bin/bash
[[ $1 == "git" ]] && exit 1
exit 0
'
write_stub omarchy-cmd-present '#!/bin/bash
[[ $1 == "omarchy-dev-unlink" || $1 == "gum" || $1 == "git" ]] && exit 0
exit 1
'
write_stub git '#!/bin/bash
printf "git" >>"$OMARCHY_CHANNEL_TEST_LOG"
for arg in "$@"; do printf "\t%s" "$arg" >>"$OMARCHY_CHANNEL_TEST_LOG"; done
@@ -96,8 +83,6 @@ esac
run_channel() {
: >"$log_file"
OMARCHY_CHANNEL_TEST_LOG="$log_file" \
OMARCHY_DEV_PATH="${OMARCHY_DEV_PATH:-}" \
OMARCHY_TEST_GUM_INPUT="${OMARCHY_TEST_GUM_INPUT:-}" \
OMARCHY_PATH="$ROOT" \
HOME="$test_tmp/home" \
PATH="$stub_bin:$ROOT/bin:$PATH" \
@@ -112,17 +97,6 @@ assert_log_line() {
pass "$description"
}
assert_numbered_log_line() {
local number="$1"
local expected="$2"
local description="$3"
local actual=""
actual=$(sed -n "${number}p" "$log_file")
[[ $actual == $expected ]] || fail "$description" "$(cat "$log_file")"
pass "$description"
}
run_channel stable
assert_log_line $'refresh\tstable' "stable refreshes the stable pacman channel"
assert_log_line $'sudo\tenv\tOMARCHY_UPDATE_PACMAN=1\tpacman\t-S\t--needed\t--noconfirm\t--ask\t4\tomarchy\tomarchy-settings' "stable installs stable Omarchy packages"
@@ -141,20 +115,9 @@ assert_log_line $'sudo\tenv\tOMARCHY_UPDATE_PACMAN=1\tpacman\t-S\t--needed\t--no
assert_log_line 'unlink' "edge remains package-backed"
assert_log_line $'update\t-y' "edge runs the normal update pipeline"
checkout="$test_tmp/dev-checkout"
default_checkout="$test_tmp/home/Work/omarchy"
OMARCHY_TEST_GUM_INPUT="$checkout" run_channel dev
assert_numbered_log_line 1 $'gum\tconfirm\t--default=false\tEnable Dev anyway?' "dev warns before changing packages"
assert_numbered_log_line 2 $'gum\tinput\t--value\t'"$default_checkout"$'\t--placeholder\t'"$default_checkout"$'\t--header\tWhere should Dev checkout live? Existing non-checkout paths will not be overwritten.' "dev prompts for the checkout path before changing packages"
assert_log_line $'gum\tconfirm\t--default=false\tEnable Dev anyway?' "dev asks for confirmation"
assert_log_line $'refresh\tedge' "dev refreshes the edge pacman channel"
assert_log_line $'sudo\tenv\tOMARCHY_UPDATE_PACMAN=1\tpacman\t-S\t--needed\t--noconfirm\t--ask\t4\tomarchy-dev\tomarchy-settings-dev' "dev installs development Omarchy packages"
assert_log_line $'git\tclone\t--branch\tquattro\t--single-branch\thttps://github.com/basecamp/omarchy.git\t'"$checkout" "dev clones the quattro checkout"
assert_log_line $'link\t'"$checkout" "dev links the source checkout"
occupied_checkout="$test_tmp/occupied"
mkdir -p "$occupied_checkout"
if OMARCHY_TEST_GUM_INPUT="$occupied_checkout" run_channel dev >"$test_tmp/occupied.out" 2>"$test_tmp/occupied.err"; then
checkout="$test_tmp/home/omarchy"
mkdir -p "$checkout"
if run_channel dev >"$test_tmp/occupied.out" 2>"$test_tmp/occupied.err"; then
fail "dev refuses to use an occupied non-checkout path"
fi
@@ -164,6 +127,24 @@ if grep -Fx $'refresh\tedge' "$log_file" >/dev/null; then
fi
pass "dev refuses occupied non-checkout paths before package changes"
rmdir "$checkout"
run_channel dev
assert_log_line $'gum\tconfirm\t--default=false\tEnable Dev anyway?' "dev asks for confirmation"
assert_log_line $'refresh\tedge' "dev refreshes the edge pacman channel"
assert_log_line $'sudo\tenv\tOMARCHY_UPDATE_PACMAN=1\tpacman\t-S\t--needed\t--noconfirm\t--ask\t4\tomarchy-dev\tomarchy-settings-dev' "dev installs development Omarchy packages"
assert_log_line $'git\tclone\thttps://github.com/basecamp/omarchy.git\t'"$checkout" "dev clones the source checkout to ~/omarchy"
assert_log_line $'link\t'"$checkout" "dev links ~/omarchy"
run_channel stable
assert_log_line 'unlink' "switching from dev to stable unlinks the source checkout"
run_channel dev
if grep -q $'^git\tclone\t' "$log_file"; then
fail "dev reuses an existing checkout" "$(cat "$log_file")"
fi
assert_log_line $'link\t'"$checkout" "switching back to dev links ~/omarchy"
pass "switching back to dev reuses the existing ~/omarchy checkout"
current_channel() {
OMARCHY_TEST_VERSION_CHANNEL="$1" \
OMARCHY_TEST_PACKAGES="$2" \
@@ -182,4 +163,4 @@ pass "current channel detects rc"
pass "current channel detects package-backed edge"
[[ $(current_channel edge dev "$test_tmp/dev-checkout") == "dev" ]] || fail "current channel detects dev from OMARCHY_PATH"
pass "current channel detects dev from OMARCHY_PATH"
pass "current channel honors a dev link outside ~/omarchy"