Skip to content

Flag whether each duplicate's content matches the note being kept - #124

Merged
jonhadfield merged 1 commit into
mainfrom
feat/duplicates-compare-content
Sep 22, 2026
Merged

jonhadfield merged 1 commit into
mainfrom
feat/duplicates-compare-content

Conversation

@jonhadfield

Copy link
Copy Markdown
Owner

Follow-up to #120 and #121.

Why

The listing said which notes would be deleted, but not whether deleting them would lose anything. Notes are already decrypted locally by the sync the command performs, so comparing their content costs nothing: no extra API calls.

What changed

Every note about to be deleted is now labelled by comparing its title and text with the note being kept:

2 notes would be deleted, in 1 sets of duplicates:
  keep    2026-09-21 14:30  9f2a...  Shopping      
  delete  2026-09-02 09:12  1b77...  Shopping      identical
  delete  2026-09-05 11:48  3c01...  Shopping      differs

--identical-only deletes just the exact copies and reports the rest, so a note edited since it was duplicated is left for you to look at:

sn delete duplicates --identical-only

Default behaviour is unchanged: without the flag, every note in the set is still deleted apart from the newest.

A note whose text matches but whose title doesn't counts as differs, since something was changed after the copy was made.

Tests

Five new cases: identical content, differing text, differing title, the --identical-only filter including a set where nothing is identical and the whole set is dropped, and the filter on an empty input. Sixteen tests in total for this command.

make lint reports 0 issues and make test passes.

Still not tested against a real account — no credentials here, so only the selection and comparison logic is covered.

🤖 Generated with Claude Code

The listing said which notes would be deleted but not whether anything
would be lost. The notes are already decrypted locally by the sync, so
comparing them costs nothing.

Each note to be deleted is now labelled identical or differs, comparing
its title and text with the note being kept. --identical-only restricts
deletion to exact copies and reports the rest.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 22, 2026 20:15
@codacy-production

codacy-production Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 22 complexity · 6 duplication

Metric Results
Complexity 22
Duplication 6

View in Codacy

🟢 Coverage 38.18% diff coverage · +0.14% coverage variation

Metric Results
Coverage variation ✅ +0.14% coverage variation (-1.00%)
Diff coverage ✅ 38.18% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (76ab438) 9037 973 10.77%
Head commit (c146727) 9082 (+45) 991 (+18) 10.91% (+0.14%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#124) 55 21 38.18%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@jonhadfield
jonhadfield merged commit d72e5a5 into main Sep 22, 2026
11 checks passed
@jonhadfield
jonhadfield deleted the feat/duplicates-compare-content branch September 22, 2026 20:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The command can print a misleading “no duplicate notes found” message after reporting kept-differing/kept-no-original duplicates, which should be clarified for correct UX.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Low severity

Open (1)
What changed in this PR

This PR enhances sn delete duplicates to show whether each duplicate note’s content matches the note being kept, and adds an --identical-only option to delete only exact copies (same title + text) while reporting notes that differ.

Changes:

  • Add content comparison (Identical) to duplicate summaries and display identical/differs in the duplicates listing.
  • Introduce --identical-only to delete only exact copies and keep/report diverged duplicates.
  • Extend tests to cover identical/differing content and the new filter behavior.
File Description
README.md Documents the new “identical vs differs” listing and --identical-only usage.
internal/​sncli/​duplicates.go Computes Identical per deletion candidate and implements KeepOnlyIdentical + config/output plumbing.
internal/​sncli/​duplicates_test.go Adds coverage for identical/differing content and KeepOnlyIdentical filtering.
cmd/​sncli/​duplicates.go Wires CLI flag into the command, prints content labels, and reports notes kept due to differing content.
cmd/​sncli/​delete.go Adds shell completion + CLI flag definition for --identical-only.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cmd/sncli/duplicates.go
Comment on lines 44 to 48
writeDuplicatesKept(c, found.KeptNoOriginal)
writeDuplicatesDiffering(c, found.KeptDiffering)

toDelete := found.Deleted()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants