mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-22 02:50:04 -05:00
Creating an interface for fetching a remote DB as needed
This commit is contained in:
@@ -147,7 +147,7 @@ func pullHelper(ctx context.Context, dEnv *env.DoltEnv, pullSpec *env.PullSpec)
|
||||
return fmt.Errorf("fetch failed; %w", err)
|
||||
}
|
||||
|
||||
// Only merge iff branch is current branch and there is an upstream set (pullSpec.Branch is set to nil if there is no upstream)
|
||||
// Merge iff branch is current branch and there is an upstream set (pullSpec.Branch is set to nil if there is no upstream)
|
||||
if branchRef != pullSpec.Branch {
|
||||
continue
|
||||
}
|
||||
|
||||
+28
-2
@@ -23,6 +23,7 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/set"
|
||||
"github.com/dolthub/dolt/go/store/hash"
|
||||
)
|
||||
@@ -131,8 +132,8 @@ func DeleteBranch(ctx context.Context, dbData env.DbData, config *env.DoltCliCon
|
||||
return DeleteBranchOnDB(ctx, dbData, config, dref, opts)
|
||||
}
|
||||
|
||||
func DeleteBranchOnDB(ctx context.Context, dbData env.DbData, config *env.DoltCliConfig, dref ref.DoltRef, opts DeleteOptions) error {
|
||||
ddb := dbData.Ddb
|
||||
func DeleteBranchOnDB(ctx context.Context, dbdata env.DbData, config *env.DoltCliConfig, dref ref.DoltRef, opts DeleteOptions) error {
|
||||
ddb := dbdata.Ddb
|
||||
hasRef, err := ddb.HasRef(ctx, dref)
|
||||
|
||||
if err != nil {
|
||||
@@ -142,6 +143,31 @@ func DeleteBranchOnDB(ctx context.Context, dbData env.DbData, config *env.DoltCl
|
||||
}
|
||||
|
||||
if !opts.Force && !opts.Remote {
|
||||
// check to see if the branch is fully merged into its parent
|
||||
branch := dbdata.Rsr.CWBHeadRef()
|
||||
trackedBranches, err := dbdata.Rsr.GetBranches()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
trackedBranch, hasUpstream := trackedBranches[branch.GetPath()]
|
||||
if hasUpstream {
|
||||
remoteRef := trackedBranch.Merge.Ref
|
||||
|
||||
remotes, err := dbdata.Rsr.GetRemotes()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
remote, ok := remotes[remoteRef.GetPath()]
|
||||
if !ok {
|
||||
// TODO: skip error?
|
||||
return fmt.Errorf("remote %s not found", remoteRef.GetPath())
|
||||
}
|
||||
|
||||
sess := dsess.DSessFromSess(ctx.Session)
|
||||
remoteDB, err := remote.GetRemoteDB(ctx, config)
|
||||
}
|
||||
|
||||
ms, err := doltdb.NewCommitSpec(env.GetDefaultInitBranch(config))
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
+6
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/filesys"
|
||||
"github.com/dolthub/dolt/go/store/hash"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
type RepoStateReader interface {
|
||||
@@ -46,6 +47,11 @@ type RepoStateWriter interface {
|
||||
UpdateBranch(name string, new BranchConfig) error
|
||||
}
|
||||
|
||||
// RemoteDbProvider is an interface for getting a database from a remote
|
||||
type RemoteDbProvider interface {
|
||||
GetRemoteDB(ctx context.Context, format *types.NomsBinFormat, r Remote, withCaching bool) (*doltdb.DoltDB, error)
|
||||
}
|
||||
|
||||
type DbData struct {
|
||||
Ddb *doltdb.DoltDB
|
||||
Rsw RepoStateWriter
|
||||
|
||||
Reference in New Issue
Block a user