Git integration — GitCore operations #8

Closed
opened 2026-04-16 11:29:33 +00:00 by claude-desktop · 0 comments
Collaborator

User story

As a backend developer, I want a GitCore module that wraps git2-rs to provide repository status, diff, commit, branch listing, and log operations, so that the checkpoint system and the frontend git panel have a reliable git abstraction.

Acceptance criteria

GitCore (git/core.rs)

  • open_repo(path: &str) -> Result<git2::Repository, GitError> — discovers and opens a git repo
  • status(repo) -> Result<GitStatus, GitError> — lists staged, unstaged, untracked files and current branch using git2::StatusOptions
  • diff(repo, from: Option<&str>, to: Option<&str>) -> Result<Vec<FileDiff>, GitError> — computes diff between refs (or working tree) and returns structured FileDiff with hunks and lines
  • commit(repo, message, signature) -> Result<String, GitError> — stages all changes and commits, returns the commit hash
  • branches(repo) -> Result<Vec<BranchInfo>, GitError> — lists all branches with current indicator and upstream
  • log(repo, limit: usize) -> Result<Vec<CommitInfo>, GitError> — returns recent commits
  • create_branch(repo, name: &str) -> Result<(), GitError> — creates a new branch from HEAD
  • checkout_branch(repo, name: &str) -> Result<(), GitError> — switches to an existing branch

GitManager (git/manager.rs)

  • Wraps GitCore and handles GitCommand variants from IPC
  • handle_command(&self, cmd: GitCommand) -> Result<AppEvent, GitError> — dispatches to GitCore and returns appropriate AppEvent::GitStatus

Error types

  • GitError enum wrapping git2::Error and custom variants (RepoNotFound, BranchAlreadyExists, etc.)

Tests

  • Test: open_repo on a temp git repo succeeds
  • Test: status on a clean repo returns empty changes
  • Test: commit creates a new commit and returns valid hash
  • Test: diff returns correct hunks for a modified file
  • Test: branches lists the default branch
  • All tests use tempdir with git2::Repository::init()

Out of scope

  • CheckpointReactor (separate story)
  • Push to remote (v1 deferred)

References

  • Spec §8.1 (GitCore)
  • Spec §8.3 (Git contract types — from contracts crate)

Dependencies

  • Blocked by: none (GitCore + shapes are self-contained; GitManager.handle_command uses GitCommand from #6 but can be stubbed behind a feature gate and wired once #6 lands)
  • Blocks: #9, #16
  • Branch off: main
  • Full graph: #21
## User story As a **backend developer**, I want a `GitCore` module that wraps `git2-rs` to provide repository status, diff, commit, branch listing, and log operations, so that the checkpoint system and the frontend git panel have a reliable git abstraction. ## Acceptance criteria ### GitCore (`git/core.rs`) - [ ] `open_repo(path: &str) -> Result<git2::Repository, GitError>` — discovers and opens a git repo - [ ] `status(repo) -> Result<GitStatus, GitError>` — lists staged, unstaged, untracked files and current branch using `git2::StatusOptions` - [ ] `diff(repo, from: Option<&str>, to: Option<&str>) -> Result<Vec<FileDiff>, GitError>` — computes diff between refs (or working tree) and returns structured `FileDiff` with hunks and lines - [ ] `commit(repo, message, signature) -> Result<String, GitError>` — stages all changes and commits, returns the commit hash - [ ] `branches(repo) -> Result<Vec<BranchInfo>, GitError>` — lists all branches with current indicator and upstream - [ ] `log(repo, limit: usize) -> Result<Vec<CommitInfo>, GitError>` — returns recent commits - [ ] `create_branch(repo, name: &str) -> Result<(), GitError>` — creates a new branch from HEAD - [ ] `checkout_branch(repo, name: &str) -> Result<(), GitError>` — switches to an existing branch ### GitManager (`git/manager.rs`) - [ ] Wraps `GitCore` and handles `GitCommand` variants from IPC - [ ] `handle_command(&self, cmd: GitCommand) -> Result<AppEvent, GitError>` — dispatches to GitCore and returns appropriate `AppEvent::GitStatus` ### Error types - [ ] `GitError` enum wrapping `git2::Error` and custom variants (RepoNotFound, BranchAlreadyExists, etc.) ### Tests - [ ] Test: open_repo on a temp git repo succeeds - [ ] Test: status on a clean repo returns empty changes - [ ] Test: commit creates a new commit and returns valid hash - [ ] Test: diff returns correct hunks for a modified file - [ ] Test: branches lists the default branch - [ ] All tests use `tempdir` with `git2::Repository::init()` ## Out of scope - CheckpointReactor (separate story) - Push to remote (v1 deferred) ## References - Spec §8.1 (GitCore) - Spec §8.3 (Git contract types — from contracts crate) ## Dependencies - **Blocked by:** none (GitCore + shapes are self-contained; `GitManager.handle_command` uses `GitCommand` from #6 but can be stubbed behind a feature gate and wired once #6 lands) - **Blocks:** #9, #16 - **Branch off:** `main` - **Full graph:** #21
claude-desktop added this to the v0.1.0 milestone 2026-04-16 11:29:33 +00:00
Sign in to join this conversation.
No description provided.