diff --git a/go/cmd/dolt/commands/rebase.go b/go/cmd/dolt/commands/rebase.go index 536a751d0fb..34be0f73699 100644 --- a/go/cmd/dolt/commands/rebase.go +++ b/go/cmd/dolt/commands/rebase.go @@ -49,7 +49,7 @@ branch. For example, you can drop commits that contain debugging or test changes single commit, or reorder commits so that related changes are adjacent in the new commit history. `, Synopsis: []string{ - `(-i | --interactive) [--empty=drop|keep] {{.LessThan}}upstream{{.GreaterThan}}`, + `[-i | --interactive] [--empty=drop|keep] {{.LessThan}}upstream{{.GreaterThan}}`, `(--continue | --abort)`, }, } diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_rebase.go b/go/libraries/doltcore/sqle/dprocedures/dolt_rebase.go index 39b8aee8f9d..f8b9b3bf675 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_rebase.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_rebase.go @@ -180,9 +180,6 @@ func doDoltRebase(ctx *sql.Context, args []string) (int, string, error) { } else if apr.NArg() > 1 { return 1, "", fmt.Errorf("too many args") } - if !apr.Contains(cli.InteractiveFlag) { - return 1, "", fmt.Errorf("non-interactive rebases not currently supported") - } err = startRebase(ctx, apr.Arg(0), commitBecomesEmptyHandling, emptyCommitHandling) if err != nil { return 1, "", err @@ -193,6 +190,14 @@ func doDoltRebase(ctx *sql.Context, args []string) (int, string, error) { return 1, "", err } + if !apr.Contains(cli.InteractiveFlag) { + rebaseBranch, err := continueRebase(ctx) + if err != nil { + return 1, "", err + } + return 0, SuccessfulRebaseMessage + rebaseBranch, nil + } + return 0, fmt.Sprintf("interactive rebase started on branch %s; "+ "adjust the rebase plan in the dolt_rebase table, then continue rebasing by "+ "calling dolt_rebase('--continue')", currentBranch), nil diff --git a/go/libraries/doltcore/sqle/enginetest/dolt_queries_rebase.go b/go/libraries/doltcore/sqle/enginetest/dolt_queries_rebase.go index dc74569560a..401236f28c7 100644 --- a/go/libraries/doltcore/sqle/enginetest/dolt_queries_rebase.go +++ b/go/libraries/doltcore/sqle/enginetest/dolt_queries_rebase.go @@ -37,7 +37,7 @@ var DoltRebaseScriptTests = []queries.ScriptTest{ ExpectedErrStr: "no rebase in progress", }, { Query: "call dolt_rebase('main');", - ExpectedErrStr: "non-interactive rebases not currently supported", + ExpectedErrStr: "didn't identify any commits!", }, { Query: "call dolt_rebase('-i');", ExpectedErrStr: "not enough args", @@ -122,6 +122,33 @@ var DoltRebaseScriptTests = []queries.ScriptTest{ }, }, }, + { + Name: "dolt_rebase: non-interactive rebase successful", + SetUpScript: []string{ + "create table t (pk int primary key);", + "call dolt_commit('-Am', 'creating table t on main');", + "insert into t values (42);", + "call dolt_commit('-am', 'main commit with pk = 42');", + "call dolt_branch('feature', 'HEAD~1');", + "call dolt_checkout('feature');", + "insert into t values (1);", + "call dolt_commit('-am', 'feature commit 1');", + "insert into t values (2);", + "call dolt_commit('-am', 'feature commit 2');", + }, + Assertions: []queries.ScriptTestAssertion{ + { + Query: "call dolt_rebase('main');", + Expected: []sql.Row{{0, "Successfully rebased and updated refs/heads/feature"}}, + }, + { + Query: "select pk from t where pk = 42;", + Expected: []sql.Row{ + {42}, + }, + }, + }, + }, { Name: "dolt_rebase errors: rebase working branch already exists", SetUpScript: []string{ diff --git a/integration-tests/bats/rebase.bats b/integration-tests/bats/rebase.bats index b3f9ecc34ff..a3ab3329b47 100755 --- a/integration-tests/bats/rebase.bats +++ b/integration-tests/bats/rebase.bats @@ -48,10 +48,19 @@ setupCustomEditorScript() { [[ "$output" =~ "no rebase in progress" ]] || false } -@test "rebase: -i flag required" { +@test "rebase: non-interactive rebase works" { + run dolt sql -r csv -q "select * from dolt_branch_status('main', 'b1');" + [ "$status" -eq 0 ] + # main and b1 have diverged by 1 commit each + [[ "$output" =~ "b1,1,1" ]] || false + run dolt rebase b1 - [ "$status" -eq 1 ] - [[ "$output" =~ "non-interactive rebases not currently supported" ]] || false + [ "$status" -eq 0 ] + + # Main should be 1 ahead of b1 now + run dolt sql -r csv -q "select * from dolt_branch_status('main', 'b1');" + [ "$status" -eq 0 ] + [[ "$output" =~ "b1,0,1" ]] || false } @test "rebase: bad args" {