diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_reset.go b/go/libraries/doltcore/sqle/dprocedures/dolt_reset.go index fb9f288ec2c..2a183625a53 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_reset.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_reset.go @@ -114,7 +114,6 @@ func doDoltReset(ctx *sql.Context, args []string) (int, error) { if err != nil { return 1, err } - } else if apr.Contains(cli.SoftResetParam) { arg := "" if apr.NArg() > 1 { @@ -176,7 +175,10 @@ func doDoltReset(ctx *sql.Context, args []string) (int, error) { } } } + } + if err = commitTransaction(ctx, dSess, nil); err != nil { + return 1, err } return 0, nil diff --git a/go/libraries/doltcore/sqle/enginetest/dolt_engine_tests.go b/go/libraries/doltcore/sqle/enginetest/dolt_engine_tests.go index 2c389cbfde6..d46f79719dc 100755 --- a/go/libraries/doltcore/sqle/enginetest/dolt_engine_tests.go +++ b/go/libraries/doltcore/sqle/enginetest/dolt_engine_tests.go @@ -975,7 +975,7 @@ func RunDoltMergeArtifacts(t *testing.T, h DoltEnginetestHarness) { } func RunDoltResetTest(t *testing.T, h DoltEnginetestHarness) { - for _, script := range DoltReset { + for _, script := range DoltResetTestScripts { // dolt versioning conflicts with reset harness -- use new harness every time func() { h := h.NewHarness(t) diff --git a/go/libraries/doltcore/sqle/enginetest/dolt_queries.go b/go/libraries/doltcore/sqle/enginetest/dolt_queries.go index cc21a27e2f4..14a1031b58d 100644 --- a/go/libraries/doltcore/sqle/enginetest/dolt_queries.go +++ b/go/libraries/doltcore/sqle/enginetest/dolt_queries.go @@ -3559,7 +3559,7 @@ var DoltBranchScripts = []queries.ScriptTest{ }, } -var DoltReset = []queries.ScriptTest{ +var DoltResetTestScripts = []queries.ScriptTest{ { Name: "CALL DOLT_RESET('--hard') should reset the merge state after uncommitted merge", SetUpScript: []string{ @@ -3614,6 +3614,75 @@ var DoltReset = []queries.ScriptTest{ }, }, }, + { + Name: "dolt_reset('--hard') commits the active SQL transaction", + SetUpScript: []string{ + "create table t (pk int primary key);", + "insert into t values (1), (2);", + "call dolt_commit('-Am', 'creating table t');", + }, + Assertions: []queries.ScriptTestAssertion{ + { + Query: "start transaction;", + Expected: []sql.Row{}, + }, + { + Query: "call dolt_reset('--hard', 'HEAD~');", + Expected: []sql.Row{{0}}, + }, + { + // dolt_status should be empty after a hard reset + Query: "select * from dolt_status", + Expected: []sql.Row{}, + }, + }, + }, + { + Name: "dolt_reset('--soft') commits the active SQL transaction", + SetUpScript: []string{ + "create table t (pk int primary key);", + "insert into t values (1), (2);", + "call dolt_commit('-Am', 'creating table t');", + }, + Assertions: []queries.ScriptTestAssertion{ + { + Query: "start transaction;", + Expected: []sql.Row{}, + }, + { + Query: "call dolt_reset('--soft', 'HEAD~');", + Expected: []sql.Row{{0}}, + }, + { + // dolt_status should only show the unstaged table t being added + Query: "select * from dolt_status", + Expected: []sql.Row{{"t", false, "new table"}}, + }, + }, + }, + { + Name: "dolt_reset() commits the active SQL transaction", + SetUpScript: []string{ + "create table t (pk int primary key);", + "insert into t values (1), (2);", + "call dolt_commit('-Am', 'creating table t');", + }, + Assertions: []queries.ScriptTestAssertion{ + { + Query: "start transaction;", + Expected: []sql.Row{}, + }, + { + Query: "call dolt_reset('HEAD~');", + Expected: []sql.Row{{0}}, + }, + { + // dolt_status should only show the unstaged table t being added + Query: "select * from dolt_status", + Expected: []sql.Row{{"t", false, "new table"}}, + }, + }, + }, } func gcSetup() []string {