fix a bug where deleting a vbranch fails to update state

This commit is contained in:
Kiril Videlov 2024-09-10 10:55:36 +02:00
parent dfa38908f9
commit 310d4cf73a
No known key found for this signature in database
GPG Key ID: A4C733025427C471
3 changed files with 24 additions and 6 deletions

View File

@ -40,11 +40,6 @@ impl BranchManager<'_> {
self.delete_branch(branch_id, perm, &target_commit)?;
// If we were conflicting, it means that it was the only branch applied. Since we've now unapplied it we can clear all conflicts
if conflicts::is_conflicting(self.ctx, None)? {
conflicts::clear(self.ctx)?;
}
vb_state.update_ordering()?;
// Ensure we still have a default target
@ -137,6 +132,13 @@ impl BranchManager<'_> {
vbranch::ensure_selected_for_changes(&vb_state)
.context("failed to ensure selected for changes")?;
// If we were conflicting, it means that it was the only branch applied. Since we've now unapplied it we can clear all conflicts
if conflicts::is_conflicting(self.ctx, None)? {
conflicts::clear(self.ctx)?;
}
crate::integration::update_workspace_commit(&vb_state, self.ctx)
.context("failed to update gitbutler workspace")?;
Ok(())
}
}

View File

@ -20,6 +20,14 @@ fn should_unapply_diff() {
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
let c = gitbutler_branch_actions::create_commit(
project,
branches.first().unwrap().id,
"asdf",
None,
false,
);
assert!(c.is_ok());
gitbutler_branch_actions::delete_virtual_branch(project, branches[0].id).unwrap();
@ -27,6 +35,14 @@ fn should_unapply_diff() {
assert_eq!(branches.len(), 0);
assert!(!repository.path().join("file.txt").exists());
let mut opts = git2::StatusOptions::new();
opts.include_untracked(true);
let statuses = repository
.local_repository
.statuses(Some(&mut opts))
.unwrap();
assert!(statuses.is_empty());
let refnames = repository
.references()
.into_iter()

View File

@ -10,7 +10,7 @@ pub fn temp_dir() -> TempDir {
}
pub struct TestProject {
local_repository: git2::Repository,
pub local_repository: git2::Repository,
local_tmp: Option<TempDir>,
remote_repository: git2::Repository,
remote_tmp: Option<TempDir>,