Skip to content

Enhancement: Migrate sync state on git rename to avoid duplicate Notion pages #77

Description

@virtualguard101

Summary

When a nav-listed file is renamed or moved (git mv), incremental sync treats the new path as a create and leaves the old file_rel entry in .notion_sync_state.json. This produces duplicate Notion pages for the same note.

Current behavior

git_diff correctly records rename status (R100\told\tnew):

  • Old path → md_deleted (logged; Notion page untouched)
  • New path → md_changedsync_one_page creates a new page

State is keyed by file_rel, so the old mapping is never migrated to the new key.

Proposed solution

  1. On rename entries in git diff, migrate state: state.pages[old_rel]state.pages[new_rel] (same Notion id / url).
  2. Optionally reparent if nav parent changed as part of the move.
  3. Update content on the existing Notion page instead of creating a new one.
  4. Log: renamed state obsidian/old.md → obsidian/new.md.

Also handle renames passed via --paths / CI path lists when old path appears in md_deleted and new in md_changed in the same run.

Acceptance criteria

  • git mv of a synced note updates content on the existing Notion page.
  • No second page created for the new file_rel.
  • Old state key removed after migration.
  • Dry-run reports state migration.
  • Works with structure reconciliation when parent section also changes.

Related

  • Nav hierarchy reconciliation (reparent)
  • Opt-in orphan pruning (old path without migration would leave orphan)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions