core-agent-ide/codex-rs/utils/git
jif-oai 0d9801d448
feat: ghost snapshot v2 (#8055)
This PR updates ghost snapshotting to avoid capturing oversized
untracked artifacts while keeping undo safe. Snapshot creation now
builds a temporary index from `git status --porcelain=2 -z`, writes a
tree and detached commit without touching refs, and records any ignored
large files/dirs in the snapshot report. Undo uses that metadata to
preserve large local artifacts while still cleaning up new transient
files.
2025-12-15 11:14:36 +01:00
..
src feat: ghost snapshot v2 (#8055) 2025-12-15 11:14:36 +01:00
Cargo.toml chore: add cargo-deny configuration (#7119) 2025-11-24 12:22:18 -08:00
README.md chore: merge git crates (#5909) 2025-10-29 12:11:44 +00:00

codex-git

Helpers for interacting with git, including patch application and worktree snapshot utilities.

use std::path::Path;

use codex_git::{
    apply_git_patch, create_ghost_commit, restore_ghost_commit, ApplyGitRequest,
    CreateGhostCommitOptions,
};

let repo = Path::new("/path/to/repo");

// Apply a patch (omitted here) to the repository.
let request = ApplyGitRequest {
    cwd: repo.to_path_buf(),
    diff: String::from("...diff contents..."),
    revert: false,
    preflight: false,
};
let result = apply_git_patch(&request)?;

// Capture the current working tree as an unreferenced commit.
let ghost = create_ghost_commit(&CreateGhostCommitOptions::new(repo))?;

// Later, undo back to that state.
restore_ghost_commit(repo, &ghost)?;

Pass a custom message with .message("…") or force-include ignored files with .force_include(["ignored.log".into()]).