diff --git a/bin/omarchy-channel-set b/bin/omarchy-channel-set index 039d3292..f347317b 100755 --- a/bin/omarchy-channel-set +++ b/bin/omarchy-channel-set @@ -47,9 +47,23 @@ validate_dev_checkout() { fi } +# The dev channel refreshes pacman with the checkout's own tools. A checkout +# without this machine's region profile would silently drop its repositories. +validate_dev_region() { + local checkout="$1" region_file="${OMARCHY_REGION_FILE:-/etc/omarchy/region}" region=global + + [[ -f $region_file ]] && region=$(<"$region_file") + [[ $region == "global" ]] && return 0 + + if [[ ! -f $checkout/bin/omarchy-apply-pacman || ! -d $checkout/default/regions/$region ]]; then + fail "$checkout does not support the '$region' region, so switching would drop its package repositories. Check out a branch with default/regions/$region, or remove $region_file to use global defaults." + fi +} + link_dev_checkout() { local checkout="$1" required [[ -d $checkout/.git ]] || git clone https://github.com/omacom/omarchy.git "$checkout" + validate_dev_region "$checkout" # Check the destination before changing /etc/omarchy.conf or sudo's path. # An existing checkout is not pulled automatically and may predate this policy. diff --git a/test/shell.d/channel-test.sh b/test/shell.d/channel-test.sh index cbbfc6e8..7872c6f7 100644 --- a/test/shell.d/channel-test.sh +++ b/test/shell.d/channel-test.sh @@ -113,6 +113,7 @@ run_channel() { : >"$log_file" OMARCHY_CHANNEL_TEST_LOG="$log_file" \ OMARCHY_PATH="${OMARCHY_TEST_PATH:-$package_root}" \ + OMARCHY_REGION_FILE="${OMARCHY_TEST_REGION_FILE:-$test_tmp/no-region}" \ HOME="$test_tmp/home" \ PATH="$stub_bin:$ROOT/bin:$PATH" \ "${OMARCHY_TEST_PATH:-$package_root}/bin/omarchy-channel-set" "$@" @@ -190,6 +191,21 @@ fi assert_log_line $'link\t'"$checkout"$'\t--no-reboot' "switching back to dev links ~/omarchy" pass "switching back to dev reuses the existing ~/omarchy checkout" +printf 'cn\n' >"$test_tmp/region" +if OMARCHY_TEST_REGION_FILE="$test_tmp/region" run_channel dev >"$test_tmp/region.out" 2>"$test_tmp/region.err"; then + fail "dev refuses a checkout without this machine's region" +fi +grep -q "does not support the 'cn' region" "$test_tmp/region.err" || fail "dev explains the missing region" "$(cat "$test_tmp/region.err")" +if grep -Eq $'^(link|refresh)\t' "$log_file"; then + fail "dev refuses before linking or refreshing pacman" "$(cat "$log_file")" +fi +pass "dev refuses a checkout without the region before touching pacman" + +mkdir -p "$checkout/default/regions/cn" +touch "$checkout/bin/omarchy-apply-pacman" +OMARCHY_TEST_REGION_FILE="$test_tmp/region" run_channel dev +assert_log_line $'refresh\tedge' "dev proceeds with a checkout that supports the region" + current_channel() { OMARCHY_TEST_VERSION_CHANNEL="$1" \ OMARCHY_TEST_PACKAGES="$2" \