Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ but-rebase = { path = "crates/but-rebase" }
but-core = { path = "crates/but-core" }
but-workspace = { path = "crates/but-workspace" }
but-hunk-dependency = { path = "crates/but-hunk-dependency" }
but-debugging = { path = "crates/but-debugging" }

[profile.release]
codegen-units = 1 # Compile crates one after another so the compiler can optimize better
Expand Down
1 change: 1 addition & 0 deletions crates/gitbutler-branch-actions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ toml.workspace = true
pretty_assertions = "1.4"
gitbutler-testsupport.workspace = true
gitbutler-workspace.workspace = true
but-debugging.workspace = true
gix = { workspace = true, features = [] }
glob = "0.3.2"
tempfile.workspace = true
20 changes: 19 additions & 1 deletion crates/gitbutler-branch-actions/tests/extra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ use gitbutler_branch_actions::{
BranchManagerExt, Get,
};
use gitbutler_commit::{commit_ext::CommitExt, commit_headers::CommitHeadersV2};
use gitbutler_oxidize::OidExt;
use gitbutler_reference::{Refname, RemoteRefname};
use gitbutler_repo::RepositoryExt;
use gitbutler_stack::{BranchOwnershipClaims, Target, VirtualBranchesHandle};
use gitbutler_testsupport::{commit_all, virtual_branches::set_test_target, Case, Suite};
use gix::refs::transaction::PreviousValue;
use pretty_assertions::assert_eq;

#[test]
Expand Down Expand Up @@ -829,6 +831,12 @@ fn merge_vbranch_upstream_clean_rebase() -> Result<()> {
sha: target_oid,
push_remote_name: None,
})?;
ctx.gix_repository()?.reference(
"refs/remotes/origin/master".to_string(),
target_oid.to_gix(),
PreviousValue::Any,
"",
)?;

// add some uncommitted work
let file_path2 = Path::new("test2.txt");
Expand Down Expand Up @@ -959,6 +967,12 @@ fn merge_vbranch_upstream_conflict() -> Result<()> {
sha: target_oid,
push_remote_name: None,
})?;
ctx.gix_repository()?.reference(
"refs/remotes/origin/master".to_string(),
target_oid.to_gix(),
PreviousValue::Any,
"",
)?;

let remote_branch: RemoteRefname = "refs/remotes/origin/g-branch-1".parse().unwrap();
let branch_manager = ctx.branch_manager();
Expand Down Expand Up @@ -1764,6 +1778,8 @@ fn commit_partial_by_hunk() -> Result<()> {
let list_result = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branches = list_result.branches;
let branch = &branches.iter().find(|b| b.id == stack1_id).unwrap();

but_debugging::git_log(ctx.repo().path(), but_debugging::LogOptions::default().all(true));

assert_eq!(branch.files.len(), 1);
assert_eq!(branch.files[0].hunks.len(), 2);
Expand Down Expand Up @@ -1843,14 +1859,16 @@ fn commit_partial_by_file() -> Result<()> {
let list_result = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branches = list_result.branches;
let branch1 = &branches.iter().find(|b| b.id == stack1_id).unwrap();

but_debugging::git_log(ctx.repo().path(), but_debugging::LogOptions::default().all(true));

// branch one test.txt has just the 1st and 3rd hunks applied
let commit2 = &branch1.series[0].clone()?.patches[0].id;
let commit2 = ctx
.repo()
.find_commit(commit2.to_owned())
.expect("failed to get commit object");

let tree = commit1.tree().expect("failed to get tree");
let file_list = tree_to_file_list(ctx.repo(), &tree);
assert_eq!(file_list, vec!["test.txt", "test2.txt"]);
Expand Down
21 changes: 17 additions & 4 deletions crates/gitbutler-stack/src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,23 @@ impl Stack {
/// - If a target is not set for the project
/// - If the head commit of the stack is not found
pub fn merge_base(&self, stack_context: &StackContext) -> Result<git2::Oid> {
let target = stack_context.target();
let repository = stack_context.repository();
let merge_base = repository.merge_base(self.head(&repository.to_gix()?)?, target.sha)?;
Ok(merge_base)
let gix_repo = stack_context.repository().to_gix()?;
let git2_repository = stack_context.repository();
let target_sha = gix_repo
.find_reference(&stack_context.target().branch.to_string())?
.peel_to_commit()?
.id;
let mut revwalk = git2_repository.revwalk()?;
let head_oid = self.head(&gix_repo)?;
revwalk.hide(head_oid)?;
revwalk.push(target_sha.to_git2())?;
revwalk.simplify_first_parent()?;
if let Some(last) = revwalk.last() {
let commit = git2_repository.find_commit(last?)?;
Ok(commit.parent_id(0)?)
} else {
Ok(head_oid)
}
}

/// An initialized stack has at least one head (branch).
Expand Down
1 change: 1 addition & 0 deletions crates/gitbutler-testsupport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ gitbutler-stack.workspace = true
but-settings.workspace = true
gitbutler-oxidize.workspace = true
gitbutler-commit.workspace = true
but-debugging.workspace = true
termtree = "0.5.1"
uuid.workspace = true
9 changes: 9 additions & 0 deletions crates/gitbutler-testsupport/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ pub mod paths {

pub mod virtual_branches {
use gitbutler_command_context::CommandContext;
use gitbutler_oxidize::OidExt;
use gitbutler_stack::{Target, VirtualBranchesHandle};
use gix::refs::transaction::PreviousValue;

use crate::empty_bare_repository;

Expand All @@ -49,6 +51,13 @@ pub mod virtual_branches {
})
.expect("failed to write target");

ctx.gix_repository()?.reference(
"refs/remotes/origin/master".to_string(),
remote_repo.head().unwrap().target().unwrap().to_gix(),
PreviousValue::Any,
"",
)?;

gitbutler_branch_actions::update_workspace_commit(&vb_state, ctx)
.expect("failed to update workspace");

Expand Down
Loading