Update active dev checkout with system

This commit is contained in:
David Heinemeier Hansson
2026-07-23 15:28:32 -07:00
parent 7a9947a732
commit 8e549c27d0
7 changed files with 227 additions and 4 deletions
+88 -1
View File
@@ -8,6 +8,7 @@ test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT
stub_bin="$test_tmp/bin"
git_log="$test_tmp/git.log"
mkdir -p "$stub_bin"
cat >"$stub_bin/checkupdates" <<'SH'
@@ -52,8 +53,48 @@ exit 0
SH
chmod +x "$stub_bin/pacman"
cat >"$stub_bin/git" <<'SH'
#!/bin/bash
printf '%s\n' "$*" >>"$TEST_GIT_LOG"
[[ $1 == "-C" ]] || exit 1
shift 2
case "$1" in
fetch)
[[ ${TEST_GIT_FETCH:-ok} == "ok" ]]
;;
rev-parse)
case "$2" in
--is-inside-work-tree)
[[ ${TEST_GIT_CHECKOUT:-yes} == "yes" ]] || exit 1
echo true
;;
--abbrev-ref)
[[ ${TEST_GIT_UPSTREAM:-origin/quattro} != "none" ]] || exit 1
echo "${TEST_GIT_UPSTREAM:-origin/quattro}"
;;
*)
exit 1
;;
esac
;;
rev-list)
echo "${TEST_GIT_BEHIND:-0}"
;;
*)
exit 1
;;
esac
SH
chmod +x "$stub_bin/git"
run_checker() {
PATH="$stub_bin:$PATH" "$ROOT/bin/omarchy-update-available"
OMARCHY_PATH="${TEST_OMARCHY_PATH:-/usr/share/omarchy}" \
TEST_GIT_LOG="$git_log" \
PATH="$stub_bin:$PATH" \
"$ROOT/bin/omarchy-update-available"
}
capture_checker() {
@@ -124,3 +165,49 @@ fi
[[ $status -eq 1 ]] || fail "update checker exits non-zero when no updates are available"
grep -q '^Omarchy is up to date$' "$stdout" || fail "update checker prints up-to-date message"
pass "update checker reports up-to-date Omarchy packages"
: >"$git_log"
if capture_checker "$stdout" "$stderr" \
TEST_CHECKUPDATES=none \
TEST_INSTALLED_PACKAGE=none \
TEST_OMARCHY_PATH="$test_tmp/checkout" \
TEST_GIT_BEHIND=2; then
status=0
else
status=$?
fi
[[ $status -eq 0 ]] || fail "update checker exits successfully when dev commits are available"
grep -Fx 'omarchy-dev-checkout 2 new commits on origin/quattro' "$stdout" >/dev/null ||
fail "update checker reports available dev commits" "$(cat "$stdout")"
grep -Fx -- "-C $test_tmp/checkout fetch --quiet" "$git_log" >/dev/null ||
fail "update checker fetches the dev checkout upstream" "$(cat "$git_log")"
pass "update checker detects new commits in the dev checkout"
if capture_checker "$stdout" "$stderr" \
TEST_CHECKUPDATES=none \
TEST_INSTALLED_PACKAGE=none \
TEST_OMARCHY_PATH="$test_tmp/checkout" \
TEST_GIT_BEHIND=0; then
status=0
else
status=$?
fi
[[ $status -eq 1 ]] || fail "update checker exits non-zero when the dev checkout is current"
grep -q '^Omarchy is up to date$' "$stdout" || fail "update checker reports a current dev checkout"
pass "update checker ignores a current dev checkout"
if capture_checker "$stdout" "$stderr" \
TEST_CHECKUPDATES=none \
TEST_INSTALLED_PACKAGE=none \
TEST_OMARCHY_PATH="$test_tmp/checkout" \
TEST_GIT_BEHIND=1 \
TEST_GIT_FETCH=fail; then
status=0
else
status=$?
fi
[[ $status -eq 0 ]] || fail "update checker uses cached upstream state when fetch fails"
grep -Fx 'omarchy-dev-checkout 1 new commit on origin/quattro' "$stdout" >/dev/null ||
fail "update checker reports cached dev commits after a fetch failure" "$(cat "$stdout")"
[[ ! -s $stderr ]] || fail "update checker keeps dev fetch failures quiet" "$(cat "$stderr")"
pass "update checker uses cached dev state when fetching is unavailable"
+84
View File
@@ -0,0 +1,84 @@
#!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT
stub_bin="$test_tmp/bin"
git_log="$test_tmp/git.log"
checkout="$test_tmp/checkout"
mkdir -p "$stub_bin" "$checkout"
cat >"$stub_bin/git" <<'SH'
#!/bin/bash
printf '%s\n' "$*" >>"$TEST_GIT_LOG"
[[ $1 == "-C" ]] || exit 1
shift 2
case "$1" in
rev-parse)
case "$2" in
--is-inside-work-tree)
[[ ${TEST_GIT_CHECKOUT:-yes} == "yes" ]] || exit 1
echo true
;;
--abbrev-ref)
[[ ${TEST_GIT_UPSTREAM:-origin/quattro} != "none" ]] || exit 1
echo "${TEST_GIT_UPSTREAM:-origin/quattro}"
;;
*)
exit 1
;;
esac
;;
pull)
[[ $2 == "--ff-only" ]]
;;
*)
exit 1
;;
esac
SH
chmod +x "$stub_bin/git"
run_dev_update() {
OMARCHY_PATH="$1" \
TEST_GIT_LOG="$git_log" \
PATH="$stub_bin:$PATH" \
"$ROOT/bin/omarchy-update-dev"
}
: >"$git_log"
run_dev_update /usr/share/omarchy
[[ ! -s $git_log ]] || fail "package-backed updates do not invoke git" "$(cat "$git_log")"
pass "package-backed updates skip the dev checkout step"
: >"$git_log"
run_dev_update "$checkout"
grep -Fx -- "-C $checkout pull --ff-only" "$git_log" >/dev/null ||
fail "dev checkout update pulls its upstream with fast-forward only" "$(cat "$git_log")"
pass "dev checkout update pulls its configured upstream"
: >"$git_log"
TEST_GIT_UPSTREAM=none run_dev_update "$checkout"
if grep -q ' pull ' "$git_log"; then
fail "dev checkout without an upstream is not pulled" "$(cat "$git_log")"
fi
pass "dev checkout without an upstream is skipped safely"
: >"$git_log"
if TEST_GIT_CHECKOUT=no run_dev_update "$checkout" >"$test_tmp/invalid.out" 2>"$test_tmp/invalid.err"; then
fail "invalid dev checkout fails the update"
fi
grep -F "OMARCHY_PATH is not a git checkout: $checkout" "$test_tmp/invalid.err" >/dev/null ||
fail "invalid dev checkout reports the configured path" "$(cat "$test_tmp/invalid.err")"
pass "invalid dev checkout fails with a useful error"
grep -qE '^ *omarchy-update-dev$' "$ROOT/bin/omarchy-update" ||
fail "top-level update includes the dev checkout step"
pass "top-level update includes the dev checkout step"
+1
View File
@@ -34,6 +34,7 @@ SH
for command in \
omarchy-toggle-idle \
systemd-inhibit \
omarchy-update-dev \
omarchy-update-keyring \
omarchy-update-system-pkgs \
omarchy-migrate \