Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/cmd/dolt/commands/rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)`,
},
}
Expand Down
11 changes: 8 additions & 3 deletions go/libraries/doltcore/sqle/dprocedures/dolt_rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
29 changes: 28 additions & 1 deletion go/libraries/doltcore/sqle/enginetest/dolt_queries_rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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{
Expand Down
15 changes: 12 additions & 3 deletions integration-tests/bats/rebase.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Loading