go/libraries/doltcore/env/actions: commit.go: Error when attempting to create a commit with unresolved conflicts still in the working set.

This commit is contained in:
Aaron Son
2020-07-15 10:55:35 -07:00
parent 0d742ea707
commit edba809f4c
3 changed files with 60 additions and 0 deletions

View File

@@ -76,6 +76,48 @@ teardown() {
[[ "$output" =~ "| 0 " ]] || false
}
@test "dolt add fails on table with conflict" {
dolt checkout -b merge_branch
dolt SQL -q "INSERT INTO test1 values (0,1,1)"
dolt add test1
dolt commit -m "add pk 0 = 1,1 to test1"
dolt checkout master
dolt SQL -q "INSERT INTO test1 values (0,2,2)"
dolt add test1
dolt commit -m "add pk 0 = 2,2 to test1"
run dolt merge merge_branch
[ "$status" -eq 0 ]
[[ "$output" =~ "test1" ]] || false
run dolt add test1
[ "$status" -ne 0 ]
[[ "$output" =~ "not all tables merged" ]] || false
[[ "$output" =~ "test1" ]] || false
}
@test "dolt commit fails with unmerged tables in working set" {
dolt checkout -b merge_branch
dolt SQL -q "INSERT INTO test1 values (0,1,1)"
dolt add test1
dolt commit -m "add pk 0 = 1,1 to test1"
dolt checkout master
dolt SQL -q "INSERT INTO test1 values (0,2,2)"
dolt add test1
dolt commit -m "add pk 0 = 2,2 to test1"
run dolt merge merge_branch
[ "$status" -eq 0 ]
[[ "$output" =~ "test1" ]] || false
run dolt commit -m 'create a merge commit'
[ "$status" -ne 0 ]
[[ "$output" =~ "unresolved conflicts" ]] || false
[[ "$output" =~ "test1" ]] || false
}
@test "ff merge doesn't stomp working changes" {
dolt checkout -b merge_branch
dolt SQL -q "INSERT INTO test1 values (0,1,2)"

View File

@@ -181,6 +181,12 @@ func handleCommitErr(ctx context.Context, dEnv *env.DoltEnv, err error, usage cl
}
}
if actions.IsTblInConflict(err) {
inConflict := actions.GetTablesForError(err)
bdr := errhand.BuildDError(`tables %v have unresolved conflicts from the merge. resolve the conflicts before commiting`, inConflict)
return HandleVErrAndExitCode(bdr.Build(), usage)
}
verr := errhand.BuildDError("error: Failed to commit changes.").AddCause(err).Build()
return HandleVErrAndExitCode(verr, usage)
}

View File

@@ -88,6 +88,18 @@ func CommitStaged(ctx context.Context, dEnv *env.DoltEnv, props CommitStagedProp
var mergeCmSpec []*doltdb.CommitSpec
if dEnv.IsMergeActive() {
root, err := dEnv.WorkingRoot(ctx)
if err != nil {
return err
}
inConflict, err := root.TablesInConflict(ctx)
if err != nil {
return err
}
if len(inConflict) > 0 {
return NewTblInConflictError(inConflict)
}
spec, err := doltdb.NewCommitSpec(dEnv.RepoState.Merge.Commit)
if err != nil {