Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/rgitui_diff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ rgitui_ui.workspace = true
rgitui_git.workspace = true
rgitui_settings.workspace = true
anyhow.workspace = true
# Only for parsing a hex OID out of a `DiffSource` when building the tree pair
# an apply/revert patch comes from.
git2.workspace = true
log.workspace = true
syntect = { version = "5.3", default-features = false, features = ["default-fancy"] }

Expand Down
1,282 changes: 1,086 additions & 196 deletions crates/rgitui_diff/src/lib.rs

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions crates/rgitui_git/src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod refresh;
mod search;
mod submodule;
mod watcher;
mod worktree_patch;

use anyhow::{Context as _, Result};
use git2::{Repository, StatusOptions};
Expand Down Expand Up @@ -79,6 +80,11 @@ pub use submodule::{
compute_submodules, submodule_init, submodule_init_all, submodule_update, submodule_update_all,
SubmoduleInfo,
};
pub use worktree_patch::{
apply_worktree_patch, restore_worktree_files, snapshots_fit_undo_stack,
WorktreeFilePermissions, WorktreeFileSnapshot, WorktreeFileState, WorktreePatchDirection,
WorktreePatchOutcome, WorktreePatchScope, WorktreePatchSource, MAX_UNDO_SNAPSHOT_BYTES,
};

fn parse_remote_tracking_ref(name: &str) -> Option<(String, String)> {
let trimmed = name.strip_prefix("refs/remotes/").unwrap_or(name);
Expand Down Expand Up @@ -256,6 +262,18 @@ pub enum GitProjectEvent {
/// Emitted after ahead/behind for all branches has been recomputed in the background.
AheadBehindRefreshed,
OperationUpdated(GitOperationUpdate),
/// An apply/revert rewrote working-tree files on disk. Carries what those
/// files held beforehand, which is the only record of it: the previous
/// contents are not recoverable from git state.
WorktreePatchApplied {
/// Undo label, e.g. "Applied hunk 2 of src/main.rs from a1b2c3d".
label: String,
snapshots: Vec<worktree_patch::WorktreeFileSnapshot>,
/// Repository entity that started the asynchronous mutation.
repo_path: PathBuf,
/// Effective worktree captured when the operation started.
worktree_path: PathBuf,
},
}

/// The core Git project state holder.
Expand Down
Loading