mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-09-11 12:25:42 +03:00
Don't create unrequired wip commits
This commit is contained in:
parent
9e2f065109
commit
2f54e51a33
@ -8,7 +8,6 @@ use crate::{
|
||||
NameConflictResolution, VirtualBranchesExt,
|
||||
};
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use git2::build::TreeUpdateBuilder;
|
||||
use gitbutler_branch::{Branch, BranchExt, BranchId};
|
||||
use gitbutler_commit::commit_headers::CommitHeadersV2;
|
||||
use gitbutler_oplog::SnapshotExt;
|
||||
@ -180,16 +179,16 @@ impl BranchManager<'_> {
|
||||
vbranch.source_refname = Some(Refname::try_from(&branch)?);
|
||||
vb_state.set_branch(vbranch.clone())?;
|
||||
|
||||
self.build_metadata_commit(vbranch, &branch)?;
|
||||
self.build_wip_commit(vbranch, &branch)?;
|
||||
|
||||
Ok(branch)
|
||||
}
|
||||
|
||||
fn build_metadata_commit(
|
||||
fn build_wip_commit(
|
||||
&self,
|
||||
vbranch: &mut Branch,
|
||||
branch: &git2::Branch<'_>,
|
||||
) -> Result<git2::Oid> {
|
||||
) -> Result<Option<git2::Oid>> {
|
||||
let repo = self.project_repository.repo();
|
||||
|
||||
// Build wip tree as either any uncommitted changes or an empty tree
|
||||
@ -199,7 +198,8 @@ impl BranchManager<'_> {
|
||||
let tree = if vbranch_head_tree.id() != vbranch_wip_tree.id() {
|
||||
vbranch_wip_tree
|
||||
} else {
|
||||
repo.find_tree(TreeUpdateBuilder::new().create_updated(repo, &vbranch_head_tree)?)?
|
||||
// Don't create the wip commit if not required
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
// Build commit message
|
||||
@ -227,6 +227,6 @@ impl BranchManager<'_> {
|
||||
vbranch.not_in_workspace_wip_change_id = Some(commit_headers.change_id);
|
||||
vb_state.set_branch(vbranch.clone())?;
|
||||
|
||||
Ok(commit_oid)
|
||||
Ok(Some(commit_oid))
|
||||
}
|
||||
}
|
||||
|
@ -103,8 +103,7 @@ async fn rebase_commit() {
|
||||
assert_eq!(branches.len(), 1);
|
||||
assert_eq!(branches[0].id, branch1_id);
|
||||
assert_eq!(branches[0].files.len(), 0);
|
||||
// TODO: THIS SHOULD BE 1
|
||||
assert_eq!(branches[0].commits.len(), 2);
|
||||
assert_eq!(branches[0].commits.len(), 1);
|
||||
assert!(branches[0].active);
|
||||
assert!(!branches[0].conflicted);
|
||||
|
||||
|
@ -132,7 +132,7 @@ mod applied_branch {
|
||||
assert!(branches[0].conflicted);
|
||||
assert!(branches[0].base_current);
|
||||
assert_eq!(branches[0].files.len(), 1);
|
||||
assert_eq!(branches[0].commits.len(), 2);
|
||||
assert_eq!(branches[0].commits.len(), 1);
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
||||
"<<<<<<< ours\nconflict\n=======\nsecond\n>>>>>>> theirs\n"
|
||||
@ -208,7 +208,7 @@ mod applied_branch {
|
||||
assert!(branches[0].conflicted);
|
||||
assert!(branches[0].base_current);
|
||||
assert_eq!(branches[0].files.len(), 1);
|
||||
assert_eq!(branches[0].commits.len(), 2);
|
||||
assert_eq!(branches[0].commits.len(), 1);
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
||||
"<<<<<<< ours\nconflict\n=======\nsecond\n>>>>>>> theirs\n"
|
||||
|
Loading…
Reference in New Issue
Block a user