Mirror
A mirror is upstream’s copy of a page in the vault: searchable, with backlinks and graph, opened in place. Not for editing: updates overwrite it.
Provenance
mirror_remote, mirror_repo, mirror_path, mirror_branch, mirror_commit, mirror_blob,
mirror_date: as their fork_* namesakes (fork.md), for the version held. No
mirror_seen: an update overwrites.
A note is a mirror when mirror_path and mirror_blob are valid, it has a valid
mirror_remote or mirror_repo, and it isn’t a fork (valid fork_* keys win). Writing a
mirror removes every fork_* key. Keys decide, not the folder: a mirror moved by hand is still
one.
Where
<communityFolder>/<folder or remote name>/<upstream path> (mirrorFolderOf(),
mirrorPath()): wiki/cs/git.md from txt → community/txt/wiki/cs/git.md. Never asked.
Mirror
From the check view (Mirror on a file, or Mirror selected, which clears ticks) at the
head the check saw, or Mirror a file from a source (pick source, skipped if one; fetch head;
pick file). Markdown only; its attachments come with it (Attachments). Per file
(planMirrors()):
- Already mirrored anywhere: left alone, but gets any attachments it lacks, from the version it holds. So mirroring again brings a mirror’s attachments.
- Its place taken by something else: skipped, reported.
- Otherwise: blob fetched, checked (copy-safety.md), note created,
mirror_*keys added. Upstream front matter that isn’t valid YAML is refused before writing.
One notice (sticky on failure); the note isn’t opened.
Links
Left as upstream wrote them; Obsidian resolves them. The folder has upstream’s layout, so ./ and
../ links go to the mirror, or dangle until it is mirrored; one from the repo root (/b.md)
doesn’t find it. Any other may land on the user’s note, or another source’s page, of that name:
the wiki way, unguarded. A link by path to a page forked away dangles.
The link commands work on a mirror (links.md). Links rewritten showing the same words aren’t an edit (fork-update.md), so an update overwrites the mirror unasked, in upstream’s form again.
Attachments
The files that aren’t Markdown a mirror links or embeds (images, PDFs, audio): copied into the mirror folder at their upstream paths, so the note’s links find them unchanged. Copied when the note is mirrored, mirrored again, or updated; nothing else checks them, so one changed upstream under an unchanged note waits for the note’s next update.
Which (linkRefs(), resolveRef()): wikilinks, Markdown links and HTML src, front matter
too, not in code; not web links. Each is looked up in the tree at the head being mirrored, as
Obsidian would find it: by its path from the note or from the root, else by the end of its path,
the note’s folder first, then the shortest. Not found upstream: left.
No front matter, so no keys. An attachment’s content is its provenance: its git blob SHA
(gitBlobSha()). One already there (attachmentState()):
- the same as upstream’s: left;
- a blob the clone holds (
RemoteHost.has), so once upstream’s: an earlier version, overwritten; - anything else (edited, or never upstream’s): left, and named.
Forking a mirror copies the attachments beside it to beside the fork (fork.md).
A notice line says how many were copied and updated; one left or failed makes it sticky.
Update
Update on a file, or Update mirrors (n), overwrites with upstream at the head the check
saw and rewrites mirror_*, then copies its attachments. The new versions are checked first
(copy-safety.md). Compare on the check view’s row, or the Preview view’s Compare mirror, shows a version beside
the mirror first (compare.md). Its mirrors are looked up again, so one moved by hand
since the check is updated where it is.
A mirror isn’t overwritten unasked (mirrorState()) when it is edited
(fork-update.md), or when that can’t be told (its version can’t be read).
Update asks, saying which, and suggests forking; Update mirrors skips and names it. A note
that changes while it is being updated is left and reported. A file whose mirrors are all gone
leaves the list.
Stop
Stop on a mirrored file, Remove on one gone upstream, or Stop mirroring this note:
after confirming, the mirror is trashed, with any edits made to it: the question says so, and
suggests forking. Its attachments in the mirror folder go too, but those another note links to
(unusedAttachments(), by Obsidian’s resolved links); the question names them. A page mirrored twice stops with both notes, which it names. A gone mirror stays
listed until removed or forked.
Code
Pure: src/mirror/mirror.ts, update.ts, src/copy/copy.ts, edited.ts, attachments.ts,
src/sources/fork-meta.ts. Vault: src/mirror/run.ts, update-run.ts, attachments-run.ts,
src/copy/run.ts, src/sources/forks.ts.