Fix data-loss bugs and make adopt write to the config - #2
Merged
Conversation
Four defects that either destroyed files or failed silently:
- defaults.link without a `backup:` key disabled backups entirely (Go
zero value), so `force: true` overwrote real files with no copy. The
LinkDefaults fields are now *bool, absent means backup enabled, and a
failed backup aborts the overwrite instead of proceeding.
- Duplicate detection deleted any symlink in the target's directory
pointing at the same source, so two config entries sharing a source
destroyed each other on every run. It is now opt-in via
`remove_duplicates` and never touches a declared target.
- Runs exited 0 even when every link failed. Commands now end with
failureError(), and SilenceUsage keeps runtime errors readable.
- Template execution errors were swallowed, creating links with
`{{ .Hostnam }}` in their names. Exec errors are now fatal; parse
errors stay tolerated for configs holding a literal `{{`.
adopt now finishes the job: it takes several paths, mirrors each one's
location inside the repo minus leading dots (~/.config/nvim ->
config/nvim), and inserts the link entry into the config through a
yaml.Node round-trip that preserves comments. It edits the raw file
rather than the template-expanded copy, so `{{ }}` variables survive,
and falls back to printing the entry when the config cannot be parsed
or no profile section matches. Adds --to and --no-config.
Also: deterministic processing order (maps were iterated at random),
failing pre_* hooks abort their section, a backup manifest so
`backup list` shows real paths and dates, stale directory backups are
cleared before recopying, a warning when there is no backup to restore,
and --quiet no longer prints the summary.
Tests cover the destructive paths for the first time: createLink,
duplicate handling, adopt, config insertion, unlink --restore and exit
code propagation.
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.
Four defects that either destroyed files or failed silently:
backup:key disabled backups entirely (Go zero value), soforce: trueoverwrote real files with no copy. The LinkDefaults fields are now *bool, absent means backup enabled, and a failed backup aborts the overwrite instead of proceeding.remove_duplicatesand never touches a declared target.{{ .Hostnam }}in their names. Exec errors are now fatal; parse errors stay tolerated for configs holding a literal{{.adopt now finishes the job: it takes several paths, mirrors each one's location inside the repo minus leading dots (~/.config/nvim -> config/nvim), and inserts the link entry into the config through a yaml.Node round-trip that preserves comments. It edits the raw file rather than the template-expanded copy, so
{{ }}variables survive, and falls back to printing the entry when the config cannot be parsed or no profile section matches. Adds --to and --no-config.Also: deterministic processing order (maps were iterated at random), failing pre_* hooks abort their section, a backup manifest so
backup listshows real paths and dates, stale directory backups are cleared before recopying, a warning when there is no backup to restore, and --quiet no longer prints the summary.Tests cover the destructive paths for the first time: createLink, duplicate handling, adopt, config insertion, unlink --restore and exit code propagation.