Git Integration
Magia integrates with git at multiple layers: the session sidebar shows file status, the editor gutter annotates changed lines with blame on hover, and a set of Tauri commands expose worktrees and snapshots for more advanced workflows.
File status
Section titled “File status”The session sidebar polls git status --porcelain every three seconds and annotates each file in the changed-files list with one of: modified, added, deleted, untracked, or renamed. This is powered by the git_status Tauri command, which resolves absolute paths relative to the repository root so every entry can be opened directly.
Branch detection
Section titled “Branch detection”The active branch is read from the current session’s git metadata and shown in the status bar at the bottom of the window (the GitBranchItem). It displays the branch name with a git-branch icon and a tooltip. If the session has no associated git repo, the item is hidden.
Remote URL detection
Section titled “Remote URL detection”The git_remote_url command reads origin’s remote URL and normalizes it to a canonical https:// form. SSH remotes (git@github.com:org/repo.git), HTTPS remotes, and ssh:// URLs are all normalized. This is used internally to associate sessions with their upstream repository.
Git gutter in the editor
Section titled “Git gutter in the editor”The code editor (CodeMirror 6) includes a git gutter extension (gitGutterExtension) that shows colored markers in the left gutter for each changed line:
| Marker | Meaning |
|---|---|
| Green bar | Line was added relative to HEAD |
| Yellow/amber bar | Line was modified |
| Red marker | Line was deleted |
The gutter is updated by dispatching setGitChanges with a list of {line, change_type} entries from the backend diff.
Blame on hover
Section titled “Blame on hover”Hovering over a gutter marker for 400 ms triggers a blame lookup via the git_blame_line command. The result — commit hash, author, date, and commit message — appears in a floating tooltip next to the marker. Results are cached per file and line number to avoid redundant invocations. The cache is cleared when the file content changes.
Line-level diff
Section titled “Line-level diff”The git_diff_lines command (called internally by the gutter) parses unified diff output with hunk headers and produces a flat list of {line, change_type} entries. The hunk regex @@ -\d+(,\d+)? \+\d+(,\d+)? @@ is used to locate and reconstruct added, modified, and deleted lines.
Snapshots
Section titled “Snapshots”A snapshot captures the full working tree state (staged + unstaged + untracked changes) and stores it as a hidden git ref at refs/magia/snapshots/{uuid}.
git_create_snapshot(path) → "refs/magia/snapshots/<uuid>"Snapshots use a temporary index file so the real index is never modified. The process:
- Create a temp index and populate it with
git add -A. - Write a tree object (
git write-tree). - Commit the tree with a
magia-snapshot: <timestamp>message. - Store the commit under
refs/magia/snapshots/<uuid>.
Snapshots are the source of truth for worktree creation.
Worktrees
Section titled “Worktrees”Magia can create, list, and remove git worktrees that are isolated to the .worktrees/ directory inside the repository.
Creating a worktree
Section titled “Creating a worktree”git_create_worktree(path, name, snapshot_ref) → "/path/to/.worktrees/magia-<name>"The worktree is created detached at the commit pointed to by snapshot_ref. The resulting directory is .worktrees/magia-{name}/ relative to the repo root.
Listing worktrees
Section titled “Listing worktrees”git_list_worktrees(path) → WorktreeInfo[]Returns each worktree’s absolute path, HEAD ref (branch name preferred over bare hash), and whether it is the main worktree.
Removing a worktree
Section titled “Removing a worktree”git_remove_worktree(path, name)Runs git worktree remove --force on .worktrees/magia-{name}/ and then git worktree prune to clean up stale metadata. Errors about missing directories are silently ignored so the operation is idempotent.
Worktree root detection
Section titled “Worktree root detection”git_worktree_root returns the root of the git worktree for any given path, which is used to determine per-worktree app data isolation during development.