reflect squashing rules in ui

This commit is contained in:
Nikita Galaiko 2023-12-12 10:18:34 +01:00 committed by GitButler
parent a98ea8ccc3
commit 08e41f46d1
2 changed files with 20 additions and 10 deletions

View File

@ -79,6 +79,10 @@ export class Commit {
files!: File[]; files!: File[];
parentIds!: string[]; parentIds!: string[];
branchId!: string; branchId!: string;
isParentOf(possibleChild: Commit) {
return possibleChild.parentIds.includes(this.id);
}
} }
export class RemoteCommit { export class RemoteCommit {

View File

@ -59,22 +59,28 @@
function acceptSquash(commit: Commit) { function acceptSquash(commit: Commit) {
return (data: any) => { return (data: any) => {
return ( if (!isDraggableCommit(data)) return false;
isDraggableCommit(data) && if (data.branchId != branch.id) return false;
data.branchId == branch.id &&
(commit.parentIds.includes(data.commit.id) || data.commit.parentIds.includes(commit.id)) 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 onSquash(commit: Commit) {
function isParentOf(commit: Commit, other: Commit) {
return commit.parentIds.includes(other.id);
}
return (data: DraggableCommit) => { return (data: DraggableCommit) => {
if (isParentOf(commit, data.commit)) { if (data.commit.isParentOf(commit)) {
branchController.squashBranchCommit(data.branchId, commit.id); 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); branchController.squashBranchCommit(data.branchId, data.commit.id);
} }
}; };