Merge pull request #8128 from dolthub/fulghum/bugfix

Bug fix: `dolt_reset()` should commit the active transaction
This commit is contained in:
Jason Fulghum
2024-07-17 11:10:44 -07:00
committed by GitHub
3 changed files with 74 additions and 3 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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 {