checkout proc startpoint (#3557)

* checkout proc startpoint

* zach comments
This commit is contained in:
Maximilian Hoffman
2022-06-07 10:31:26 -07:00
committed by GitHub
parent 0623d8a308
commit 1f39d77f6e
2 changed files with 35 additions and 0 deletions

View File

@@ -78,6 +78,8 @@ func DoDoltCheckout(ctx *sql.Context, args []string) (int, error) {
if newBranch, newBranchOk := apr.GetValue(cli.CheckoutCoBranch); newBranchOk {
if len(newBranch) == 0 {
err = errors.New("error: cannot checkout empty string")
} else if len(apr.Args) > 0 {
err = checkoutNewBranch(ctx, dbName, dbData, roots, newBranch, apr.Arg(0))
} else {
err = checkoutNewBranch(ctx, dbName, dbData, roots, newBranch, "")
}

View File

@@ -1433,6 +1433,39 @@ var DoltBranchScripts = []queries.ScriptTest{
},
},
},
{
Name: "Create branch from startpoint",
SetUpScript: []string{
"create table a (x int)",
"set @commit1 = (select DOLT_COMMIT('-am', 'add table a'));",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "show tables",
Expected: []sql.Row{{"a"}, {"myview"}},
},
{
Query: "CALL DOLT_CHECKOUT('-b', 'newBranch', 'head~1')",
Expected: []sql.Row{{0}},
},
{
Query: "show tables",
Expected: []sql.Row{{"myview"}},
},
{
Query: "CALL DOLT_CHECKOUT('-b', 'newBranch2', @commit1)",
Expected: []sql.Row{{0}},
},
{
Query: "show tables",
Expected: []sql.Row{{"a"}, {"myview"}},
},
{
Query: "CALL DOLT_CHECKOUT('-b', 'otherBranch', 'unknownCommit')",
ExpectedErrStr: "fatal: 'unknownCommit' is not a commit and a branch 'otherBranch' cannot be created from it",
},
},
},
}
var DoltReset = []queries.ScriptTest{