Skip to content

Commit

Permalink
Merge pull request #799 from liquidata-inc/aaron/dolt-no-merge-commit…
Browse files Browse the repository at this point in the history
…-with-conflicts

go/libraries/doltcore/env/actions: commit.go: Error when attempting to create a commit with unresolved conflicts still in the working set.
  • Loading branch information
Oscar Batori authored Jul 16, 2020
2 parents a89ac93 + edba809 commit 26fbd97
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
42 changes: 42 additions & 0 deletions bats/merge.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
6 changes: 6 additions & 0 deletions go/cmd/dolt/commands/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,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)
}
Expand Down
12 changes: 12 additions & 0 deletions go/libraries/doltcore/env/actions/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 26fbd97

Please sign in to comment.