Skip to content

Commit

Permalink
Merge pull request #7421 from gitbutlerapp/fix-move-commit-bug
Browse files Browse the repository at this point in the history
Fix move commit bug related to archived branches
  • Loading branch information
krlvi authored Feb 26, 2025
2 parents 75af988 + c9f4584 commit 61d526a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions apps/desktop/src/lib/dragging/stackingReorderDropzoneManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ export function buildNewStackOrder(
actorCommitId: string,
targetCommitId: string
): StackOrder | undefined {
const patchSeries = allSeries.map((s) => ({
name: s.name,
commitIds: s.patches.map((p) => p.id)
}));
const branches = allSeries
.filter((s) => !s.archived)
.map((s) => ({
name: s.name,
commitIds: s.patches.map((p) => p.id)
}));

const allCommitIds = patchSeries.flatMap((s) => s.commitIds);
const allCommitIds = branches.flatMap((s) => s.commitIds);

if (
targetCommitId !== 'top' &&
Expand All @@ -118,15 +120,15 @@ export function buildNewStackOrder(
throw new Error('Commit not found in series');
}

const currentSeriesIndex = patchSeries.findIndex((s) => s.name === currentSeries.name);
const currentSeriesIndex = branches.findIndex((s) => s.name === currentSeries.name);
if (currentSeriesIndex === -1) return undefined;

// Remove actorCommitId from its current position
patchSeries.forEach((s) => {
branches.forEach((s) => {
s.commitIds = s.commitIds.filter((id) => id !== actorCommitId);
});

const updatedCurrentSeries = patchSeries[currentSeriesIndex];
const updatedCurrentSeries = branches[currentSeriesIndex];
if (!updatedCurrentSeries) return undefined;

// Put actorCommtId in its new position
Expand All @@ -137,10 +139,10 @@ export function buildNewStackOrder(
updatedCurrentSeries.commitIds.splice(targetIndex + 1, 0, actorCommitId);
}

patchSeries[currentSeriesIndex] = updatedCurrentSeries;
branches[currentSeriesIndex] = updatedCurrentSeries;

return {
series: patchSeries
series: branches
};
}

Expand Down

0 comments on commit 61d526a

Please sign in to comment.