How mateusmolina/obsidian-git-file-explorer works
Project type and purpose
• This is an Obsidian desktop-only plugin written in TypeScript that augments Obsidian’s file explorer with Git capabilities (status badges, commit/sync widgets, diff integration, repo initialization).
• Key clues: a manifest.json (Obsidian plugin), main.ts, src/… handlers & widgets, README describing UI widgets and Git operations.
File structure
• Top-level: build configs (esbuild.config.mjs, tsconfig.json), plugin manifest, scripts (copy-to-test-vault.mjs, version-bump.mjs), main.ts.
• src/: core plugin logic
• capabilityProvider.ts – registers plugin features with Obsidian
• commandRegister.ts – CLI commands (commit, sync, diff, init repo)
• contextMenuInstaller.ts – adds right-click diff/init options
• fileExplorerHandler.ts – injects badges and widgets into UI
• git/… – GitRepository abstraction + terminalExecutor to run Git CLI
• handlers: gitDiffHandler.ts, initNewRepoHandler.ts
• settings.ts – user-configurable options
• widgets/… – UI widgets (ChangesGitWidget, SyncGitWidget, GitWidgetFactory) and utilities (eventBus, debouncer, autoSyncManager, widgetManager)
• Styles: styles.css for highlighting changed files.
Read README for additional insights
• Describes features: Git Changes Widget, Git Sync Widget (with auto-sync), Git Diff integration, file explorer enhancements, repo management.
• Mentions user interactions (click to commit or sync, context menu for diff/init), settings, and Git CLI dependency.
a. Obsidian Host
– The container application that loads the plugin via manifest.json.
b. Plugin Core
– main.ts → initializes CapabilityProvider → wires up CommandRegister and ContextMenuInstaller → loads Settings.
c. File Explorer Integration
– FileExplorerHandler injects UI elements into Obsidian’s file explorer.
d. Widgets Layer
– WidgetFactory produces widget instances (GitWidget, ChangesGitWidget, SyncGitWidget, NavColorUpdater).
– WidgetManager registers and updates widgets.
– EventBus propagates UI events (clicks) and internal triggers (auto-sync).
e. Business Logic / Handlers
– CommandRegister triggers Git operations.
– GitDiffHandler & InitNewRepoHandler handle diff and repo init.
f. Data Access / Git Abstraction
– GitRepository exposes status, commit, pull, push.
– TerminalExecutor runs Git CLI commands.
– File system as underlying data store (vault, repos).
g. Settings
– Settings module reads/writes user preferences (commit prompts, styling, auto-sync frequency).
h. External Services
– Git CLI (shell) as an external dependency.
Relationships and data flows
• On startup: Obsidian → loads plugin (main.ts) → CapabilityProvider registers event hooks.
• FileExplorerHandler listens to “file‐explorer‐render” events → uses WidgetFactory → widgets rendered in UI.
• Widgets subscribe to EventBus → on click → fire “commit” or “sync” commands → CommandRegister invokes GitRepository→ TerminalExecutor → Git CLI.
• GitRepository returns results → EventBus broadcasts updates → WidgetManager triggers widget re‐render.
• AutoSyncManager schedules periodic syncs via EventBus and Debouncer.
• Settings influence widget behavior and styling.
Architectural patterns
• Event-driven: EventBus decouples UI from logic.
• Factory: WidgetFactory creates widget instances.
• Manager: WidgetManager oversees widget lifecycle.
• Abstraction: GitRepository wraps TerminalExecutor to isolate Git CLI.