Skip to content

Commit dbf1cc0

Browse files
committed
Also provide the names of the stacks that conflicted, so they can be shown.
1 parent 3025671 commit dbf1cc0

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

crates/but-testing/src/command/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ pub mod stacks {
282282
let ref_name = Refname::from_str(&format!("refs/remotes/{remote_name}/{name}"))?;
283283
let remote_ref_name = RemoteRefname::new(remote_name, name);
284284

285-
let (stack_id, _) = gitbutler_branch_actions::create_virtual_branch_from_branch(
285+
let (stack_id, _, _) = gitbutler_branch_actions::create_virtual_branch_from_branch(
286286
ctx,
287287
&ref_name,
288288
Some(remote_ref_name),

crates/but-tools/src/workspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@ pub fn split_branch(
14101410
let refname = Refname::Local(LocalRefname::new(&params.new_branch_name, None));
14111411
let branch_manager = ctx.branch_manager();
14121412

1413-
let (stack_id, _) = branch_manager.create_virtual_branch_from_branch(
1413+
let (stack_id, _, _) = branch_manager.create_virtual_branch_from_branch(
14141414
&refname,
14151415
None,
14161416
None,

crates/gitbutler-branch-actions/src/actions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ pub fn create_virtual_branch_from_branch(
516516
branch: &Refname,
517517
remote: Option<RemoteRefname>,
518518
pr_number: Option<usize>,
519-
) -> Result<(StackId, Vec<StackId>)> {
519+
) -> Result<(StackId, Vec<StackId>, Vec<String>)> {
520520
let mut guard = ctx.project().exclusive_worktree_access();
521521
ctx.verify(guard.write_permission())?;
522522
ensure_open_workspace_mode(ctx)

crates/gitbutler-branch-actions/src/branch_manager/branch_creation.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,21 @@ use crate::{
3434
pub struct CreateBranchFromBranchOutcome {
3535
pub stack_id: StackId,
3636
pub unapplied_stacks: Vec<StackId>,
37+
pub unapplied_stacks_short_names: Vec<String>,
3738
}
3839

39-
impl From<(StackId, Vec<StackId>)> for CreateBranchFromBranchOutcome {
40-
fn from((stack_id, unapplied_stacks): (StackId, Vec<StackId>)) -> Self {
40+
impl From<(StackId, Vec<StackId>, Vec<String>)> for CreateBranchFromBranchOutcome {
41+
fn from(
42+
(stack_id, unapplied_stacks, unapplied_stacks_short_names): (
43+
StackId,
44+
Vec<StackId>,
45+
Vec<String>,
46+
),
47+
) -> Self {
4148
Self {
4249
stack_id,
4350
unapplied_stacks,
51+
unapplied_stacks_short_names,
4452
}
4553
}
4654
}
@@ -145,7 +153,7 @@ impl BranchManager<'_> {
145153
upstream_branch: Option<RemoteRefname>,
146154
pr_number: Option<usize>,
147155
perm: &mut WorktreeWritePermission,
148-
) -> Result<(StackId, Vec<StackId>)> {
156+
) -> Result<(StackId, Vec<StackId>, Vec<String>)> {
149157
let branch_name = target
150158
.branch()
151159
.expect("always a branch reference")
@@ -183,7 +191,21 @@ impl BranchManager<'_> {
183191
.0
184192
.id
185193
.context("BUG: newly applied stacks should always have a stack id")?;
186-
return Ok((applied_branch_stack_id, out.conflicting_stack_ids));
194+
let conflicted_stack_short_names_for_display = ws
195+
.stacks
196+
.iter()
197+
.filter_map(|s| {
198+
out.conflicting_stack_ids
199+
.contains(&s.id?)
200+
.then(|| s.ref_name().map(|rn| rn.shorten().to_string()))
201+
.flatten()
202+
})
203+
.collect();
204+
return Ok((
205+
applied_branch_stack_id,
206+
out.conflicting_stack_ids,
207+
conflicted_stack_short_names_for_display,
208+
));
187209
}
188210
let old_cwd = (!self.ctx.app_settings().feature_flags.cv3)
189211
.then(|| self.ctx.repo().create_wd_tree(0).map(|tree| tree.id()))
@@ -312,14 +334,14 @@ impl BranchManager<'_> {
312334
self.ctx.add_branch_reference(&branch)?;
313335

314336
match self.apply_branch(branch.id, perm, old_workspace, old_cwd) {
315-
Ok((_, unapplied_stacks)) => Ok((branch.id, unapplied_stacks)),
337+
Ok((_, unapplied_stacks)) => Ok((branch.id, unapplied_stacks, vec![])),
316338
Err(err)
317339
if err
318340
.downcast_ref()
319341
.is_some_and(|marker: &Marker| *marker == Marker::ProjectConflict) =>
320342
{
321343
// if branch conflicts with the workspace, it's ok. keep it unapplied
322-
Ok((branch.id, vec![]))
344+
Ok((branch.id, vec![], vec![]))
323345
}
324346
Err(err) => Err(err).context("failed to apply"),
325347
}

crates/gitbutler-branch-actions/src/move_branch.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,13 @@ pub(crate) fn tear_off_branch(
133133
.context("failed to update gitbutler workspace")?;
134134

135135
let branch_manager = ctx.branch_manager();
136-
let (_, unapplied_stacks) = branch_manager.create_virtual_branch_from_branch(
137-
&Refname::Local(LocalRefname::new(subject_branch_name, None)),
138-
None,
139-
None,
140-
perm,
141-
)?;
136+
let (_, unapplied_stacks, _unapplied_stack_shortnames) = branch_manager
137+
.create_virtual_branch_from_branch(
138+
&Refname::Local(LocalRefname::new(subject_branch_name, None)),
139+
None,
140+
None,
141+
perm,
142+
)?;
142143

143144
Ok(MoveBranchResult {
144145
deleted_stacks,

0 commit comments

Comments
 (0)