From 08e41f46d1a95fd0c3b7fd9205e75caa34df84b9 Mon Sep 17 00:00:00 2001 From: Nikita Galaiko Date: Tue, 12 Dec 2023 10:18:34 +0100 Subject: [PATCH] reflect squashing rules in ui --- packages/ui/src/lib/vbranches/types.ts | 4 +++ .../components/CommitListItem.svelte | 26 ++++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/packages/ui/src/lib/vbranches/types.ts b/packages/ui/src/lib/vbranches/types.ts index 44e10fd16..c448f37d7 100644 --- a/packages/ui/src/lib/vbranches/types.ts +++ b/packages/ui/src/lib/vbranches/types.ts @@ -79,6 +79,10 @@ export class Commit { files!: File[]; parentIds!: string[]; branchId!: string; + + isParentOf(possibleChild: Commit) { + return possibleChild.parentIds.includes(this.id); + } } export class RemoteCommit { diff --git a/packages/ui/src/routes/[projectId]/components/CommitListItem.svelte b/packages/ui/src/routes/[projectId]/components/CommitListItem.svelte index 630fe5903..bdfcb67e6 100644 --- a/packages/ui/src/routes/[projectId]/components/CommitListItem.svelte +++ b/packages/ui/src/routes/[projectId]/components/CommitListItem.svelte @@ -59,22 +59,28 @@ function acceptSquash(commit: Commit) { return (data: any) => { - return ( - isDraggableCommit(data) && - data.branchId == branch.id && - (commit.parentIds.includes(data.commit.id) || data.commit.parentIds.includes(commit.id)) - ); + if (!isDraggableCommit(data)) return false; + if (data.branchId != branch.id) return false; + + if (data.commit.isParentOf(commit)) { + if (data.commit.isIntegrated) return false; + if (data.commit.isRemote && !project.ok_with_force_push) return false; + return true; + } else if (commit.isParentOf(data.commit)) { + if (commit.isIntegrated) return false; + if (commit.isRemote && !project.ok_with_force_push) return false; + return true; + } else { + return false; + } }; } function onSquash(commit: Commit) { - function isParentOf(commit: Commit, other: Commit) { - return commit.parentIds.includes(other.id); - } return (data: DraggableCommit) => { - if (isParentOf(commit, data.commit)) { + if (data.commit.isParentOf(commit)) { branchController.squashBranchCommit(data.branchId, commit.id); - } else if (isParentOf(data.commit, commit)) { + } else if (commit.isParentOf(data.commit)) { branchController.squashBranchCommit(data.branchId, data.commit.id); } };