Skip to content

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.

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.

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.

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.

The code editor (CodeMirror 6) includes a git gutter extension (gitGutterExtension) that shows colored markers in the left gutter for each changed line:

MarkerMeaning
Green barLine was added relative to HEAD
Yellow/amber barLine was modified
Red markerLine was deleted

The gutter is updated by dispatching setGitChanges with a list of {line, change_type} entries from the backend diff.

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.

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.

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:

  1. Create a temp index and populate it with git add -A.
  2. Write a tree object (git write-tree).
  3. Commit the tree with a magia-snapshot: <timestamp> message.
  4. Store the commit under refs/magia/snapshots/<uuid>.

Snapshots are the source of truth for worktree creation.

Magia can create, list, and remove git worktrees that are isolated to the .worktrees/ directory inside the repository.

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.

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.

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.

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.