Files
Ziad Arafat 7ca1845213 Add dot sync for dotfiles-only updates
dot update also upgrades Flatpak apps, mise tools, Claude and checks for
missing apps, which is slow for a one-file change. dot sync pulls the
checkout with --ff-only and switches, nothing else; dot update
--switch-only is an alias. Serialise concurrent home-manager runs on
~/.config/dotfiles/switch.lock so two switches cannot fight over the Nix
store, and cover the path with tests/sync.sh.
2026-12-02 11:57:19 -07:00

53 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# dot sync: pull --ff-only + switch only. No upgrades, no flake input bump.
set -euo pipefail
cd "$(dirname "$0")/.."
fixture="$(mktemp -d)"
trap 'rm -rf "$fixture"' EXIT
export HOME="$fixture/home"
mkdir -p "$HOME/.config/dotfiles" "$fixture/repo"
DOTFILES_DIR="$fixture/repo"
export DOTFILES_DIR
# Load the CLI without running main().
source <(sed '$d' bin/dot)
STATE_DIR="$HOME/.config/dotfiles"
log="$fixture/calls.log"
: >"$log"
git() { printf 'git %s\n' "$*" >>"$log"; }
cmd_switch() { printf 'switch %s\n' "${*:-}" >>"$log"; }
flatpak() { printf 'flatpak %s\n' "$*" >>"$log"; }
mise() { printf 'mise %s\n' "$*" >>"$log"; }
claude() { printf 'claude %s\n' "$*" >>"$log"; }
cmd_apps() { printf 'apps\n' >>"$log"; }
have() { case "$1" in git|flatpak|mise|claude) return 0;; *) return 1;; esac; }
cmd_sync
grep -q '^git -C .* pull --ff-only$' "$log" || { echo "FAIL: no ff-only pull"; cat "$log"; exit 1; }
grep -q '^switch' "$log" || { echo "FAIL: no switch"; cat "$log"; exit 1; }
for unwanted in flatpak mise claude apps; do
if grep -qi "^$unwanted" "$log"; then echo "FAIL: dot sync ran $unwanted"; cat "$log"; exit 1; fi
done
# --inputs is refused rather than silently ignored.
: >"$log"
if ( cmd_sync --inputs ) 2>/dev/null; then echo "FAIL: dot sync accepted --inputs"; exit 1; fi
[ -s "$log" ] && { echo "FAIL: dot sync --inputs still pulled"; cat "$log"; exit 1; }
# `dot sync <profile>` passes the profile through to the switch.
: >"$log"
cmd_sync headless
grep -q '^switch headless$' "$log" || { echo "FAIL: profile not forwarded"; cat "$log"; exit 1; }
# The concurrency guard serialises a second run instead of racing it.
exec 8>>"$STATE_DIR/switch.lock"
flock 8
switch_lock_ok=0
if flock -n "$STATE_DIR/switch.lock" 2>/dev/null; then switch_lock_ok=1; fi
[ "$switch_lock_ok" = 0 ] || { echo "FAIL: lock not held by a concurrent run"; exit 1; }
echo "ok dot sync"