Fix (some) wrong files displaying in edit mode

This commit is contained in:
Caleb Owens 2024-09-17 14:31:58 +02:00
parent c991ec48a8
commit 2a3f0e8a04
3 changed files with 6 additions and 22 deletions

View File

@ -1,4 +1,3 @@
use crate::integration::get_workspace_head;
use crate::{RemoteBranchFile, VirtualBranchesExt};
use anyhow::{bail, Context, Result};
use bstr::{BStr, ByteSlice};
@ -10,7 +9,7 @@ use gitbutler_command_context::CommandContext;
use gitbutler_diff::DiffByPathMap;
use gitbutler_project::access::WorktreeReadPermission;
use gitbutler_reference::normalize_branch_name;
use gitbutler_repo::GixRepositoryExt;
use gitbutler_repo::{GixRepositoryExt, RepositoryExt as _};
use gitbutler_serde::BStringForFrontend;
use gix::object::tree::diff::Action;
use gix::prelude::ObjectIdExt;
@ -31,7 +30,7 @@ pub(crate) fn get_uncommited_files_raw(
ctx: &CommandContext,
_permission: &WorktreeReadPermission,
) -> Result<DiffByPathMap> {
gitbutler_diff::workdir(ctx.repository(), get_workspace_head(ctx)?)
gitbutler_diff::workdir(ctx.repository(), ctx.repository().head_commit()?.id())
.context("Failed to list uncommited files")
}

View File

@ -613,6 +613,8 @@ mod test {
let tempdir = tempdir().unwrap();
let repository = git2::Repository::init(tempdir.path()).unwrap();
let initial_commit = commit_file(&repository, None, &[("foo.txt", "bar")]);
// Create refs/heads/master
repository.branch("master", &initial_commit, false).unwrap();
let old_target = commit_file(&repository, Some(&initial_commit), &[("foo.txt", "baz")]);
let branch_head = commit_file(&repository, Some(&old_target), &[("foo.txt", "fux")]);
let new_target = commit_file(&repository, Some(&old_target), &[("foo.txt", "qux")]);

View File

@ -27,7 +27,6 @@ use gitbutler_repo::{
pub mod commands;
pub const EDIT_UNCOMMITED_FILES_REF: &str = "refs/gitbutler/edit_uncommited_files";
pub const EDIT_INITIAL_STATE_REF: &str = "refs/gitbutler/edit_initial_state";
fn save_uncommited_files(ctx: &CommandContext) -> Result<()> {
let repository = ctx.repository();
@ -123,7 +122,6 @@ fn checkout_edit_branch(ctx: &CommandContext, commit: &git2::Commit) -> Result<(
commit.parent(0)?
};
repository.reference(EDIT_BRANCH_REF, commit_parent.id(), true, "")?;
repository.reference(EDIT_INITIAL_STATE_REF, commit_parent.id(), true, "")?;
repository.set_head(EDIT_BRANCH_REF)?;
repository.checkout_head(Some(CheckoutBuilder::new().force().remove_untracked(true)))?;
@ -140,18 +138,6 @@ fn checkout_edit_branch(ctx: &CommandContext, commit: &git2::Commit) -> Result<(
),
)?;
let tree = repository.create_wd_tree()?;
// Commit initial state commit
repository.commit(
Some(EDIT_INITIAL_STATE_REF),
&author_signature,
&committer_signature,
"Initial state commit",
&tree,
&[&commit_parent],
)?;
Ok(())
}
@ -365,12 +351,9 @@ pub(crate) fn starting_index_state(
let commit_parent = commit.parent(0)?;
let commit_parent_tree = repository.find_real_tree(&commit_parent, Default::default())?;
let initial_state = repository
.find_reference(EDIT_INITIAL_STATE_REF)?
.peel_to_tree()?;
let index = get_commit_index(repository, &commit)?;
let diff =
repository.diff_tree_to_tree(Some(&commit_parent_tree), Some(&initial_state), None)?;
let diff = repository.diff_tree_to_index(Some(&commit_parent_tree), Some(&index), None)?;
let diff_files = hunks_by_filepath(Some(repository), &diff)?
.into_iter()