Fix: Detect files modified directly on GitHub

Fixes #45 - Plugin now detects when files are edited via GitHub web UI.

The manifest only updates when syncing through this plugin. We now compare
actual tree SHAs with manifest SHAs to catch external modifications.

Changes:
- Compare remote file SHAs from git tree with manifest SHAs
- Update manifest when external changes detected
- Handle new files added externally
This commit is contained in:
TheOutdoorProgrammer 2026-01-30 12:05:55 -05:00
parent 2ebd201da9
commit 07dca55fe1
No known key found for this signature in database
GPG key ID: 8CFCD72C22B7A345

View file

@ -440,6 +440,40 @@ export default class SyncManager {
decodeBase64String(blob.content),
);
// Detect files modified directly on GitHub (via web UI or other means).
// The manifest only updates when syncing through this plugin, so we compare
// actual tree SHAs with manifest SHAs to catch external modifications.
await this.logger.info("Checking for remote changes outside manifest");
Object.keys(files).forEach((filePath: string) => {
if (filePath === `${this.vault.configDir}/${MANIFEST_FILE_NAME}`) {
return;
}
const actualRemoteSHA = files[filePath].sha;
const manifestEntry = remoteMetadata.files[filePath];
if (manifestEntry) {
if (manifestEntry.sha !== actualRemoteSHA) {
this.logger.info("Detected external change", {
filePath,
manifestSHA: manifestEntry.sha,
actualSHA: actualRemoteSHA,
});
manifestEntry.sha = actualRemoteSHA;
manifestEntry.lastModified = Date.now();
}
} else {
this.logger.info("Detected new file added externally", { filePath });
remoteMetadata.files[filePath] = {
path: filePath,
sha: actualRemoteSHA,
dirty: false,
justDownloaded: false,
lastModified: Date.now(),
};
}
});
const conflicts = await this.findConflicts(remoteMetadata.files);
// We treat every resolved conflict as an upload SyncAction, mainly cause