fix(init): stop --force wiping config.toml; guard skill overwrites#135
Merged
Merged
Conversation
`hm init --force` called `remove_dir_all` on the whole `.hm/` directory before recreating it and writing a single template. A repo with multiple pipelines (e.g. `pipeline.py` + `deploy.py`, as examples/elixir-phoenix ships) plus a cloud `config.toml` lost everything but the one template on `--force` — silent data loss. Now `--force` overwrites only the target template file; `config.toml`, `.gitignore`, and co-resident pipelines survive (the `.hm/` dir already exists, so `create_dir_all` is a no-op). `write_skills` also unconditionally clobbered each `SKILL.md`, destroying local edits whenever a user re-ran `hm init` and confirmed skills. It now takes `force` (threaded from `args.force`): an absent file is installed, an unchanged bundled file is a silent no-op, and a customized file is skipped with a `tracing::warn!` pointing at `--force`. The info log now distinguishes "installed" (new) from "overwrote" (force) for honest feedback. Tests: rewrote init_force_overwrites_existing -> init_force_preserves_ coresident_files (asserts config.toml + deploy.py survive while the template is rewritten); added unit tests for write_skills covering install / preserve-without-force / force-overwrite / unchanged-no-op. Fixes: init-force-wipes-dir-1, init-skills-overwrite-1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
hm init --forceused toremove_dir_allthe entire.hm/directory beforerewriting a single template. In a repo with multiple pipelines (e.g.
pipeline.py+deploy.py, asexamples/elixir-phoenixships) plus a cloudconfig.toml,--forcesilently destroyed everything but the one regeneratedtemplate — silent data loss. This PR makes
--forceoverwrite only thetarget template file (
std::fs::writeclobbers just that path;.hm/alreadyexists, so
create_dir_allis a no-op), soconfig.toml,.gitignore, andco-resident pipelines survive.
It also hardens
write_skills, which previously clobbered eachSKILL.mdunconditionally — destroying local edits on any re-run of
hm init. It nowtakes a
forceflag (threaded fromargs.force):tracing::warn!pointing at--force.The info log now distinguishes "installed" (new) from "overwrote" (force) for
honest feedback.
Findings addressed
init-force-wipes-dir-1—--forceno longer wipes the whole.hm/dir.init-skills-overwrite-1—write_skillsno longer silently clobbers customized skills.Verification
Worktree
/tmp/hmfix/9, branch rebased onto currentorigin/mainso the PRcontains only the fix commit (3 files:
init.rs,cmd_init.rs,CHANGELOG.md).cargo test -p harmont-cli --lib commands::init→ 4 passed, 0 failed(new unit tests: install-when-absent, preserve-without-force,
force-overwrites, unchanged-no-op).
cargo test -p harmont-cli --test cmd_init init_force_preserves_coresident_files→ 1 passed(asserts
config.toml+deploy.pysurvive while the template is rewritten).cargo test -p harmont-cli --test cmd_init→ 23 passed, 1 failed. Thesingle failure,
init_ts_templates_roundtrip_render, is a pre-existing,environment-level failure (Bun cannot resolve the
pipelineexport in thebundled
@harmont/hm/index.mjs). It reproduces identically withorigin/main'scopy of the touched files and is untouched by this change — not a regression.
cargo clippy -p harmont-cli --lib→ clean, no warnings.Judge verdict
Approved. Blocking issues: none.
Generated by the Harmont release-readiness workflow (automated; needs human review before merge). 🤖