Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore(frontend): add rebase after merge option (#10667)

Liu Jif9eb7131cfc8
diff --git a/frontend/src/components/Branch/BranchMergeView/BranchMergeView.vue b/frontend/src/components/Branch/BranchMergeView/BranchMergeView.vue
index b108a7ca18..94c9eea037 100644
--- a/frontend/src/components/Branch/BranchMergeView/BranchMergeView.vue
+++ b/frontend/src/components/Branch/BranchMergeView/BranchMergeView.vue
@@ -3,7 +3,6 @@
<MaskSpinner v-if="state.isMerging" />
<MergeBranchSelect
- v-model:delete-branch-after-merged="state.deleteBranchAfterMerged"
:project="project"
:head-branch="headBranch"
:target-branch="targetBranch"
@@ -45,20 +44,19 @@
</div>
<div class="flex flex-row justify-end items-center gap-x-3">
- <NButton
- type="primary"
- :disabled="!allowConfirm || state.isMerging"
- @click="handleMergeBranch"
- >
- {{ $t("common.confirm") }}
- </NButton>
+ <MergeBranchButton
+ :button-props="{
+ type: 'primary',
+ disabled: !allowConfirm || state.isMerging,
+ }"
+ @perform-action="handleMergeBranch"
+ />
</div>
</div>
</template>
<script lang="ts" setup>
import { computedAsync } from "@vueuse/core";
-import { NButton } from "naive-ui";
import { Status } from "nice-grpc-common";
import { computed, reactive, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
@@ -69,13 +67,13 @@ import { ComposedProject } from "@/types";
import { Branch } from "@/types/proto/v1/branch_service";
import { extractGrpcErrorMessage, getErrorCode } from "@/utils/grpcweb";
import BranchComparison from "../common/BranchComparison.vue";
+import MergeBranchButton from "./MergeBranchButton.vue";
import MergeBranchSelect from "./MergeBranchSelect.vue";
import MergeBranchValidationStateView from "./MergeBranchValidationStateView.vue";
-import { MergeBranchValidationState } from "./types";
+import { MergeBranchValidationState, PostMergeAction } from "./types";
interface LocalState {
targetBranchName: string | null;
- deleteBranchAfterMerged: boolean;
isMerging: boolean;
}
@@ -96,7 +94,6 @@ const emit = defineEmits<{
const state = reactive<LocalState>({
targetBranchName: null,
- deleteBranchAfterMerged: false,
isMerging: false,
});
const { t } = useI18n();
@@ -184,7 +181,7 @@ const allowConfirm = computed(() => {
);
});
-const handleMergeBranch = async () => {
+const handleMergeBranch = async (post: PostMergeAction) => {
const target = targetBranch.value;
if (!target) return;
const head = headBranch.value;
@@ -198,27 +195,46 @@ const handleMergeBranch = async () => {
etag: "",
validateOnly: false,
});
- if (state.deleteBranchAfterMerged) {
+
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("branch.merge-rebase.merge-succeeded"),
+ });
+ if (post === "DELETE") {
await branchStore.deleteBranch(head.name);
pushNotification({
module: "bytebase",
style: "SUCCESS",
title: t("common.deleted"),
});
- }
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("branch.merge-rebase.merge-succeeded"),
- });
+ emit("merged", mergedBranch, head.name, undefined);
+ return;
+ }
+ if (post === "REBASE") {
+ await branchStore.deleteBranch(head.name);
+ const pendingRecreateBranch = Branch.fromPartial({});
+ if (head.parentBranch) {
+ pendingRecreateBranch.parentBranch = head.parentBranch;
+ } else {
+ pendingRecreateBranch.baselineDatabase = head.baselineDatabase;
+ }
+ const recreatedBranch = await branchStore.createBranch(
+ props.project.name,
+ head.branchId,
+ pendingRecreateBranch
+ );
- emit(
- "merged",
- mergedBranch,
- head.name,
- state.deleteBranchAfterMerged ? undefined : head
- );
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("branch.merge-rebase.rebase-succeeded"),
+ });
+ emit("merged", recreatedBranch, recreatedBranch.name, recreatedBranch);
+ return;
+ }
+ emit("merged", mergedBranch, head.name, head);
} catch (error: any) {
pushNotification({
module: "bytebase",
diff --git a/frontend/src/components/Branch/BranchMergeView/MergeBranchButton.vue b/frontend/src/components/Branch/BranchMergeView/MergeBranchButton.vue
new file mode 100644
index 0000000000..9a448248ae
--- /dev/null
+++ b/frontend/src/components/Branch/BranchMergeView/MergeBranchButton.vue
@@ -0,0 +1,57 @@
+<template>
+ <ContextMenuButton
+ :preference-key="`bb-branch-merge-action`"
+ :action-list="actions"
+ default-action-key="REBASE"
+ size="medium"
+ @click="
+ $emit(
+ 'perform-action',
+ ($event as ContextMenuButtonAction<PostMergeAction>).params
+ )
+ "
+ />
+</template>
+
+<script setup lang="ts">
+import { ButtonProps } from "naive-ui";
+import { computed } from "vue";
+import { useI18n } from "vue-i18n";
+import {
+ ContextMenuButton,
+ type ContextMenuButtonAction,
+} from "@/components/v2";
+import { PostMergeAction } from "./types";
+
+const props = defineProps<{
+ buttonProps?: ButtonProps;
+}>();
+
+defineEmits<{
+ (event: "perform-action", post: PostMergeAction): void;
+}>();
+
+const { t } = useI18n();
+const actions = computed((): ContextMenuButtonAction<PostMergeAction>[] => {
+ return [
+ {
+ key: "NOOP",
+ text: t("branch.merge-rebase.merge-branch"),
+ params: "NOOP",
+ props: props.buttonProps,
+ },
+ {
+ key: "REBASE",
+ text: t("branch.merge-rebase.post-merge-action.rebase"),
+ params: "REBASE",
+ props: props.buttonProps,
+ },
+ {
+ key: "DELETE",
+ text: t("branch.merge-rebase.post-merge-action.delete"),
+ params: "DELETE",
+ props: props.buttonProps,
+ },
+ ];
+});
+</script>
diff --git a/frontend/src/components/Branch/BranchMergeView/MergeBranchSelect.vue b/frontend/src/components/Branch/BranchMergeView/MergeBranchSelect.vue
index 96690b7d0a..5f5636d266 100644
--- a/frontend/src/components/Branch/BranchMergeView/MergeBranchSelect.vue
+++ b/frontend/src/components/Branch/BranchMergeView/MergeBranchSelect.vue
@@ -22,20 +22,11 @@
:filter="headBranchFilter"
@update:branch="$emit('update:head-branch-name', $event)"
/>
- <NCheckbox
- :checked="deleteBranchAfterMerged"
- @update:checked="
- $emit('update:delete-branch-after-merged', $event as boolean)
- "
- >
- {{ $t("branch.merge-rebase.delete-branch-after-merged") }}
- </NCheckbox>
</div>
</template>
<script setup lang="ts">
import { MoveLeftIcon } from "lucide-vue-next";
-import { NCheckbox } from "naive-ui";
import { ComposedProject } from "@/types";
import { Branch } from "@/types/proto/v1/branch_service";
@@ -43,13 +34,11 @@ const props = defineProps<{
project: ComposedProject;
targetBranch: Branch | undefined;
headBranch: Branch | undefined;
- deleteBranchAfterMerged: boolean;
}>();
defineEmits<{
(event: "update:head-branch-name", branch: string | undefined): void;
(event: "update:target-branch-name", branch: string | undefined): void;
- (event: "update:delete-branch-after-merged", on: boolean): void;
}>();
const targetBranchFilter = (branch: Branch) => {
diff --git a/frontend/src/components/Branch/BranchMergeView/types.ts b/frontend/src/components/Branch/BranchMergeView/types.ts
index bb54b314eb..0cf750f5ba 100644
--- a/frontend/src/components/Branch/BranchMergeView/types.ts
+++ b/frontend/src/components/Branch/BranchMergeView/types.ts
@@ -6,3 +6,5 @@ export type MergeBranchValidationState = {
branch?: Branch;
errmsg?: string;
};
+
+export type PostMergeAction = "NOOP" | "DELETE" | "REBASE";
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 7980001fbe..e41dc7e79d 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -3437,7 +3437,11 @@
"before-merge": "Before merge",
"after-merge": "After merge",
"before-rebase": "Before rebase",
- "after-rebase": "After rebase"
+ "after-rebase": "After rebase",
+ "post-merge-action": {
+ "rebase": "Merge and rebase branch",
+ "delete": "Merge and delete branch"
+ }
},
"source": {
"baseline-version": "Baseline version",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 7c3ce3746c..a45fe656cb 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -3434,7 +3434,11 @@
"before-merge": "Antes de fusionarse",
"after-merge": "Después de fusionar",
"before-rebase": "Antes de rebase",
- "after-rebase": "Después de rebase"
+ "after-rebase": "Después de rebase",
+ "post-merge-action": {
+ "rebase": "Fusionar y reorganizar rama",
+ "delete": "Fusionar y eliminar rama"
+ }
},
"source": {
"baseline-version": "Versión básica",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index ff0e5e5af8..175ff6b835 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -3434,7 +3434,11 @@
"before-merge": "マージ前",
"after-merge": "マージ後",
"before-rebase": "リベース前",
- "after-rebase": "リベース後"
+ "after-rebase": "リベース後",
+ "post-merge-action": {
+ "rebase": "ブランチをマージしてリベースする",
+ "delete": "ブランチのマージと削除"
+ }
},
"source": {
"baseline-version": "ベースラインバージョン",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 188e40842d..4faee99f73 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -3436,7 +3436,11 @@
"before-merge": "Trước khi hợp nhất",
"after-merge": "Sau khi hợp nhất",
"before-rebase": "Trước khi nổi loạn",
- "after-rebase": "Sau khi nổi loạn"
+ "after-rebase": "Sau khi nổi loạn",
+ "post-merge-action": {
+ "rebase": "Hợp nhất và rebase chi nhánh",
+ "delete": "Hợp nhất và xóa chi nhánh"
+ }
},
"source": {
"baseline-version": "Phiên bản cơ bản",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 261fd36297..584ab9e56b 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -3429,7 +3429,11 @@
"before-merge": "合并前",
"after-merge": "合并后",
"before-rebase": "rebase 前",
- "after-rebase": "rebase 后"
+ "after-rebase": "rebase 后",
+ "post-merge-action": {
+ "rebase": "合并且同步分支",
+ "delete": "合并且删除分支"
+ }
},
"source": {
"baseline-version": "基线版本",