mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-06 11:20:30 -05:00
Allow running git pull if the only changes are to ignored tables.
This commit is contained in:
+5
-5
@@ -492,12 +492,12 @@ func CheckoutWouldStompWorkingSetChanges(ctx context.Context, sourceRoots, destR
|
||||
|
||||
// In some cases, a working set differs from its head only by the feature version.
|
||||
// If this is the case, moving the working set is safe.
|
||||
modifiedSourceRoots, err := clearFeatureVersion(ctx, sourceRoots)
|
||||
modifiedSourceRoots, err := ClearFeatureVersion(ctx, sourceRoots)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
|
||||
modifiedDestRoots, err := clearFeatureVersion(ctx, destRoots)
|
||||
modifiedDestRoots, err := ClearFeatureVersion(ctx, destRoots)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
@@ -521,10 +521,10 @@ func doRootsHaveIncompatibleChanges(sourceRoots, destRoots doltdb.Roots) bool {
|
||||
return sourceHasChanges && destHasChanges && (sourceWorkingHash != destWorkingHash || sourceStagedHash != destStagedHash)
|
||||
}
|
||||
|
||||
// clearFeatureVersion creates a new version of the provided roots where all three roots have the same
|
||||
// ClearFeatureVersion creates a new version of the provided roots where all three roots have the same
|
||||
// feature version. By hashing these new roots, we can easily determine whether the roots differ only by
|
||||
// their feature version.
|
||||
func clearFeatureVersion(ctx context.Context, roots doltdb.Roots) (doltdb.Roots, error) {
|
||||
func ClearFeatureVersion(ctx context.Context, roots doltdb.Roots) (doltdb.Roots, error) {
|
||||
currentBranchFeatureVersion, _, err := roots.Head.GetFeatureVersion(ctx)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
@@ -551,7 +551,7 @@ func clearFeatureVersion(ctx context.Context, roots doltdb.Roots) (doltdb.Roots,
|
||||
// the working and staged roots are identical. This function will ignore any difference in feature
|
||||
// versions between the root values.
|
||||
func RootHasUncommittedChanges(roots doltdb.Roots) (hasChanges bool, workingHash hash.Hash, stagedHash hash.Hash, err error) {
|
||||
roots, err = clearFeatureVersion(context.Background(), roots)
|
||||
roots, err = ClearFeatureVersion(context.Background(), roots)
|
||||
if err != nil {
|
||||
return false, hash.Hash{}, hash.Hash{}, err
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/diff"
|
||||
"sync"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
@@ -192,11 +193,33 @@ func doDoltPull(ctx *sql.Context, args []string) (int, int, string, error) {
|
||||
return noConflictsOrViolations, threeWayMerge, "", err
|
||||
}
|
||||
|
||||
uncommittedChanges, _, _, err := actions.RootHasUncommittedChanges(roots)
|
||||
roots, err = actions.ClearFeatureVersion(context.Background(), roots)
|
||||
if err != nil {
|
||||
return noConflictsOrViolations, threeWayMerge, "", err
|
||||
}
|
||||
if uncommittedChanges {
|
||||
|
||||
headHash, err := roots.Head.HashOf()
|
||||
if err != nil {
|
||||
return noConflictsOrViolations, threeWayMerge, "", err
|
||||
}
|
||||
|
||||
stagedHash, err := roots.Staged.HashOf()
|
||||
if err != nil {
|
||||
return noConflictsOrViolations, threeWayMerge, "", err
|
||||
}
|
||||
|
||||
if headHash != stagedHash {
|
||||
return noConflictsOrViolations, threeWayMerge, "", ErrUncommittedChanges.New()
|
||||
}
|
||||
|
||||
// We allow changes to ignored tables. If this causes a conflict because the remote also modified these tables,
|
||||
// we will detect that during the pull.
|
||||
workingSetClean, err := diff.WorkingSetContainsOnlyIgnoredTables(ctx, roots)
|
||||
if err != nil {
|
||||
return noConflictsOrViolations, threeWayMerge, "", err
|
||||
}
|
||||
|
||||
if !workingSetClean {
|
||||
return noConflictsOrViolations, threeWayMerge, "", ErrUncommittedChanges.New()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user