Skip to content

Commit fe9f5fc

Browse files
committed
Also use the unassigned stack names in the UI
1 parent dbf1cc0 commit fe9f5fc

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

apps/desktop/cypress/e2e/support/mock/backend.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ export default class MockBackend {
623623

624624
// Do nothing for now
625625
return {
626+
unappliedStacksShortNames: [],
626627
stackId: 'something',
627628
unappliedStacks: []
628629
};

apps/desktop/src/lib/stacks/stack.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,43 @@ import type iconsJson from '@gitbutler/ui/data/icons.json';
77
export type CreateBranchFromBranchOutcome = {
88
stackId: string;
99
unappliedStacks: string[];
10+
unappliedStacksShortNames: string[];
1011
};
1112

13+
function stackCount(numStacks: number): string {
14+
if (numStacks === 1) {
15+
return 'one stack';
16+
} else {
17+
return 'some stacks';
18+
}
19+
}
20+
21+
function prettyNamedListIfPossible(expectedNames: number, names: string[]): string {
22+
// It could happen that not all stacks had names, for now we don't deal with that.
23+
// Also, the old codepath doesn't produce names.
24+
if (expectedNames !== names.length) {
25+
return stackCount(expectedNames);
26+
}
27+
if (names.length === 0) {
28+
return '';
29+
} else if (names.length === 1) {
30+
return `stack ${names[0]}`;
31+
} else if (names.length === 2) {
32+
return `stack ${names[0]} and stack ${names[1]}`;
33+
}
34+
35+
const allButLast = names.slice(0, -1);
36+
const last = names[names.length - 1];
37+
38+
return `${allButLast.map((n) => `stack ${n}`).join(', ')}, and stack ${last}`;
39+
}
40+
1241
export function handleCreateBranchFromBranchOutcome(outcome: CreateBranchFromBranchOutcome) {
1342
if (outcome.unappliedStacks.length > 0) {
1443
showToast({
1544
testId: TestId.StacksUnappliedToast,
16-
title: 'Heads up: We had to unapply some stacks to apply this one',
17-
message: `There were some conflicts detected when applying this branch into your workspace, so we automatically unapplied ${outcome.unappliedStacks.length} ${outcome.unappliedStacks.length === 1 ? 'stack' : 'stacks'}.
45+
title: `Heads up: We had to unapply ${stackCount(outcome.unappliedStacks.length)} to apply this one`,
46+
message: `There were some conflicts detected when applying this branch into your workspace, so we automatically unapplied ${prettyNamedListIfPossible(outcome.unappliedStacks.length, outcome.unappliedStacksShortNames)}.
1847
You can always re-apply them later from the branches page.`
1948
});
2049
}

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,20 @@ impl BranchManager<'_> {
192192
.id
193193
.context("BUG: newly applied stacks should always have a stack id")?;
194194
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()
195+
.metadata
196+
.as_ref()
197+
.map(|md| {
198+
md.stacks
199+
.iter()
200+
.filter_map(|s| {
201+
out.conflicting_stack_ids
202+
.contains(&s.id)
203+
.then(|| s.ref_name().map(|rn| rn.shorten().to_string()))
204+
.flatten()
205+
})
206+
.collect::<Vec<_>>()
202207
})
203-
.collect();
208+
.unwrap_or_default();
204209
return Ok((
205210
applied_branch_stack_id,
206211
out.conflicting_stack_ids,

0 commit comments

Comments
 (0)