Rename fields named branch to stack where the type is Stack

This commit is contained in:
Kiril Videlov 2024-11-09 22:57:59 +01:00
parent 62a74107dc
commit d45e7d874d
7 changed files with 102 additions and 102 deletions

View File

@ -230,11 +230,11 @@ pub fn update_branch_order(
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx)
.context("Updating branch order requires open workspace mode")?; .context("Updating branch order requires open workspace mode")?;
for branch_update in branch_updates { for branch_update in branch_updates {
let branch = ctx let stack = ctx
.project() .project()
.virtual_branches() .virtual_branches()
.get_branch_in_workspace(branch_update.id)?; .get_branch_in_workspace(branch_update.id)?;
if branch_update.order != Some(branch.order) { if branch_update.order != Some(stack.order) {
vbranch::update_branch(&ctx, &branch_update)?; vbranch::update_branch(&ctx, &branch_update)?;
} }
} }

View File

@ -66,19 +66,19 @@ impl BranchManager<'_> {
delete_vb_state: bool, delete_vb_state: bool,
) -> Result<()> { ) -> Result<()> {
let vb_state = self.ctx.project().virtual_branches(); let vb_state = self.ctx.project().virtual_branches();
let Some(branch) = vb_state.try_branch(stack_id)? else { let Some(stack) = vb_state.try_branch(stack_id)? else {
return Ok(()); return Ok(());
}; };
// We don't want to try unapplying branches which are marked as not in workspace by the new metric // We don't want to try unapplying branches which are marked as not in workspace by the new metric
if !branch.in_workspace { if !stack.in_workspace {
return Ok(()); return Ok(());
} }
_ = self _ = self
.ctx .ctx
.project() .project()
.snapshot_branch_deletion(branch.name.clone(), perm); .snapshot_branch_deletion(stack.name.clone(), perm);
let repo = self.ctx.repository(); let repo = self.ctx.repository();
@ -93,7 +93,7 @@ impl BranchManager<'_> {
// doing this earlier in the flow, in case any of the steps that follow fail // doing this earlier in the flow, in case any of the steps that follow fail
vb_state vb_state
.mark_as_not_in_workspace(branch.id) .mark_as_not_in_workspace(stack.id)
.context("Failed to remove branch")?; .context("Failed to remove branch")?;
// go through the other applied branches and merge them into the final tree // go through the other applied branches and merge them into the final tree
@ -108,18 +108,18 @@ impl BranchManager<'_> {
let merge_options = gix_repo.tree_merge_options()?; let merge_options = gix_repo.tree_merge_options()?;
let final_tree_id = applied_statuses let final_tree_id = applied_statuses
.into_iter() .into_iter()
.filter(|(branch, _)| branch.id != stack_id) .filter(|(stack, _)| stack.id != stack_id)
.try_fold( .try_fold(
git2_to_gix_object_id(target_commit.tree_id()), git2_to_gix_object_id(target_commit.tree_id()),
|final_tree_id, status| -> Result<_> { |final_tree_id, status| -> Result<_> {
let branch = status.0; let stack = status.0;
let files = status let files = status
.1 .1
.into_iter() .into_iter()
.map(|file| (file.path, file.hunks)) .map(|file| (file.path, file.hunks))
.collect::<Vec<(PathBuf, Vec<VirtualBranchHunk>)>>(); .collect::<Vec<(PathBuf, Vec<VirtualBranchHunk>)>>();
let tree_oid = let tree_oid =
gitbutler_diff::write::hunks_onto_oid(self.ctx, branch.head(), files)?; gitbutler_diff::write::hunks_onto_oid(self.ctx, stack.head(), files)?;
let mut merge = gix_repo.merge_trees( let mut merge = gix_repo.merge_trees(
git2_to_gix_object_id(base_tree_id), git2_to_gix_object_id(base_tree_id),
final_tree_id, final_tree_id,
@ -143,7 +143,7 @@ impl BranchManager<'_> {
.context("failed to checkout tree")?; .context("failed to checkout tree")?;
if delete_vb_state { if delete_vb_state {
self.ctx.delete_branch_reference(&branch)?; self.ctx.delete_branch_reference(&stack)?;
} }
vbranch::ensure_selected_for_changes(&vb_state) vbranch::ensure_selected_for_changes(&vb_state)

View File

@ -87,9 +87,9 @@ pub fn integrate_upstream_commits(
let project = ctx.project(); let project = ctx.project();
let vb_state = project.virtual_branches(); let vb_state = project.virtual_branches();
let branch = vb_state.get_branch_in_workspace(stack_id)?; let stack = vb_state.get_branch_in_workspace(stack_id)?;
let Some(upstream_refname) = branch.clone().upstream else { let Some(upstream_refname) = stack.clone().upstream else {
bail!("No upstream reference found for branch"); bail!("No upstream reference found for branch");
}; };
@ -98,7 +98,7 @@ pub fn integrate_upstream_commits(
// If the upstream branch head is the same as the local, then the branch is // If the upstream branch head is the same as the local, then the branch is
// up to date. // up to date.
if upstream_branch_head == branch.head() { if upstream_branch_head == stack.head() {
return Ok(()); return Ok(());
} }
@ -109,20 +109,20 @@ pub fn integrate_upstream_commits(
let integrate_upstream_context = IntegrateUpstreamContext { let integrate_upstream_context = IntegrateUpstreamContext {
repository, repository,
target_branch_head, target_branch_head,
branch_head: branch.head(), branch_head: stack.head(),
branch_tree: branch.tree, branch_tree: stack.tree,
branch_name: &branch.name, branch_name: &stack.name,
remote_head: upstream_branch_head, remote_head: upstream_branch_head,
remote_branch_name: upstream_branch.name()?.unwrap_or("Unknown"), remote_branch_name: upstream_branch.name()?.unwrap_or("Unknown"),
prefers_merge: !branch.allow_rebasing, prefers_merge: !stack.allow_rebasing,
}; };
let BranchHeadAndTree { head, tree } = let BranchHeadAndTree { head, tree } =
integrate_upstream_context.inner_integrate_upstream_commits()?; integrate_upstream_context.inner_integrate_upstream_commits()?;
let mut branch = branch.clone(); let mut stack = stack.clone();
branch.set_stack_head(ctx, head, Some(tree))?; stack.set_stack_head(ctx, head, Some(tree))?;
checkout_branch_trees(ctx, perm)?; checkout_branch_trees(ctx, perm)?;

View File

@ -310,30 +310,30 @@ pub(crate) fn integrate_upstream(
// could enter a much worse state if we're simultaniously updating trees // could enter a much worse state if we're simultaniously updating trees
// Delete branches // Delete branches
for (branch_id, integration_result) in &integration_results { for (stack_id, integration_result) in &integration_results {
if !matches!(integration_result, IntegrationResult::DeleteBranch) { if !matches!(integration_result, IntegrationResult::DeleteBranch) {
continue; continue;
}; };
let branch = virtual_branches_state.get_branch(*branch_id)?; let stack = virtual_branches_state.get_branch(*stack_id)?;
virtual_branches_state.delete_branch_entry(branch_id)?; virtual_branches_state.delete_branch_entry(stack_id)?;
command_context.delete_branch_reference(&branch)?; command_context.delete_branch_reference(&stack)?;
} }
let permission = context._permission.expect("Permission provided above"); let permission = context._permission.expect("Permission provided above");
// Unapply branches // Unapply branches
for (branch_id, integration_result) in &integration_results { for (stack_id, integration_result) in &integration_results {
if !matches!(integration_result, IntegrationResult::UnapplyBranch) { if !matches!(integration_result, IntegrationResult::UnapplyBranch) {
continue; continue;
}; };
command_context command_context
.branch_manager() .branch_manager()
.save_and_unapply(*branch_id, permission)?; .save_and_unapply(*stack_id, permission)?;
} }
let mut branches = virtual_branches_state.list_branches_in_workspace()?; let mut stacks = virtual_branches_state.list_branches_in_workspace()?;
// Update branch trees // Update branch trees
for (branch_id, integration_result) in &integration_results { for (branch_id, integration_result) in &integration_results {
@ -341,19 +341,19 @@ pub(crate) fn integrate_upstream(
continue; continue;
}; };
let Some(branch) = branches.iter_mut().find(|branch| branch.id == *branch_id) else { let Some(stack) = stacks.iter_mut().find(|branch| branch.id == *branch_id) else {
continue; continue;
}; };
branch.set_stack_head(command_context, *head, Some(*tree))?; stack.set_stack_head(command_context, *head, Some(*tree))?;
branch.archive_integrated_heads(command_context)?; stack.archive_integrated_heads(command_context)?;
} }
// checkout_branch_trees won't checkout anything if there are no // checkout_branch_trees won't checkout anything if there are no
// applied branches, and returns the current_wd_tree as its result. // applied branches, and returns the current_wd_tree as its result.
// This is very sensible, but in this case, we want to checkout the // This is very sensible, but in this case, we want to checkout the
// new target sha. // new target sha.
if branches.is_empty() { if stacks.is_empty() {
context context
.repository .repository
.checkout_tree_builder(&context.new_target.tree()?) .checkout_tree_builder(&context.new_target.tree()?)
@ -588,20 +588,20 @@ mod test {
let old_target = test_repository.commit_tree(Some(&initial_commit), &[("foo.txt", "baz")]); let old_target = test_repository.commit_tree(Some(&initial_commit), &[("foo.txt", "baz")]);
let new_target = test_repository.commit_tree(Some(&old_target), &[("foo.txt", "qux")]); let new_target = test_repository.commit_tree(Some(&old_target), &[("foo.txt", "qux")]);
let branch = make_branch(old_target.id(), old_target.tree_id()); let stack = make_branch(old_target.id(), old_target.tree_id());
let context = UpstreamIntegrationContext { let context = UpstreamIntegrationContext {
_permission: None, _permission: None,
old_target, old_target,
new_target, new_target,
repository: &test_repository.repository, repository: &test_repository.repository,
virtual_branches_in_workspace: vec![branch.clone()], virtual_branches_in_workspace: vec![stack.clone()],
target_branch_name: "main".to_string(), target_branch_name: "main".to_string(),
}; };
assert_eq!( assert_eq!(
upstream_integration_statuses(&context).unwrap(), upstream_integration_statuses(&context).unwrap(),
BranchStatuses::UpdatesRequired(vec![(branch.id, BranchStatus::Empty)]), BranchStatuses::UpdatesRequired(vec![(stack.id, BranchStatus::Empty)]),
) )
} }
@ -613,21 +613,21 @@ mod test {
let branch_head = test_repository.commit_tree(Some(&old_target), &[("foo.txt", "fux")]); let branch_head = test_repository.commit_tree(Some(&old_target), &[("foo.txt", "fux")]);
let new_target = test_repository.commit_tree(Some(&old_target), &[("foo.txt", "qux")]); let new_target = test_repository.commit_tree(Some(&old_target), &[("foo.txt", "qux")]);
let branch = make_branch(branch_head.id(), branch_head.tree_id()); let stack = make_branch(branch_head.id(), branch_head.tree_id());
let context = UpstreamIntegrationContext { let context = UpstreamIntegrationContext {
_permission: None, _permission: None,
old_target, old_target,
new_target: new_target.clone(), new_target: new_target.clone(),
repository: &test_repository.repository, repository: &test_repository.repository,
virtual_branches_in_workspace: vec![branch.clone()], virtual_branches_in_workspace: vec![stack.clone()],
target_branch_name: "main".to_string(), target_branch_name: "main".to_string(),
}; };
assert_eq!( assert_eq!(
upstream_integration_statuses(&context).unwrap(), upstream_integration_statuses(&context).unwrap(),
BranchStatuses::UpdatesRequired(vec![( BranchStatuses::UpdatesRequired(vec![(
branch.id, stack.id,
BranchStatus::Conflicted { BranchStatus::Conflicted {
potentially_conflicted_uncommited_changes: false potentially_conflicted_uncommited_changes: false
} }
@ -637,8 +637,8 @@ mod test {
let updates = compute_resolutions( let updates = compute_resolutions(
&context, &context,
&[Resolution { &[Resolution {
branch_id: branch.id, branch_id: stack.id,
branch_tree: branch.tree, branch_tree: stack.tree,
approach: ResolutionApproach::Rebase, approach: ResolutionApproach::Rebase,
}], }],
None, None,
@ -670,21 +670,21 @@ mod test {
// new target diverged from old target // new target diverged from old target
let new_target = test_repository.commit_tree(Some(&initial_commit), &[("foo.txt", "qux")]); let new_target = test_repository.commit_tree(Some(&initial_commit), &[("foo.txt", "qux")]);
let branch = make_branch(branch_head.id(), branch_head.tree_id()); let stack = make_branch(branch_head.id(), branch_head.tree_id());
let context = UpstreamIntegrationContext { let context = UpstreamIntegrationContext {
_permission: None, _permission: None,
old_target, old_target,
new_target: new_target.clone(), new_target: new_target.clone(),
repository: &test_repository.repository, repository: &test_repository.repository,
virtual_branches_in_workspace: vec![branch.clone()], virtual_branches_in_workspace: vec![stack.clone()],
target_branch_name: "main".to_string(), target_branch_name: "main".to_string(),
}; };
assert_eq!( assert_eq!(
upstream_integration_statuses(&context).unwrap(), upstream_integration_statuses(&context).unwrap(),
BranchStatuses::UpdatesRequired(vec![( BranchStatuses::UpdatesRequired(vec![(
branch.id, stack.id,
BranchStatus::Conflicted { BranchStatus::Conflicted {
potentially_conflicted_uncommited_changes: false potentially_conflicted_uncommited_changes: false
} }
@ -694,8 +694,8 @@ mod test {
let updates = compute_resolutions( let updates = compute_resolutions(
&context, &context,
&[Resolution { &[Resolution {
branch_id: branch.id, branch_id: stack.id,
branch_tree: branch.tree, branch_tree: stack.tree,
approach: ResolutionApproach::Rebase, approach: ResolutionApproach::Rebase,
}], }],
Some(BaseBranchResolutionApproach::HardReset), Some(BaseBranchResolutionApproach::HardReset),
@ -729,27 +729,27 @@ mod test {
let new_target = let new_target =
test_repository.commit_tree(Some(&initial_commit), &[("other.txt", "qux")]); test_repository.commit_tree(Some(&initial_commit), &[("other.txt", "qux")]);
let branch = make_branch(branch_head.id(), branch_head.tree_id()); let stack = make_branch(branch_head.id(), branch_head.tree_id());
let context = UpstreamIntegrationContext { let context = UpstreamIntegrationContext {
_permission: None, _permission: None,
old_target, old_target,
new_target: new_target.clone(), new_target: new_target.clone(),
repository: &test_repository.repository, repository: &test_repository.repository,
virtual_branches_in_workspace: vec![branch.clone()], virtual_branches_in_workspace: vec![stack.clone()],
target_branch_name: "main".to_string(), target_branch_name: "main".to_string(),
}; };
assert_eq!( assert_eq!(
upstream_integration_statuses(&context).unwrap(), upstream_integration_statuses(&context).unwrap(),
BranchStatuses::UpdatesRequired(vec![(branch.id, BranchStatus::SaflyUpdatable)]), BranchStatuses::UpdatesRequired(vec![(stack.id, BranchStatus::SaflyUpdatable)]),
); );
let updates = compute_resolutions( let updates = compute_resolutions(
&context, &context,
&[Resolution { &[Resolution {
branch_id: branch.id, branch_id: stack.id,
branch_tree: branch.tree, branch_tree: stack.tree,
approach: ResolutionApproach::Rebase, approach: ResolutionApproach::Rebase,
}], }],
Some(BaseBranchResolutionApproach::HardReset), Some(BaseBranchResolutionApproach::HardReset),
@ -781,7 +781,7 @@ mod test {
// new target diverged from old target // new target diverged from old target
let new_target = test_repository.commit_tree(Some(&initial_commit), &[("foo.txt", "qux")]); let new_target = test_repository.commit_tree(Some(&initial_commit), &[("foo.txt", "qux")]);
let branch = make_branch(branch_head.id(), branch_head.tree_id()); let stack = make_branch(branch_head.id(), branch_head.tree_id());
let commits_to_rebase = test_repository let commits_to_rebase = test_repository
.repository .repository
@ -806,14 +806,14 @@ mod test {
.find_commit(head_after_rebase) .find_commit(head_after_rebase)
.unwrap(), .unwrap(),
repository: &test_repository.repository, repository: &test_repository.repository,
virtual_branches_in_workspace: vec![branch.clone()], virtual_branches_in_workspace: vec![stack.clone()],
target_branch_name: "main".to_string(), target_branch_name: "main".to_string(),
}; };
assert_eq!( assert_eq!(
upstream_integration_statuses(&context).unwrap(), upstream_integration_statuses(&context).unwrap(),
BranchStatuses::UpdatesRequired(vec![( BranchStatuses::UpdatesRequired(vec![(
branch.id, stack.id,
BranchStatus::Conflicted { BranchStatus::Conflicted {
potentially_conflicted_uncommited_changes: false potentially_conflicted_uncommited_changes: false
} }
@ -823,8 +823,8 @@ mod test {
let updates = compute_resolutions( let updates = compute_resolutions(
&context, &context,
&[Resolution { &[Resolution {
branch_id: branch.id, branch_id: stack.id,
branch_tree: branch.tree, branch_tree: stack.tree,
approach: ResolutionApproach::Rebase, approach: ResolutionApproach::Rebase,
}], }],
Some(BaseBranchResolutionApproach::Rebase), Some(BaseBranchResolutionApproach::Rebase),
@ -856,7 +856,7 @@ mod test {
// new target diverged from old target // new target diverged from old target
let new_target = test_repository.commit_tree(Some(&initial_commit), &[("foo.txt", "qux")]); let new_target = test_repository.commit_tree(Some(&initial_commit), &[("foo.txt", "qux")]);
let branch = make_branch(branch_head.id(), branch_head.tree_id()); let stack = make_branch(branch_head.id(), branch_head.tree_id());
let commits_to_rebase = test_repository let commits_to_rebase = test_repository
.repository .repository
@ -881,20 +881,20 @@ mod test {
.find_commit(head_after_rebase) .find_commit(head_after_rebase)
.unwrap(), .unwrap(),
repository: &test_repository.repository, repository: &test_repository.repository,
virtual_branches_in_workspace: vec![branch.clone()], virtual_branches_in_workspace: vec![stack.clone()],
target_branch_name: "main".to_string(), target_branch_name: "main".to_string(),
}; };
assert_eq!( assert_eq!(
upstream_integration_statuses(&context).unwrap(), upstream_integration_statuses(&context).unwrap(),
BranchStatuses::UpdatesRequired(vec![(branch.id, BranchStatus::SaflyUpdatable)]), BranchStatuses::UpdatesRequired(vec![(stack.id, BranchStatus::SaflyUpdatable)]),
); );
let updates = compute_resolutions( let updates = compute_resolutions(
&context, &context,
&[Resolution { &[Resolution {
branch_id: branch.id, branch_id: stack.id,
branch_tree: branch.tree, branch_tree: stack.tree,
approach: ResolutionApproach::Rebase, approach: ResolutionApproach::Rebase,
}], }],
Some(BaseBranchResolutionApproach::Rebase), Some(BaseBranchResolutionApproach::Rebase),
@ -926,7 +926,7 @@ mod test {
// new target diverged from old target // new target diverged from old target
let new_target = test_repository.commit_tree(Some(&initial_commit), &[("foo.txt", "qux")]); let new_target = test_repository.commit_tree(Some(&initial_commit), &[("foo.txt", "qux")]);
let branch = make_branch(branch_head.id(), branch_head.tree_id()); let stack = make_branch(branch_head.id(), branch_head.tree_id());
let merge_commit = gitbutler_merge_commits( let merge_commit = gitbutler_merge_commits(
&test_repository.repository, &test_repository.repository,
@ -942,14 +942,14 @@ mod test {
old_target, old_target,
new_target: merge_commit.clone(), new_target: merge_commit.clone(),
repository: &test_repository.repository, repository: &test_repository.repository,
virtual_branches_in_workspace: vec![branch.clone()], virtual_branches_in_workspace: vec![stack.clone()],
target_branch_name: "main".to_string(), target_branch_name: "main".to_string(),
}; };
assert_eq!( assert_eq!(
upstream_integration_statuses(&context).unwrap(), upstream_integration_statuses(&context).unwrap(),
BranchStatuses::UpdatesRequired(vec![( BranchStatuses::UpdatesRequired(vec![(
branch.id, stack.id,
BranchStatus::Conflicted { BranchStatus::Conflicted {
potentially_conflicted_uncommited_changes: false potentially_conflicted_uncommited_changes: false
} }
@ -959,8 +959,8 @@ mod test {
let updates = compute_resolutions( let updates = compute_resolutions(
&context, &context,
&[Resolution { &[Resolution {
branch_id: branch.id, branch_id: stack.id,
branch_tree: branch.tree, branch_tree: stack.tree,
approach: ResolutionApproach::Rebase, approach: ResolutionApproach::Rebase,
}], }],
Some(BaseBranchResolutionApproach::Merge), Some(BaseBranchResolutionApproach::Merge),
@ -992,7 +992,7 @@ mod test {
// new target diverged from old target // new target diverged from old target
let new_target = test_repository.commit_tree(Some(&initial_commit), &[("foo.txt", "qux")]); let new_target = test_repository.commit_tree(Some(&initial_commit), &[("foo.txt", "qux")]);
let branch = make_branch(branch_head.id(), branch_head.tree_id()); let stack = make_branch(branch_head.id(), branch_head.tree_id());
let merge_commit = gitbutler_merge_commits( let merge_commit = gitbutler_merge_commits(
&test_repository.repository, &test_repository.repository,
@ -1008,20 +1008,20 @@ mod test {
old_target, old_target,
new_target: merge_commit.clone(), new_target: merge_commit.clone(),
repository: &test_repository.repository, repository: &test_repository.repository,
virtual_branches_in_workspace: vec![branch.clone()], virtual_branches_in_workspace: vec![stack.clone()],
target_branch_name: "main".to_string(), target_branch_name: "main".to_string(),
}; };
assert_eq!( assert_eq!(
upstream_integration_statuses(&context).unwrap(), upstream_integration_statuses(&context).unwrap(),
BranchStatuses::UpdatesRequired(vec![(branch.id, BranchStatus::SaflyUpdatable)]), BranchStatuses::UpdatesRequired(vec![(stack.id, BranchStatus::SaflyUpdatable)]),
); );
let updates = compute_resolutions( let updates = compute_resolutions(
&context, &context,
&[Resolution { &[Resolution {
branch_id: branch.id, branch_id: stack.id,
branch_tree: branch.tree, branch_tree: stack.tree,
approach: ResolutionApproach::Rebase, approach: ResolutionApproach::Rebase,
}], }],
Some(BaseBranchResolutionApproach::Merge), Some(BaseBranchResolutionApproach::Merge),
@ -1052,21 +1052,21 @@ mod test {
let branch_head = test_repository.commit_tree(Some(&old_target), &[("foo.txt", "fux")]); let branch_head = test_repository.commit_tree(Some(&old_target), &[("foo.txt", "fux")]);
let new_target = test_repository.commit_tree(Some(&old_target), &[("foo.txt", "qux")]); let new_target = test_repository.commit_tree(Some(&old_target), &[("foo.txt", "qux")]);
let branch = make_branch(old_target.id(), branch_head.tree_id()); let stack = make_branch(old_target.id(), branch_head.tree_id());
let context = UpstreamIntegrationContext { let context = UpstreamIntegrationContext {
_permission: None, _permission: None,
old_target, old_target,
new_target, new_target,
repository: &test_repository.repository, repository: &test_repository.repository,
virtual_branches_in_workspace: vec![branch.clone()], virtual_branches_in_workspace: vec![stack.clone()],
target_branch_name: "main".to_string(), target_branch_name: "main".to_string(),
}; };
assert_eq!( assert_eq!(
upstream_integration_statuses(&context).unwrap(), upstream_integration_statuses(&context).unwrap(),
BranchStatuses::UpdatesRequired(vec![( BranchStatuses::UpdatesRequired(vec![(
branch.id, stack.id,
BranchStatus::Conflicted { BranchStatus::Conflicted {
potentially_conflicted_uncommited_changes: true potentially_conflicted_uncommited_changes: true
} }
@ -1083,21 +1083,21 @@ mod test {
let branch_tree = test_repository.commit_tree(Some(&old_target), &[("foo.txt", "bax")]); let branch_tree = test_repository.commit_tree(Some(&old_target), &[("foo.txt", "bax")]);
let new_target = test_repository.commit_tree(Some(&old_target), &[("foo.txt", "qux")]); let new_target = test_repository.commit_tree(Some(&old_target), &[("foo.txt", "qux")]);
let branch = make_branch(branch_head.id(), branch_tree.tree_id()); let stack = make_branch(branch_head.id(), branch_tree.tree_id());
let context = UpstreamIntegrationContext { let context = UpstreamIntegrationContext {
_permission: None, _permission: None,
old_target, old_target,
new_target, new_target,
repository: &test_repository.repository, repository: &test_repository.repository,
virtual_branches_in_workspace: vec![branch.clone()], virtual_branches_in_workspace: vec![stack.clone()],
target_branch_name: "main".to_string(), target_branch_name: "main".to_string(),
}; };
assert_eq!( assert_eq!(
upstream_integration_statuses(&context).unwrap(), upstream_integration_statuses(&context).unwrap(),
BranchStatuses::UpdatesRequired(vec![( BranchStatuses::UpdatesRequired(vec![(
branch.id, stack.id,
BranchStatus::Conflicted { BranchStatus::Conflicted {
potentially_conflicted_uncommited_changes: true potentially_conflicted_uncommited_changes: true
} }
@ -1112,20 +1112,20 @@ mod test {
let old_target = test_repository.commit_tree(Some(&initial_commit), &[("foo.txt", "baz")]); let old_target = test_repository.commit_tree(Some(&initial_commit), &[("foo.txt", "baz")]);
let new_target = test_repository.commit_tree(Some(&old_target), &[("foo.txt", "qux")]); let new_target = test_repository.commit_tree(Some(&old_target), &[("foo.txt", "qux")]);
let branch = make_branch(new_target.id(), new_target.tree_id()); let stack = make_branch(new_target.id(), new_target.tree_id());
let context = UpstreamIntegrationContext { let context = UpstreamIntegrationContext {
_permission: None, _permission: None,
old_target, old_target,
new_target, new_target,
repository: &test_repository.repository, repository: &test_repository.repository,
virtual_branches_in_workspace: vec![branch.clone()], virtual_branches_in_workspace: vec![stack.clone()],
target_branch_name: "main".to_string(), target_branch_name: "main".to_string(),
}; };
assert_eq!( assert_eq!(
upstream_integration_statuses(&context).unwrap(), upstream_integration_statuses(&context).unwrap(),
BranchStatuses::UpdatesRequired(vec![(branch.id, BranchStatus::FullyIntegrated)]), BranchStatuses::UpdatesRequired(vec![(stack.id, BranchStatus::FullyIntegrated)]),
) )
} }
@ -1143,20 +1143,20 @@ mod test {
let tree = test_repository let tree = test_repository
.commit_tree(Some(&old_target), &[("foo.txt", "baz"), ("bar.txt", "qux")]); .commit_tree(Some(&old_target), &[("foo.txt", "baz"), ("bar.txt", "qux")]);
let branch = make_branch(new_target.id(), tree.tree_id()); let stack = make_branch(new_target.id(), tree.tree_id());
let context = UpstreamIntegrationContext { let context = UpstreamIntegrationContext {
_permission: None, _permission: None,
old_target, old_target,
new_target, new_target,
repository: &test_repository.repository, repository: &test_repository.repository,
virtual_branches_in_workspace: vec![branch.clone()], virtual_branches_in_workspace: vec![stack.clone()],
target_branch_name: "main".to_string(), target_branch_name: "main".to_string(),
}; };
assert_eq!( assert_eq!(
upstream_integration_statuses(&context).unwrap(), upstream_integration_statuses(&context).unwrap(),
BranchStatuses::UpdatesRequired(vec![(branch.id, BranchStatus::SaflyUpdatable)]), BranchStatuses::UpdatesRequired(vec![(stack.id, BranchStatus::SaflyUpdatable)]),
) )
} }
@ -1183,20 +1183,20 @@ mod test {
&[("file-one.txt", "bar"), ("file-two.txt", "baz")], &[("file-one.txt", "bar"), ("file-two.txt", "baz")],
); );
let branch = make_branch(branch_head.id(), branch_tree.tree_id()); let stack = make_branch(branch_head.id(), branch_tree.tree_id());
let context = UpstreamIntegrationContext { let context = UpstreamIntegrationContext {
_permission: None, _permission: None,
old_target, old_target,
new_target, new_target,
repository: &test_repository.repository, repository: &test_repository.repository,
virtual_branches_in_workspace: vec![branch.clone()], virtual_branches_in_workspace: vec![stack.clone()],
target_branch_name: "main".to_string(), target_branch_name: "main".to_string(),
}; };
assert_eq!( assert_eq!(
upstream_integration_statuses(&context).unwrap(), upstream_integration_statuses(&context).unwrap(),
BranchStatuses::UpdatesRequired(vec![(branch.id, BranchStatus::SaflyUpdatable)]), BranchStatuses::UpdatesRequired(vec![(stack.id, BranchStatus::SaflyUpdatable)]),
) )
} }
} }

View File

@ -230,7 +230,7 @@ pub(crate) fn reset_files(
) -> Result<()> { ) -> Result<()> {
ctx.assure_resolved()?; ctx.assure_resolved()?;
let branch = ctx let stack = ctx
.project() .project()
.virtual_branches() .virtual_branches()
.list_branches_in_workspace() .list_branches_in_workspace()
@ -240,7 +240,7 @@ pub(crate) fn reset_files(
.with_context(|| { .with_context(|| {
format!("could not find applied branch with id {stack_id} to reset files from") format!("could not find applied branch with id {stack_id} to reset files from")
})?; })?;
let claims: Vec<_> = branch let claims: Vec<_> = stack
.ownership .ownership
.claims .claims
.into_iter() .into_iter()

View File

@ -57,19 +57,19 @@ pub fn status(project: Project) -> Result<()> {
} }
pub fn unapply(project: Project, branch_name: String) -> Result<()> { pub fn unapply(project: Project, branch_name: String) -> Result<()> {
let branch = branch_by_name(&project, &branch_name)?; let stack = branch_by_name(&project, &branch_name)?;
debug_print(gitbutler_branch_actions::save_and_unapply_virutal_branch( debug_print(gitbutler_branch_actions::save_and_unapply_virutal_branch(
&project, branch.id, &project, stack.id,
)?) )?)
} }
pub fn apply(project: Project, branch_name: String) -> Result<()> { pub fn apply(project: Project, branch_name: String) -> Result<()> {
let branch = branch_by_name(&project, &branch_name)?; let stack = branch_by_name(&project, &branch_name)?;
let ctx = CommandContext::open(&project)?; let ctx = CommandContext::open(&project)?;
let mut guard = project.exclusive_worktree_access(); let mut guard = project.exclusive_worktree_access();
debug_print( debug_print(
ctx.branch_manager().create_virtual_branch_from_branch( ctx.branch_manager().create_virtual_branch_from_branch(
branch stack
.source_refname .source_refname
.as_ref() .as_ref()
.context("local reference name was missing")?, .context("local reference name was missing")?,
@ -96,8 +96,8 @@ pub fn create(project: Project, branch_name: String, set_default: bool) -> Resul
} }
pub fn set_default(project: Project, branch_name: String) -> Result<()> { pub fn set_default(project: Project, branch_name: String) -> Result<()> {
let branch = branch_by_name(&project, &branch_name)?; let stack = branch_by_name(&project, &branch_name)?;
set_default_branch(&project, &branch) set_default_branch(&project, &stack)
} }
fn set_default_branch(project: &Project, stack: &Stack) -> Result<()> { fn set_default_branch(project: &Project, stack: &Stack) -> Result<()> {
@ -124,7 +124,7 @@ pub fn series(project: Project, stack_name: String, new_series_name: String) ->
} }
pub fn commit(project: Project, branch_name: String, message: String) -> Result<()> { pub fn commit(project: Project, branch_name: String, message: String) -> Result<()> {
let branch = branch_by_name(&project, &branch_name)?; let stack = branch_by_name(&project, &branch_name)?;
let (info, skipped) = gitbutler_branch_actions::list_virtual_branches(&project)?; let (info, skipped) = gitbutler_branch_actions::list_virtual_branches(&project)?;
if !skipped.is_empty() { if !skipped.is_empty() {
@ -136,7 +136,7 @@ pub fn commit(project: Project, branch_name: String, message: String) -> Result<
let populated_branch = info let populated_branch = info
.iter() .iter()
.find(|b| b.id == branch.id) .find(|b| b.id == stack.id)
.expect("A populated branch exists for a branch we can list"); .expect("A populated branch exists for a branch we can list");
if populated_branch.ownership.claims.is_empty() { if populated_branch.ownership.claims.is_empty() {
bail!( bail!(
@ -165,7 +165,7 @@ pub fn commit(project: Project, branch_name: String, message: String) -> Result<
let run_hooks = false; let run_hooks = false;
debug_print(gitbutler_branch_actions::create_commit( debug_print(gitbutler_branch_actions::create_commit(
&project, &project,
branch.id, stack.id,
&message, &message,
Some(&populated_branch.ownership), Some(&populated_branch.ownership),
run_hooks, run_hooks,

View File

@ -42,13 +42,13 @@ mod compute_updated_branch_head {
let head = test_repository.commit_tree(Some(&base_commit), &[("foo.txt", "bar")]); let head = test_repository.commit_tree(Some(&base_commit), &[("foo.txt", "bar")]);
let tree = test_repository.commit_tree(Some(&head), &[("foo.txt", "baz")]); let tree = test_repository.commit_tree(Some(&head), &[("foo.txt", "baz")]);
let branch = make_branch(head.id(), tree.tree_id()); let stack = make_branch(head.id(), tree.tree_id());
let BranchHeadAndTree { head, tree } = let BranchHeadAndTree { head, tree } =
compute_updated_branch_head(&test_repository.repository, &branch, head.id()).unwrap(); compute_updated_branch_head(&test_repository.repository, &stack, head.id()).unwrap();
assert_eq!(head, branch.head()); assert_eq!(head, stack.head());
assert_eq!(tree, branch.tree); assert_eq!(tree, stack.tree);
} }
/// When the head ID is different from the branch ID, we should rebase the /// When the head ID is different from the branch ID, we should rebase the
@ -67,12 +67,12 @@ mod compute_updated_branch_head {
let tree = let tree =
test_repository.commit_tree(Some(&head), &[("foo.txt", "bar"), ("bar.txt", "baz")]); test_repository.commit_tree(Some(&head), &[("foo.txt", "bar"), ("bar.txt", "baz")]);
let branch = make_branch(head.id(), tree.tree_id()); let stack = make_branch(head.id(), tree.tree_id());
let new_head = test_repository.commit_tree(Some(&base_commit), &[("foo.txt", "new")]); let new_head = test_repository.commit_tree(Some(&base_commit), &[("foo.txt", "new")]);
let BranchHeadAndTree { head, tree } = let BranchHeadAndTree { head, tree } =
compute_updated_branch_head(&test_repository.repository, &branch, new_head.id()) compute_updated_branch_head(&test_repository.repository, &stack, new_head.id())
.unwrap(); .unwrap();
assert_eq!(head, new_head.id()); assert_eq!(head, new_head.id());
@ -97,12 +97,12 @@ mod compute_updated_branch_head {
let head = test_repository.commit_tree(Some(&base_commit), &[("foo.txt", "bar")]); let head = test_repository.commit_tree(Some(&base_commit), &[("foo.txt", "bar")]);
let tree = test_repository.commit_tree(Some(&head), &[("foo.txt", "baz")]); let tree = test_repository.commit_tree(Some(&head), &[("foo.txt", "baz")]);
let branch = make_branch(head.id(), tree.tree_id()); let stack = make_branch(head.id(), tree.tree_id());
let new_head = test_repository.commit_tree(Some(&base_commit), &[("foo.txt", "new")]); let new_head = test_repository.commit_tree(Some(&base_commit), &[("foo.txt", "new")]);
let BranchHeadAndTree { head, tree } = let BranchHeadAndTree { head, tree } =
compute_updated_branch_head(&test_repository.repository, &branch, new_head.id()) compute_updated_branch_head(&test_repository.repository, &stack, new_head.id())
.unwrap(); .unwrap();
let new_new_head = test_repository.repository.find_commit(head).unwrap(); let new_new_head = test_repository.repository.find_commit(head).unwrap();