mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-20 03:00:43 -05:00
implement force pull
This commit is contained in:
@@ -217,7 +217,7 @@ func CreatePullArgParser() *argparser.ArgParser {
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"remoteBranch", "The name of a branch on the specified remote to be merged into the current working set."})
|
||||
ap.SupportsFlag(SquashParam, "", "Merge changes to the working set without updating the commit history")
|
||||
ap.SupportsFlag(NoFFParam, "", "Create a merge commit even when the merge resolves as a fast-forward.")
|
||||
ap.SupportsFlag(ForceFlag, "f", "Ignore any foreign key warnings and proceed with the commit.")
|
||||
ap.SupportsFlag(ForceFlag, "f", "Update from the remote HEAD even if there are errors or the local branch has diverged.")
|
||||
ap.SupportsFlag(CommitFlag, "", "Perform the merge and commit the result. This is the default option, but can be overridden with the --no-commit flag. Note that this option does not affect fast-forward merges, which don't create a new merge commit, and if any merge conflicts or constraint violations are detected, no commit will be attempted.")
|
||||
ap.SupportsFlag(NoCommitFlag, "", "Perform the merge and stop just before creating a merge commit. Note this will not prevent a fast-forward merge; use the --no-ff arg together with the --no-commit arg to prevent both fast-forwards and merge commits.")
|
||||
ap.SupportsFlag(NoEditFlag, "", "Use an auto-generated commit message when creating a merge commit. The default for interactive CLI sessions is to open an editor.")
|
||||
|
||||
@@ -16,6 +16,7 @@ package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
@@ -160,7 +161,16 @@ func pullHelper(ctx context.Context, sqlCtx *sql.Context, queryist cli.Queryist,
|
||||
}
|
||||
|
||||
err = dEnv.DoltDB.FastForward(ctx, remoteTrackRef, srcDBCommit)
|
||||
if err != nil {
|
||||
if errors.Is(err, datas.ErrMergeNeeded) && pullSpec.Force {
|
||||
h, err := srcDBCommit.HashOf()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = dEnv.DoltDB.SetHead(ctx, branchRef, h)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("fetch failed; %w", err)
|
||||
}
|
||||
|
||||
@@ -178,7 +188,7 @@ func pullHelper(ctx context.Context, sqlCtx *sql.Context, queryist cli.Queryist,
|
||||
|
||||
name, email, configErr := env.GetNameAndEmail(dEnv.Config)
|
||||
// If the name and email aren't set we can set them to empty values for now. This is only valid for ff
|
||||
// merges which detect for later.
|
||||
// merges which we detect later.
|
||||
if configErr != nil {
|
||||
if pullSpec.Noff {
|
||||
return configErr
|
||||
|
||||
Vendored
+6
-1
@@ -406,7 +406,12 @@ type PullSpec struct {
|
||||
// NewPullSpec returns PullSpec object using arguments passed into this function, which are remoteName, remoteRefName,
|
||||
// squash, noff, noCommit, noEdit, refSpecs, force and remoteOnly. This function validates remote and gets remoteRef
|
||||
// for given remoteRefName; if it's not defined, it uses current branch to get its upstream branch if it exists.
|
||||
func NewPullSpec(_ context.Context, rsr RepoStateReader, remoteName, remoteRefName string, squash, noff, noCommit, noEdit, force, remoteOnly bool) (*PullSpec, error) {
|
||||
func NewPullSpec(
|
||||
_ context.Context,
|
||||
rsr RepoStateReader,
|
||||
remoteName, remoteRefName string,
|
||||
squash, noff, noCommit, noEdit, force, remoteOnly bool,
|
||||
) (*PullSpec, error) {
|
||||
refSpecs, err := GetRefSpecs(rsr, remoteName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/dolthub/dolt/go/store/datas"
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/cli"
|
||||
@@ -129,7 +130,16 @@ func doDoltPull(ctx *sql.Context, args []string) (int, int, error) {
|
||||
|
||||
// TODO: this could be replaced with a canFF check to test for error
|
||||
err = dbData.Ddb.FastForward(ctx, remoteTrackRef, srcDBCommit)
|
||||
if err != nil {
|
||||
if errors.Is(err, datas.ErrMergeNeeded) && pullSpec.Force {
|
||||
h, err := srcDBCommit.HashOf()
|
||||
if err != nil {
|
||||
return noConflictsOrViolations, threeWayMerge, err
|
||||
}
|
||||
err = dbData.Ddb.SetHead(ctx, branchRef, h)
|
||||
if err != nil {
|
||||
return noConflictsOrViolations, threeWayMerge, err
|
||||
}
|
||||
} else if err != nil {
|
||||
return noConflictsOrViolations, threeWayMerge, fmt.Errorf("fetch failed; %w", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user