test: lab 30 checks that each tier has its own chezmoi state
The private init's --persistent-state (chezmoistate-private.boltdb) and its
unit assertion landed in 06b03c9. chezmoi keeps its state next to the config
file, so the tiers used to share chezmoistate.boltdb and each wrote its
config-template hash over the other's: after the private init every public
command warned "config file template has changed".
Lab 30 now asserts the private state file exists, private.toml names it, and
neither tier warns and both statuses are clean after both inits. The fake
private tier is resynced with the real template and cmp alias.
This commit is contained in:
1 parent
0279d4a5d0
commit
28bcea9850
3 files changed
+43
-3
No files matched your search
@@ -24,6 +24,18 @@
|
|||||||
# so the symptom was `git commit` not knowing who you are, days later, with
|
# so the symptom was `git commit` not knowing who you are, days later, with
|
||||||
# nothing pointing back at the install that caused it. A loud failure would
|
# nothing pointing back at the install that caused it. A loud failure would
|
||||||
# have been a smaller bug.
|
# have been a smaller bug.
|
||||||
|
#
|
||||||
|
# The same goes for the PERSISTENT STATE. chezmoi keeps it next to the config
|
||||||
|
# file, so both tiers shared ~/.config/chezmoi/chezmoistate.boltdb: each wrote
|
||||||
|
# its own config-template hash and run_onchange hashes over the other's, and
|
||||||
|
# after the private init every public command warned "config file template has
|
||||||
|
# changed". Running the init it suggests only moved the warning to this tier.
|
||||||
|
# So this tier gets its own state file, beside private.toml. This key covers a
|
||||||
|
# bare `chezmoi -c private.toml`; `dotup` and `cmp` also pass the same path as
|
||||||
|
# --persistent-state, because `init` opens the state BEFORE it writes this key,
|
||||||
|
# so the first init (or a re-init from a config that predates it) would
|
||||||
|
# otherwise record its hash in the public tier's file.
|
||||||
|
persistentState = {{ joinPath (dir .chezmoi.configFile) "chezmoistate-private.boltdb" | quote }}
|
||||||
|
|
||||||
[data]
|
[data]
|
||||||
gitName = {{ promptStringOnce . "gitName" "git user.name" | quote }}
|
gitName = {{ promptStringOnce . "gitName" "git user.name" | quote }}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
# ~/.config/chezmoi/chezmoi.toml
|
# ~/.config/chezmoi/chezmoi.toml
|
||||||
# private dotup, --source ... -c .../private.toml -> ~/.local/share/dotfiles-private
|
# private dotup, --source ... -c .../private.toml -> ~/.local/share/dotfiles-private
|
||||||
# ~/.config/chezmoi/private.toml
|
# ~/.config/chezmoi/private.toml
|
||||||
|
# ~/.config/chezmoi/chezmoistate-private.boltdb
|
||||||
#
|
#
|
||||||
# The -c is not cosmetic. Both tiers used to render their .chezmoi.toml.tmpl to
|
# The -c is not cosmetic. Both tiers used to render their .chezmoi.toml.tmpl to
|
||||||
# the same default path, so re-running the PUBLIC installer overwrote the config
|
# the same default path, so re-running the PUBLIC installer overwrote the config
|
||||||
@@ -51,10 +52,17 @@
|
|||||||
# politely when their data is missing, so the first symptom was `git commit` not
|
# politely when their data is missing, so the first symptom was `git commit` not
|
||||||
# knowing who you are, days later and unconnected to the install that caused it.
|
# knowing who you are, days later and unconnected to the install that caused it.
|
||||||
#
|
#
|
||||||
# -S and -c must stay in step with dotup's PRIV_SRC and PRIV_CFG. If you move one,
|
# The --persistent-state is the same lesson for chezmoi's state file: shared, each
|
||||||
# move the other, or cmp reads a config that describes a different source tree.
|
# tier overwrote the other's config-template hash, and the public tier warned
|
||||||
|
# "config file template has changed" after every private command. private.toml
|
||||||
|
# names this file too, but `cmp init` opens the state before it rewrites that, so
|
||||||
|
# the alias has to carry it.
|
||||||
|
#
|
||||||
|
# -S, -c and --persistent-state must stay in step with dotup's PRIV_SRC, PRIV_CFG
|
||||||
|
# and PRIV_STATE. If you move one, move the others, or cmp reads a config that
|
||||||
|
# describes a different source tree.
|
||||||
alias cm='chezmoi'
|
alias cm='chezmoi'
|
||||||
alias cmp='chezmoi -S ${XDG_DATA_HOME:-$HOME/.local/share}/dotfiles-private -c ${XDG_CONFIG_HOME:-$HOME/.config}/chezmoi/private.toml'
|
alias cmp='chezmoi -S ${XDG_DATA_HOME:-$HOME/.local/share}/dotfiles-private -c ${XDG_CONFIG_HOME:-$HOME/.config}/chezmoi/private.toml --persistent-state ${XDG_CONFIG_HOME:-$HOME/.config}/chezmoi/chezmoistate-private.boltdb'
|
||||||
|
|
||||||
# Refresh ~/.config/zsh/secrets.zsh from Bitwarden Secrets Manager on demand.
|
# Refresh ~/.config/zsh/secrets.zsh from Bitwarden Secrets Manager on demand.
|
||||||
# `cmp apply` does the same thing via run_after_50-secrets.sh.
|
# `cmp apply` does the same thing via run_after_50-secrets.sh.
|
||||||
|
|||||||
@@ -202,4 +202,24 @@ git config --get 'url.git@github.com:.pushinsteadof' >/dev/null 2>&1 \
|
|||||||
|| fail "the GitHub push-over-ssh rewrite is gone entirely"
|
|| fail "the GitHub push-over-ssh rewrite is gone entirely"
|
||||||
ok "GitHub reads stay https; only pushes are rewritten to ssh"
|
ok "GitHub reads stay https; only pushes are rewritten to ssh"
|
||||||
|
|
||||||
|
# ---- two tiers, two state files: neither warns about the other --------------
|
||||||
|
# Both tiers used to share ~/.config/chezmoi/chezmoistate.boltdb, and each wrote
|
||||||
|
# its config-template hash over the other's, so after this init every public
|
||||||
|
# command said "config file template has changed". `run_` scripts always show
|
||||||
|
# as " R"; anything else in either status is drift.
|
||||||
|
CZ=$HOME/.config/chezmoi
|
||||||
|
[ -f "$CZ/chezmoistate-private.boltdb" ] || fail "the private tier has no state file of its own"
|
||||||
|
grep -q '^persistentState = ' "$CZ/private.toml" || fail "private.toml does not name its state file"
|
||||||
|
pub=$(chezmoi status 2>&1)
|
||||||
|
prv=$(chezmoi -S "$HOME/.local/share/dotfiles-private" -c "$CZ/private.toml" \
|
||||||
|
--persistent-state "$CZ/chezmoistate-private.boltdb" status 2>&1)
|
||||||
|
for t in pub prv; do
|
||||||
|
eval "o=\$$t"
|
||||||
|
case $o in *"template has changed"*|*warning*)
|
||||||
|
printf '%s\n' "$o" | sed 's/^/ | /'; fail "$t tier warns after both inits" ;; esac
|
||||||
|
d=$(printf '%s\n' "$o" | grep -v '^ R ' | grep -v '^$' || true)
|
||||||
|
[ -z "$d" ] || { printf '%s\n' "$d" | sed 's/^/ | /'; fail "$t tier status is not clean"; }
|
||||||
|
done
|
||||||
|
ok "each tier has its own state file; neither warns and both statuses are clean"
|
||||||
|
|
||||||
echo "PRIVATE TIER PASS"
|
echo "PRIVATE TIER PASS"
|
||||||
Reference in new issue
Block a user