mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-08 16:16:45 -06:00
Merge pull request #547 from liquidata-inc/km/doc-checkout-bug
Km/doc checkout bug
This commit is contained in:
@@ -479,7 +479,7 @@ SQL
|
||||
[[ "$output" =~ "This is a repository level README" ]] || false
|
||||
}
|
||||
|
||||
@test "dolt checkout <branch> should save docs to the file system, leaving any untacked files" {
|
||||
@test "dolt checkout <branch> should save docs to the file system, leaving any untracked files" {
|
||||
dolt add LICENSE.md
|
||||
dolt commit -m "license commit"
|
||||
dolt checkout -b test-branch
|
||||
@@ -507,6 +507,28 @@ SQL
|
||||
[[ "$output" =~ "new-license" ]] || false
|
||||
}
|
||||
|
||||
@test "dolt checkout <branch>, assuming no conflicts, should preserve changes in the working set (on the filesystem)" {
|
||||
dolt add LICENSE.md README.md
|
||||
dolt commit -m "initial license and readme commit"
|
||||
echo updated-readme > README.md
|
||||
dolt checkout -b test-branch
|
||||
run dolt status
|
||||
[[ "$output" =~ "README.md" ]] || false
|
||||
run cat README.md
|
||||
[[ "$output" =~ "updated-readme" ]] || false
|
||||
run cat LICENSE.md
|
||||
[[ "$output" =~ "This is a repository level LICENSE" ]] || false
|
||||
|
||||
dolt add README.md
|
||||
dolt commit -m "commit of updated-readme"
|
||||
echo "another new README!" > README.md
|
||||
dolt checkout master
|
||||
run dolt status
|
||||
[[ "$output" =~ "README.md" ]] || false
|
||||
run cat README.md
|
||||
[[ "$output" =~ "another new README!" ]] || false
|
||||
}
|
||||
|
||||
@test "dolt diff shows diffs between working root and file system docs" {
|
||||
# 2 added docs
|
||||
echo "testing readme" > README.md
|
||||
|
||||
@@ -115,6 +115,7 @@ teardown() {
|
||||
dolt push test-remote master
|
||||
|
||||
cd dolt-repo-clones/test-repo
|
||||
echo "this text should remain after pull :p" > README.md
|
||||
run dolt pull
|
||||
[[ "$output" =~ "Updating" ]] || false
|
||||
run dolt log
|
||||
@@ -125,7 +126,7 @@ teardown() {
|
||||
[[ "$output" =~ "updated-license" ]] || false
|
||||
run cat README.md
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "readme-text" ]] || false
|
||||
[[ "$output" =~ "this text should remain after pull :p" ]] || false
|
||||
}
|
||||
|
||||
@test "clone a remote" {
|
||||
|
||||
@@ -257,6 +257,11 @@ func executeFFMerge(ctx context.Context, dEnv *env.DoltEnv, cm2 *doltdb.Commit,
|
||||
}
|
||||
}
|
||||
|
||||
unstagedDocs, err := actions.GetUnstagedDocs(ctx, dEnv)
|
||||
if err != nil {
|
||||
return errhand.BuildDError("error: unable to determine unstaged docs").AddCause(err).Build()
|
||||
}
|
||||
|
||||
err = dEnv.DoltDB.FastForward(ctx, dEnv.RepoState.CWBHeadRef(), cm2)
|
||||
|
||||
if err != nil {
|
||||
@@ -278,7 +283,7 @@ and take the hash for your current branch and use it for the value for "staged"
|
||||
AddCause(err).Build()
|
||||
}
|
||||
|
||||
err = actions.SaveTrackedDocsFromWorking(ctx, dEnv)
|
||||
err = actions.SaveDocsFromWorkingExcludingFSChanges(ctx, dEnv, unstagedDocs)
|
||||
if err != nil {
|
||||
return errhand.BuildDError("error: failed to update docs to the new working root").AddCause(err).Build()
|
||||
}
|
||||
@@ -321,6 +326,11 @@ func executeMerge(ctx context.Context, dEnv *env.DoltEnv, cm1, cm2 *doltdb.Commi
|
||||
return errhand.BuildDError("Unable to update the repo state").AddCause(err).Build()
|
||||
}
|
||||
|
||||
unstagedDocs, err := actions.GetUnstagedDocs(ctx, dEnv)
|
||||
if err != nil {
|
||||
return errhand.BuildDError("error: failed to determine unstaged docs").AddCause(err).Build()
|
||||
}
|
||||
|
||||
verr := UpdateWorkingWithVErr(dEnv, workingRoot)
|
||||
|
||||
if verr == nil {
|
||||
@@ -329,7 +339,7 @@ func executeMerge(ctx context.Context, dEnv *env.DoltEnv, cm1, cm2 *doltdb.Commi
|
||||
if hasConflicts {
|
||||
cli.Println("Automatic merge failed; fix conflicts and then commit the result.")
|
||||
} else {
|
||||
err = actions.SaveTrackedDocsFromWorking(ctx, dEnv)
|
||||
err = actions.SaveDocsFromWorkingExcludingFSChanges(ctx, dEnv, unstagedDocs)
|
||||
if err != nil {
|
||||
return errhand.BuildDError("error: failed to update docs to the new working root").AddCause(err).Build()
|
||||
}
|
||||
|
||||
10
go/libraries/doltcore/env/actions/branch.go
vendored
10
go/libraries/doltcore/env/actions/branch.go
vendored
@@ -18,10 +18,9 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/ref"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/set"
|
||||
"github.com/liquidata-inc/dolt/go/store/hash"
|
||||
"github.com/liquidata-inc/dolt/go/store/types"
|
||||
@@ -246,6 +245,11 @@ func CheckoutBranch(ctx context.Context, dEnv *env.DoltEnv, brName string) error
|
||||
return err
|
||||
}
|
||||
|
||||
unstagedDocs, err := GetUnstagedDocs(ctx, dEnv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dEnv.RepoState.Head = ref.MarshalableRef{Ref: dref}
|
||||
dEnv.RepoState.Working = wrkHash.String()
|
||||
dEnv.RepoState.Staged = stgHash.String()
|
||||
@@ -256,7 +260,7 @@ func CheckoutBranch(ctx context.Context, dEnv *env.DoltEnv, brName string) error
|
||||
return err
|
||||
}
|
||||
|
||||
return SaveTrackedDocsFromWorking(ctx, dEnv)
|
||||
return SaveDocsFromWorkingExcludingFSChanges(ctx, dEnv, unstagedDocs)
|
||||
}
|
||||
|
||||
var emptyHash = hash.Hash{}
|
||||
|
||||
41
go/libraries/doltcore/env/actions/docs.go
vendored
41
go/libraries/doltcore/env/actions/docs.go
vendored
@@ -140,3 +140,44 @@ func getUpdatedWorkingAndStagedWithDocs(ctx context.Context, dEnv *env.DoltEnv,
|
||||
|
||||
return currRoot, stgRoot, nil
|
||||
}
|
||||
|
||||
// GetUnstagedDocs retrieves the unstaged docs (docs from the filesystem).
|
||||
func GetUnstagedDocs(ctx context.Context, dEnv *env.DoltEnv) (env.Docs, error) {
|
||||
_, unstagedDocDiffs, err := diff.GetDocDiffs(ctx, dEnv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
unstagedDocs := env.Docs{}
|
||||
for _, docName := range unstagedDocDiffs.Docs {
|
||||
docDetail, err := dEnv.GetOneDocDetail(docName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
unstagedDocs = append(unstagedDocs, docDetail)
|
||||
}
|
||||
return unstagedDocs, nil
|
||||
}
|
||||
|
||||
// SaveDocsFromWorkingExcludingFSChanges saves docs from the working root to the filesystem, and does not overwrite changes to docs on the FS.
|
||||
// Intended to be called after checking that no conflicts exist (during a checkout or merge, i.e.).
|
||||
func SaveDocsFromWorkingExcludingFSChanges(ctx context.Context, dEnv *env.DoltEnv, docsToExclude env.Docs) error {
|
||||
workingRoot, err := dEnv.WorkingRoot(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var docsToSave env.Docs
|
||||
if len(docsToExclude) > 0 {
|
||||
for _, doc := range dEnv.Docs {
|
||||
for _, excludedDoc := range docsToExclude {
|
||||
if doc.DocPk != excludedDoc.DocPk {
|
||||
docsToSave = append(docsToSave, doc)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
docsToSave = dEnv.Docs
|
||||
}
|
||||
|
||||
return SaveTrackedDocs(ctx, dEnv, workingRoot, workingRoot, docsToSave)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user