src/core/ module contains wit’s complete Git implementation, written from scratch in TypeScript. This provides full Git compatibility while enabling improvements like better undo, auto-stash, and AI integration.
Overview
Key Files
| File | Purpose |
|---|---|
repository.ts | Main entry point - coordinates all Git operations |
object.ts | Git object types: Blob, Tree, Commit, Tag |
object-store.ts | Persistent storage with compression |
index.ts | Staging area management |
refs.ts | Branch and tag references |
journal.ts | Operation history for undo |
merge.ts | Three-way merge implementation |
diff.ts | Unified diff generation |
remote.ts | Remote repository management |
protocol/ | Git network protocols |
Repository Class
TheRepository class is the main entry point for all Git operations.
Initialization
Configuration
Core Properties
Git Objects
Git stores data as content-addressed objects. wit implements all four object types.Blob (File Content)
Tree (Directory)
Commit
Tag
Object Store
TheObjectStore handles persistence with zlib compression.
Storage Format
Objects are stored in.wit/objects/ using the first two characters of the hash as a directory:
Index (Staging Area)
TheIndex manages the staging area for the next commit.
References
TheRefs class manages branches, tags, and HEAD.
Packed Refs
For performance, refs can be packed into a single file:Journal (Undo History)
TheJournal provides true undo capability by recording all operations.
Merge System
TheMergeManager handles three-way merges with conflict detection.
Three-Way Merge Algorithm
- Find common ancestor (merge base)
- Diff base → ours
- Diff base → theirs
- Apply non-conflicting changes
- Mark conflicts for manual resolution
Diff Engine
Thediff.ts module generates unified diffs with rename detection.
Protocol Layer
Theprotocol/ directory implements Git network protocols.
Smart HTTP
Packfile Handling
Protocol Flow
Remote Management
TheRemoteManager handles remote repository configuration and operations.
Branch State Management
TheBranchStateManager provides auto-stash on branch switch.
Large File Handling
TheLargeFileHandler chunks large files for better handling.
Hooks
TheHookManager supports Git hooks for automation.
Extension Points
Custom Storage Backend
Implement theStorageBackend interface: