Skip to content

Commit c678a00

Browse files
committed
Safe checkout for the oplog
That way it shouldn't lose untracked files anymore
1 parent 25e8829 commit c678a00

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/gitbutler-oplog/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ gitbutler-fs.workspace = true
2626
gitbutler-reference.workspace = true
2727
gitbutler-stack.workspace = true
2828
but-core.workspace = true
29+
but-workspace.workspace = true
2930

3031
[[test]]
3132
name = "oplog"

crates/gitbutler-oplog/src/oplog.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -619,11 +619,19 @@ fn restore_snapshot(
619619
repo.ignore_large_files_in_diffs(AUTO_TRACK_LIMIT_BYTES)?;
620620

621621
// Define the checkout builder
622-
let mut checkout_builder = git2::build::CheckoutBuilder::new();
623-
checkout_builder.remove_untracked(true);
624-
checkout_builder.force();
625-
// Checkout the tree
626-
repo.checkout_tree(workdir_tree.as_object(), Some(&mut checkout_builder))?;
622+
if ctx.app_settings().feature_flags.cv3 {
623+
but_workspace::branch::safe_checkout_from_head(
624+
workdir_tree.id().to_gix(),
625+
&gix_repo,
626+
but_workspace::branch::checkout::Options::default(),
627+
)?;
628+
} else {
629+
let mut checkout_builder = git2::build::CheckoutBuilder::new();
630+
checkout_builder.remove_untracked(true);
631+
checkout_builder.force();
632+
// Checkout the tree
633+
repo.checkout_tree(workdir_tree.as_object(), Some(&mut checkout_builder))?;
634+
}
627635

628636
// Update virtual_branches.toml with the state from the snapshot
629637
fs::write(

crates/gitbutler-workspace/src/branch_trees.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ pub fn update_uncommited_changes_with_tree(
6565
ctx: &CommandContext,
6666
old: WorkspaceState,
6767
new: WorkspaceState,
68-
old_uncommited_changes: Option<git2::Oid>,
68+
old_uncommitted_changes: Option<git2::Oid>,
6969
always_checkout: Option<bool>,
7070
_perm: &mut WorktreeWritePermission,
7171
) -> Result<()> {
7272
let repo = ctx.repo();
73-
if let Some(worktree_id) = old_uncommited_changes {
73+
if let Some(worktree_id) = old_uncommitted_changes {
7474
let mut new_uncommited_changes = move_tree_between_workspaces(repo, worktree_id, old, new)?;
7575

7676
// If the new tree and old tree are the same, then we don't need to do anything
@@ -91,9 +91,11 @@ pub fn update_uncommited_changes_with_tree(
9191
),
9292
)?;
9393
} else {
94+
let old_tree_id = merge_workspace(repo, old)?.to_gix();
9495
let new_tree_id = merge_workspace(repo, new)?.to_gix();
9596
let gix_repo = ctx.gix_repo_for_merging()?;
96-
but_workspace::branch::safe_checkout_from_head(
97+
but_workspace::branch::safe_checkout(
98+
old_tree_id,
9799
new_tree_id,
98100
&gix_repo,
99101
but_workspace::branch::checkout::Options::default(),

0 commit comments

Comments
 (0)