/
raiden
/
obsidian-git-encrypt
Обзор
Документация
Войти
/
raiden
/
obsidian-git-encrypt
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/sourceControl/changeStatus.ts
51 строка
2 KB
Robert Kuzhin
fix: clear staging after manual revert
10 авг 2026, 07:35
10 авг 2026, 07:35
1de1382
Код
Авторство
О чём код?
import type { Manifest, ManifestEntry } from "../mirror/manifestTypes.js"; import type { SourceFileChange } from "./sourceControlTypes.js"; export function planSourceChanges( base: Manifest, target: Readonly<Record<string, ManifestEntry>>, ): SourceFileChange[] { const changes: SourceFileChange[] = []; const fileIds = new Set([...Object.keys(base.files), ...Object.keys(target)]); for (const fileId of fileIds) { const change = compareEntries(base.files[fileId], target[fileId]); if (change !== undefined) changes.push(change); } return changes.sort((left, right) => left.path.localeCompare(right.path, "en-US")); } export function compareEntries( base: ManifestEntry | undefined, target: ManifestEntry | undefined, ): SourceFileChange | undefined { const baseActive = base !== undefined && base.deleted !== true; const targetActive = target !== undefined && target.deleted !== true; if (!baseActive && !targetActive) return undefined; if (!baseActive && targetActive) return fromEntry(target, "added"); if (baseActive && !targetActive) return fromEntry(target ?? { ...base, deleted: true }, "deleted"); if (entriesEqual(base!, target!)) return undefined; if (base!.path !== target!.path) { return { ...fromEntry(target!, "renamed"), oldPath: base!.path }; } return fromEntry(target!, "modified"); } export function entriesEqual(left: ManifestEntry, right: ManifestEntry): boolean { return ( left.fileId === right.fileId && left.path === right.path && left.plaintextHash === right.plaintextHash && left.size === right.size && left.deleted === right.deleted ); } function fromEntry(entry: ManifestEntry, kind: SourceFileChange["kind"]): SourceFileChange { return { fileId: entry.fileId, kind, path: entry.path, size: entry.size, modifiedAt: entry.modifiedAt, }; }