diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock index a55b2aec2a..e01ab1430f 100644 --- a/codex-rs/Cargo.lock +++ b/codex-rs/Cargo.lock @@ -1390,7 +1390,6 @@ dependencies = [ "codex-common", "codex-core", "codex-file-search", - "codex-git-tooling", "codex-login", "codex-ollama", "codex-protocol", @@ -3088,7 +3087,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f37dccff2791ab604f9babef0ba14fbe0be30bd368dc541e2b08d07c8aa908f3" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.4", "inotify-sys", "libc", ] @@ -3727,7 +3726,7 @@ version = "8.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d3d07927151ff8575b7087f245456e549fea62edf0ec4e565a5ee50c8402bc3" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.4", "fsevent-sys", "inotify", "kqueue", diff --git a/codex-rs/git-tooling/src/ghost_commits.rs b/codex-rs/git-tooling/src/ghost_commits.rs index ec31c377d3..48bbd0f044 100644 --- a/codex-rs/git-tooling/src/ghost_commits.rs +++ b/codex-rs/git-tooling/src/ghost_commits.rs @@ -177,6 +177,8 @@ pub fn restore_to_commit(repo_path: &Path, commit_id: &str) -> Result<(), GitToo restore_to_commit_inner(repo_root.as_path(), repo_prefix.as_deref(), commit_id) } +/// Restores the working tree and index to the given commit using `git restore`. +/// The repository root and optional repository-relative prefix limit the restore scope. fn restore_to_commit_inner( repo_root: &Path, repo_prefix: Option<&Path>, @@ -206,6 +208,7 @@ struct UntrackedSnapshot { dirs: Vec, } +/// Captures the repository's untracked files and directories scoped to an optional subdirectory. fn capture_existing_untracked( repo_root: &Path, repo_prefix: Option<&Path>, @@ -258,6 +261,7 @@ fn capture_existing_untracked( Ok(snapshot) } +/// Removes untracked files and directories that were not present when the snapshot was captured. fn remove_new_untracked( repo_root: &Path, preserved_files: &[PathBuf], @@ -288,6 +292,7 @@ fn remove_new_untracked( Ok(()) } +/// Determines whether an untracked path should be kept because it existed in the snapshot. fn should_preserve( path: &Path, preserved_files: &HashSet, @@ -302,6 +307,7 @@ fn should_preserve( .any(|dir| path.starts_with(dir.as_path())) } +/// Deletes the file or directory at the provided path, ignoring if it is already absent. fn remove_path(path: &Path) -> Result<(), GitToolingError> { match fs::symlink_metadata(path) { Ok(metadata) => { diff --git a/codex-rs/git-tooling/src/lib.rs b/codex-rs/git-tooling/src/lib.rs index ec89895671..650953ed08 100644 --- a/codex-rs/git-tooling/src/lib.rs +++ b/codex-rs/git-tooling/src/lib.rs @@ -13,11 +13,13 @@ pub use ghost_commits::restore_ghost_commit; pub use ghost_commits::restore_to_commit; pub use platform::create_symlink; +type CommitID = String; + /// Details of a ghost commit created from a repository state. #[derive(Debug, Clone, PartialEq, Eq)] pub struct GhostCommit { - id: String, - parent: Option, + id: CommitID, + parent: Option, preexisting_untracked_files: Vec, preexisting_untracked_dirs: Vec, } @@ -25,8 +27,8 @@ pub struct GhostCommit { impl GhostCommit { /// Create a new ghost commit wrapper from a raw commit ID and optional parent. pub fn new( - id: String, - parent: Option, + id: CommitID, + parent: Option, preexisting_untracked_files: Vec, preexisting_untracked_dirs: Vec, ) -> Self {