diff --git a/crates/gitbutler-core/src/ops/oplog.rs b/crates/gitbutler-core/src/ops/oplog.rs index b82fc07fa..4e528f640 100644 --- a/crates/gitbutler-core/src/ops/oplog.rs +++ b/crates/gitbutler-core/src/ops/oplog.rs @@ -64,7 +64,8 @@ pub trait Oplog { impl Oplog for Project { fn create_snapshot(&self, details: SnapshotDetails) -> Result> { - if self.enable_snapshots.is_none() || self.enable_snapshots == Some(false) { + // Default feature flag to true + if self.enable_snapshots.is_some() && self.enable_snapshots == Some(false) { return Ok(None); } @@ -136,6 +137,12 @@ impl Oplog for Project { &[&oplog_head_commit], )?; + // NOTE: After creating a snapshot we are restoring to the state from the integration commit. + // If the integration commit has not been updated, after snapshot creation we may reset to an incorrect state. + // This can be fixed by invoking virtual_branches::integration::update_gitbutler_integration(&vb_state, project_repository)?; + // before the snapshot creation is initiated in the first place. + // However, there should be no conditions under which the integration commit is stale, and if there is, it should be fixed at the source. + // Reset the workdir to how it was let integration_branch = repo .find_branch("gitbutler/integration", git2::BranchType::Local)? diff --git a/crates/gitbutler-core/tests/virtual_branches/mod.rs b/crates/gitbutler-core/tests/virtual_branches/mod.rs index f73356d6f..accca6185 100644 --- a/crates/gitbutler-core/tests/virtual_branches/mod.rs +++ b/crates/gitbutler-core/tests/virtual_branches/mod.rs @@ -795,6 +795,9 @@ fn merge_vbranch_upstream_clean_rebase() -> Result<()> { let file_path2 = Path::new("test2.txt"); std::fs::write(Path::new(&project.path).join(file_path2), "file2\n")?; + // Update integration commit + virtual_branches::integration::update_gitbutler_integration(&vb_state, project_repository)?; + let remote_branch: git::RemoteRefname = "refs/remotes/origin/master".parse().unwrap(); let mut branch = create_virtual_branch(project_repository, &BranchCreateRequest::default()) .expect("failed to create virtual branch");