Skip to content

Commit

Permalink
Merge pull request #8128 from dolthub/fulghum/bugfix
Browse files Browse the repository at this point in the history
Bug fix: `dolt_reset()` should commit the active transaction
  • Loading branch information
fulghum authored Jul 17, 2024
2 parents 8c43b2e + 4759351 commit 0ea32ea
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
4 changes: 3 additions & 1 deletion go/libraries/doltcore/sqle/dprocedures/dolt_reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go/libraries/doltcore/sqle/enginetest/dolt_engine_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
71 changes: 70 additions & 1 deletion go/libraries/doltcore/sqle/enginetest/dolt_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0ea32ea

Please sign in to comment.