Skip to content

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

feat(branch): generate conflict string in rebase branch (#10031)

h3n4l794d437ff320
diff --git a/backend/api/v1/branch_service.go b/backend/api/v1/branch_service.go
index 4ed40c4259..caae4c5229 100644
--- a/backend/api/v1/branch_service.go
+++ b/backend/api/v1/branch_service.go
@@ -3,8 +3,10 @@ package v1
import (
"context"
"fmt"
+ "io"
"log/slog"
"path"
+ "strings"
"golang.org/x/exp/slices"
"google.golang.org/grpc/codes"
@@ -12,6 +14,8 @@ import (
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/timestamppb"
+ "github.com/epiclabs-io/diff3"
+
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
enterprise "github.com/bytebase/bytebase/backend/enterprise/api"
@@ -455,7 +459,16 @@ func (s *BranchService) RebaseBranch(ctx context.Context, request *v1pb.RebaseBr
mergedTarget, err := tryMerge(baseBranch.Base.Metadata, baseBranch.Head.Metadata, upstreamMetadata)
if err != nil {
slog.Info("cannot rebase branches", log.BBError(err))
- return &v1pb.RebaseBranchResponse{Result: &v1pb.RebaseBranchResponse_ConflictSchema{ConflictSchema: "TBD"}}, nil
+ conflictSchema, err := diff3.Merge(strings.NewReader(string(baseBranch.BaseSchema)), strings.NewReader(string(baseBranch.HeadSchema)), strings.NewReader(newBaseSchema), true, "<<<<<<< HEAD", ">>>>>>>>>>>>")
+ if err != nil {
+ return nil, status.Error(codes.Internal, fmt.Sprintf("failed to compute conflict schema, %v", err))
+ }
+ sb, err := io.ReadAll(conflictSchema.Result)
+ if err != nil {
+ return nil, status.Error(codes.Internal, fmt.Sprintf("failed to read conflict schema, %v", err))
+ }
+ conflictSchemaString := string(sb)
+ return &v1pb.RebaseBranchResponse{Result: &v1pb.RebaseBranchResponse_ConflictSchema{ConflictSchema: conflictSchemaString}}, nil
}
if mergedTarget == nil {
// TODO(zp): bug, this should not be no change.
diff --git a/go.mod b/go.mod
index 44b8f88eba..b97f84282f 100644
--- a/go.mod
+++ b/go.mod
@@ -20,6 +20,7 @@ require (
github.com/bytebase/snowsql-parser v0.0.0-20230706111031-cafd8faa2dc9
github.com/cenkalti/backoff/v4 v4.2.1
github.com/coreos/go-oidc v2.2.1+incompatible
+ github.com/epiclabs-io/diff3 v0.0.0-20181217103619-05282cece609
github.com/github/gh-ost v1.1.6
github.com/go-ego/gse v0.80.2
github.com/go-ldap/ldap/v3 v3.4.6
diff --git a/go.sum b/go.sum
index 1c7cdcb5ae..c119c2cc1e 100644
--- a/go.sum
+++ b/go.sum
@@ -273,6 +273,8 @@ github.com/envoyproxy/go-control-plane v0.11.1/go.mod h1:uhMcXKCQMEJHiAb0w+YGefQ
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA=
github.com/envoyproxy/protoc-gen-validate v1.0.2/go.mod h1:GpiZQP3dDbg4JouG/NNS7QWXpgx6x8QiMKdmN72jogE=
+github.com/epiclabs-io/diff3 v0.0.0-20181217103619-05282cece609 h1:KHcpmcC/8cnCDXDm6SaCTajWF/vyUbBE1ovA27xYYEY=
+github.com/epiclabs-io/diff3 v0.0.0-20181217103619-05282cece609/go.mod h1:tM499ZoH5jQRF3wlMnl59SJQwVYXIBdJRZa/K71p0IM=
github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw=
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=