github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/libraries/doltcore/sqle/enginetest/dolt_queries_rebase.go (about)

     1  // Copyright 2022 Dolthub, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package enginetest
    16  
    17  import (
    18  	"github.com/dolthub/go-mysql-server/enginetest/queries"
    19  	"github.com/dolthub/go-mysql-server/sql"
    20  	"github.com/dolthub/go-mysql-server/sql/plan"
    21  	gmstypes "github.com/dolthub/go-mysql-server/sql/types"
    22  
    23  	"github.com/dolthub/dolt/go/libraries/doltcore/rebase"
    24  	"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dprocedures"
    25  )
    26  
    27  var DoltRebaseScriptTests = []queries.ScriptTest{
    28  	{
    29  		Name:        "dolt_rebase errors: basic errors",
    30  		SetUpScript: []string{},
    31  		Assertions: []queries.ScriptTestAssertion{
    32  			{
    33  				Query:          "call dolt_rebase('--abort');",
    34  				ExpectedErrStr: "no rebase in progress",
    35  			}, {
    36  				Query:          "call dolt_rebase('--continue');",
    37  				ExpectedErrStr: "no rebase in progress",
    38  			}, {
    39  				Query:          "call dolt_rebase('main');",
    40  				ExpectedErrStr: "non-interactive rebases not currently supported",
    41  			}, {
    42  				Query:          "call dolt_rebase('-i');",
    43  				ExpectedErrStr: "not enough args",
    44  			}, {
    45  				Query:          "call dolt_rebase('-i', 'main1', 'main2');",
    46  				ExpectedErrStr: "rebase takes at most one positional argument.",
    47  			}, {
    48  				Query:          "call dolt_rebase('--abrot');",
    49  				ExpectedErrStr: "error: unknown option `abrot'",
    50  			}, {
    51  				Query:          "call dolt_rebase('-i', 'doesnotexist');",
    52  				ExpectedErrStr: "branch not found: doesnotexist",
    53  			},
    54  		},
    55  	},
    56  	{
    57  		Name: "dolt_rebase errors: working set not clean",
    58  		SetUpScript: []string{
    59  			"create table t (pk int primary key);",
    60  			"call dolt_commit('-Am', 'creating table t');",
    61  			"insert into t values (0);",
    62  		},
    63  		Assertions: []queries.ScriptTestAssertion{
    64  			{
    65  				Query:          "call dolt_rebase('-i', 'main');",
    66  				ExpectedErrStr: dprocedures.ErrRebaseUncommittedChanges.Error(),
    67  			},
    68  			{
    69  				Query:    "call dolt_add('t');",
    70  				Expected: []sql.Row{{0}},
    71  			},
    72  			{
    73  				Query:          "call dolt_rebase('-i', 'main');",
    74  				ExpectedErrStr: dprocedures.ErrRebaseUncommittedChanges.Error(),
    75  			},
    76  		},
    77  	},
    78  	{
    79  		SkipPrepared: true,
    80  		Name:         "dolt_rebase errors: no database selected",
    81  		SetUpScript: []string{
    82  			"create database temp;",
    83  			"use temp;",
    84  			"drop database temp;",
    85  		},
    86  		Assertions: []queries.ScriptTestAssertion{
    87  			{
    88  				Query:    "select database();",
    89  				Expected: []sql.Row{{nil}},
    90  			},
    91  			{
    92  				Query:          "call dolt_rebase('-i', 'main');",
    93  				ExpectedErrStr: "no database selected",
    94  			},
    95  		},
    96  	},
    97  	{
    98  		Name: "dolt_rebase errors: active merge, cherry-pick, or rebase",
    99  		SetUpScript: []string{
   100  			"create table t (pk int primary key, col1 varchar(100));",
   101  			"call dolt_commit('-Am', 'creating table t');",
   102  			"call dolt_branch('branch1');",
   103  			"insert into t values (0, 'zero');",
   104  			"call dolt_commit('-am', 'inserting row 0');",
   105  
   106  			"call dolt_checkout('branch1');",
   107  			"insert into t values (0, 'nada');",
   108  			"call dolt_commit('-am', 'inserting row 0');",
   109  
   110  			"set @@autocommit=0;",
   111  		},
   112  		Assertions: []queries.ScriptTestAssertion{
   113  			{
   114  				// Merging main creates a conflict, so we're in an active
   115  				// merge until we resolve.
   116  				Query:    "call dolt_merge('main');",
   117  				Expected: []sql.Row{{"", 0, 1, "conflicts found"}},
   118  			},
   119  			{
   120  				Query:          "call dolt_rebase('-i', 'main');",
   121  				ExpectedErrStr: "unable to start rebase while a merge is in progress – abort the current merge before proceeding",
   122  			},
   123  		},
   124  	},
   125  	{
   126  		Name: "dolt_rebase errors: rebase working branch already exists",
   127  		SetUpScript: []string{
   128  			"create table t (pk int primary key);",
   129  			"call dolt_commit('-Am', 'creating table t');",
   130  			"call dolt_branch('branch1');",
   131  			"call dolt_branch('dolt_rebase_branch1');",
   132  
   133  			"insert into t values (0);",
   134  			"call dolt_commit('-am', 'inserting row 0');",
   135  
   136  			"call dolt_checkout('branch1');",
   137  			"insert into t values (1);",
   138  			"call dolt_commit('-am', 'inserting row 1');",
   139  			"insert into t values (10);",
   140  			"call dolt_commit('-am', 'inserting row 10');",
   141  		},
   142  		Assertions: []queries.ScriptTestAssertion{
   143  			{
   144  				Query:          "call dolt_rebase('-i', 'main');",
   145  				ExpectedErrStr: "fatal: A branch named 'dolt_rebase_branch1' already exists.",
   146  			},
   147  		},
   148  	},
   149  	{
   150  		Name: "dolt_rebase errors: invalid rebase plans",
   151  		SetUpScript: []string{
   152  			"create table t (pk int primary key);",
   153  			"call dolt_commit('-Am', 'creating table t');",
   154  			"call dolt_branch('branch1');",
   155  
   156  			"insert into t values (0);",
   157  			"call dolt_commit('-am', 'inserting row 0');",
   158  
   159  			"call dolt_checkout('branch1');",
   160  			"insert into t values (1);",
   161  			"call dolt_commit('-am', 'inserting row 1');",
   162  			"insert into t values (10);",
   163  			"call dolt_commit('-am', 'inserting row 10');",
   164  		},
   165  		Assertions: []queries.ScriptTestAssertion{
   166  			{
   167  				Query: "call dolt_rebase('-i', 'main');",
   168  				Expected: []sql.Row{{0, "interactive rebase started on branch dolt_rebase_branch1; " +
   169  					"adjust the rebase plan in the dolt_rebase table, then " +
   170  					"continue rebasing by calling dolt_rebase('--continue')"}},
   171  			},
   172  			{
   173  				Query:          "update dolt_rebase set rebase_order=1.0 where rebase_order=2.0;",
   174  				ExpectedErrStr: "duplicate primary key given: [1]",
   175  			},
   176  			{
   177  				Query: "update dolt_rebase set action='squash';",
   178  				Expected: []sql.Row{{gmstypes.OkResult{
   179  					RowsAffected: 2,
   180  					InsertID:     0,
   181  					Info: plan.UpdateInfo{
   182  						Matched:  2,
   183  						Updated:  2,
   184  						Warnings: 0,
   185  					},
   186  				}}},
   187  			},
   188  			{
   189  				Query:          "call dolt_rebase('--continue');",
   190  				ExpectedErrStr: rebase.ErrInvalidRebasePlanSquashFixupWithoutPick.Error(),
   191  			},
   192  			{
   193  				Query: "update dolt_rebase set action='drop' where rebase_order=1;",
   194  				Expected: []sql.Row{{gmstypes.OkResult{
   195  					RowsAffected: 1,
   196  					InsertID:     0,
   197  					Info: plan.UpdateInfo{
   198  						Matched:  1,
   199  						Updated:  1,
   200  						Warnings: 0,
   201  					},
   202  				}}},
   203  			},
   204  			{
   205  				Query:          "call dolt_rebase('--continue');",
   206  				ExpectedErrStr: rebase.ErrInvalidRebasePlanSquashFixupWithoutPick.Error(),
   207  			},
   208  			{
   209  				Query: "update dolt_rebase set action='pick', commit_hash='doesnotexist' where rebase_order=1;",
   210  				Expected: []sql.Row{{gmstypes.OkResult{
   211  					RowsAffected: 1,
   212  					InsertID:     0,
   213  					Info: plan.UpdateInfo{
   214  						Matched:  1,
   215  						Updated:  1,
   216  						Warnings: 0,
   217  					},
   218  				}}},
   219  			},
   220  			{
   221  				Query:          "call dolt_rebase('--continue');",
   222  				ExpectedErrStr: "invalid commit hash: doesnotexist",
   223  			},
   224  			{
   225  				Query: "update dolt_rebase set commit_hash='0123456789abcdef0123456789abcdef' where rebase_order=1;",
   226  				Expected: []sql.Row{{gmstypes.OkResult{
   227  					RowsAffected: 1,
   228  					InsertID:     0,
   229  					Info: plan.UpdateInfo{
   230  						Matched:  1,
   231  						Updated:  1,
   232  						Warnings: 0,
   233  					},
   234  				}}},
   235  			},
   236  			{
   237  				Query:          "call dolt_rebase('--continue');",
   238  				ExpectedErrStr: "unable to resolve commit hash 0123456789abcdef0123456789abcdef: target commit not found",
   239  			},
   240  		},
   241  	},
   242  	{
   243  		Name: "dolt_rebase: no commits to rebase",
   244  		SetUpScript: []string{
   245  			"create table t (pk int primary key);",
   246  			"call dolt_commit('-Am', 'creating table t');",
   247  			"call dolt_branch('branch1');",
   248  
   249  			"insert into t values (0);",
   250  			"call dolt_commit('-am', 'inserting row 0');",
   251  
   252  			"call dolt_checkout('branch1');",
   253  			"insert into t values (1);",
   254  			"call dolt_commit('-am', 'inserting row 1');",
   255  			"insert into t values (10);",
   256  			"call dolt_commit('-am', 'inserting row 10');",
   257  			"insert into t values (100);",
   258  			"call dolt_commit('-am', 'inserting row 100');",
   259  			"insert into t values (1000);",
   260  			"call dolt_commit('-am', 'inserting row 1000');",
   261  			"insert into t values (10000);",
   262  			"call dolt_commit('-am', 'inserting row 10000');",
   263  			"insert into t values (100000);",
   264  			"call dolt_commit('-am', 'inserting row 100000');",
   265  		},
   266  		Assertions: []queries.ScriptTestAssertion{
   267  			{
   268  				Query:    "select active_branch();",
   269  				Expected: []sql.Row{{"branch1"}},
   270  			},
   271  			{
   272  				Query:          "call dolt_rebase('-i', 'HEAD');",
   273  				ExpectedErrStr: "didn't identify any commits!",
   274  			},
   275  			{
   276  				// if the rebase doesn't start, then we should remain on the original branch
   277  				Query:    "select active_branch();",
   278  				Expected: []sql.Row{{"branch1"}},
   279  			},
   280  			{
   281  				// and the rebase working branch shouldn't be present
   282  				Query:    "select * from dolt_branches where name='dolt_rebase_branch1';",
   283  				Expected: []sql.Row{},
   284  			},
   285  		},
   286  	},
   287  	{
   288  		Name: "dolt_rebase: abort properly cleans up",
   289  		SetUpScript: []string{
   290  			"create table t (pk int primary key);",
   291  			"call dolt_commit('-Am', 'creating table t');",
   292  			"call dolt_branch('branch1');",
   293  
   294  			"insert into t values (0);",
   295  			"call dolt_commit('-am', 'inserting row 0');",
   296  
   297  			"call dolt_checkout('branch1');",
   298  			"insert into t values (1);",
   299  			"call dolt_commit('-am', 'inserting row 1');",
   300  			"insert into t values (10);",
   301  			"call dolt_commit('-am', 'inserting row 10');",
   302  			"insert into t values (100);",
   303  			"call dolt_commit('-am', 'inserting row 100');",
   304  			"insert into t values (1000);",
   305  			"call dolt_commit('-am', 'inserting row 1000');",
   306  			"insert into t values (10000);",
   307  			"call dolt_commit('-am', 'inserting row 10000');",
   308  			"insert into t values (100000);",
   309  			"call dolt_commit('-am', 'inserting row 100000');",
   310  		},
   311  		Assertions: []queries.ScriptTestAssertion{
   312  			{
   313  				Query: "call dolt_rebase('-i', 'main');",
   314  				Expected: []sql.Row{{0, "interactive rebase started on branch dolt_rebase_branch1; " +
   315  					"adjust the rebase plan in the dolt_rebase table, then " +
   316  					"continue rebasing by calling dolt_rebase('--continue')"}},
   317  			},
   318  			{
   319  				Query:    "select active_branch();",
   320  				Expected: []sql.Row{{"dolt_rebase_branch1"}},
   321  			},
   322  			{
   323  				Query:    "call dolt_rebase('--abort');",
   324  				Expected: []sql.Row{{0, "Interactive rebase aborted"}},
   325  			},
   326  			{
   327  				Query:    "select active_branch();",
   328  				Expected: []sql.Row{{"branch1"}},
   329  			},
   330  			{
   331  				Query:    "select name from dolt_branches",
   332  				Expected: []sql.Row{{"main"}, {"branch1"}},
   333  			},
   334  		},
   335  	},
   336  	{
   337  		Name: "dolt_rebase: rebase plan using every action",
   338  		SetUpScript: []string{
   339  			"create table t (pk int primary key);",
   340  			"call dolt_commit('-Am', 'creating table t');",
   341  			"call dolt_branch('branch1');",
   342  
   343  			"insert into t values (0);",
   344  			"call dolt_commit('-am', 'inserting row 0');",
   345  
   346  			"call dolt_checkout('branch1');",
   347  			"insert into t values (1);",
   348  			"call dolt_commit('-am', 'inserting row 1');",
   349  			"insert into t values (10);",
   350  			"call dolt_commit('-am', 'inserting row 10');",
   351  			"insert into t values (100);",
   352  			"call dolt_commit('-am', 'inserting row 100');",
   353  			"insert into t values (1000);",
   354  			"call dolt_commit('-am', 'inserting row 1000');",
   355  			"insert into t values (10000);",
   356  			"call dolt_commit('-am', 'inserting row 10000');",
   357  			"insert into t values (100000);",
   358  			"call dolt_commit('-am', 'inserting row 100000');",
   359  		},
   360  		Assertions: []queries.ScriptTestAssertion{
   361  			{
   362  				Query: "call dolt_rebase('-i', 'main');",
   363  				Expected: []sql.Row{{0, "interactive rebase started on branch dolt_rebase_branch1; " +
   364  					"adjust the rebase plan in the dolt_rebase table, then " +
   365  					"continue rebasing by calling dolt_rebase('--continue')"}},
   366  			},
   367  			{
   368  				Query: "select * from dolt_rebase order by rebase_order ASC;",
   369  				Expected: []sql.Row{
   370  					{"1", "pick", doltCommit, "inserting row 1"},
   371  					{"2", "pick", doltCommit, "inserting row 10"},
   372  					{"3", "pick", doltCommit, "inserting row 100"},
   373  					{"4", "pick", doltCommit, "inserting row 1000"},
   374  					{"5", "pick", doltCommit, "inserting row 10000"},
   375  					{"6", "pick", doltCommit, "inserting row 100000"},
   376  				},
   377  			},
   378  			{
   379  				Query: "update dolt_rebase set rebase_order=6.1 where rebase_order=6;",
   380  				Expected: []sql.Row{{gmstypes.OkResult{RowsAffected: uint64(1), Info: plan.UpdateInfo{
   381  					Matched: 1,
   382  					Updated: 1,
   383  				}}}},
   384  			},
   385  			{
   386  				Query: "update dolt_rebase set action='squash' where rebase_order in (2, 3);",
   387  				Expected: []sql.Row{{gmstypes.OkResult{RowsAffected: uint64(2), Info: plan.UpdateInfo{
   388  					Matched: 2,
   389  					Updated: 2,
   390  				}}}},
   391  			},
   392  			{
   393  				Query: "update dolt_rebase set action='drop' where rebase_order = 4;",
   394  				Expected: []sql.Row{{gmstypes.OkResult{RowsAffected: uint64(1), Info: plan.UpdateInfo{
   395  					Matched: 1,
   396  					Updated: 1,
   397  				}}}},
   398  			},
   399  			{
   400  				Query: "update dolt_rebase set action='reword', commit_message='reworded!' where rebase_order = 5;",
   401  				Expected: []sql.Row{{gmstypes.OkResult{RowsAffected: uint64(1), Info: plan.UpdateInfo{
   402  					Matched: 1,
   403  					Updated: 1,
   404  				}}}},
   405  			},
   406  			{
   407  				Query: "update dolt_rebase set action='fixup' where rebase_order = 6.10;",
   408  				Expected: []sql.Row{{gmstypes.OkResult{RowsAffected: uint64(1), Info: plan.UpdateInfo{
   409  					Matched: 1,
   410  					Updated: 1,
   411  				}}}},
   412  			},
   413  			{
   414  				Query:    "call dolt_rebase('--continue');",
   415  				Expected: []sql.Row{{0, "Successfully rebased and updated refs/heads/branch1"}},
   416  			},
   417  			{
   418  				// When rebase completes, rebase status should be cleared
   419  				Query:          "call dolt_rebase('--continue');",
   420  				ExpectedErrStr: "no rebase in progress",
   421  			},
   422  			{
   423  				// The dolt_rebase table is gone after rebasing completes
   424  				Query:          "select * from dolt_rebase;",
   425  				ExpectedErrStr: "table not found: dolt_rebase",
   426  			},
   427  			{
   428  				// The working branch for the rebase is deleted after rebasing completes
   429  				Query:    "select name from dolt_branches",
   430  				Expected: []sql.Row{{"main"}, {"branch1"}},
   431  			},
   432  			{
   433  				// Assert that the commit history is now composed of different commits
   434  				Query: "select message from dolt_log order by date desc;",
   435  				Expected: []sql.Row{
   436  					{"reworded!"},
   437  					{"inserting row 1\n\ninserting row 10\n\ninserting row 100"},
   438  					{"inserting row 0"},
   439  					{"creating table t"},
   440  					{"Initialize data repository"}},
   441  			},
   442  			{
   443  				Query:    "select * from t;",
   444  				Expected: []sql.Row{{0}, {1}, {10}, {100}, {10000}, {100000}},
   445  			},
   446  		},
   447  	},
   448  	{
   449  		Name: "dolt_rebase: data conflicts",
   450  		SetUpScript: []string{
   451  			"create table t (pk int primary key, c1 varchar(100));",
   452  			"call dolt_commit('-Am', 'creating table t');",
   453  			"call dolt_branch('branch1');",
   454  
   455  			"insert into t values (0, 'zero');",
   456  			"call dolt_commit('-am', 'inserting row 0');",
   457  
   458  			"call dolt_checkout('branch1');",
   459  			"insert into t values (1, 'one');",
   460  			"call dolt_commit('-am', 'inserting row 1');",
   461  			"update t set c1='uno' where pk=1;",
   462  			"call dolt_commit('-am', 'updating row 1');",
   463  			"update t set c1='ein' where pk=1;",
   464  			"call dolt_commit('-am', 'updating row 1');",
   465  		},
   466  		Assertions: []queries.ScriptTestAssertion{
   467  			{
   468  				Query: "call dolt_rebase('-i', 'main');",
   469  				Expected: []sql.Row{{0, "interactive rebase started on branch dolt_rebase_branch1; " +
   470  					"adjust the rebase plan in the dolt_rebase table, then " +
   471  					"continue rebasing by calling dolt_rebase('--continue')"}},
   472  			},
   473  			{
   474  				Query: "select * from dolt_rebase order by rebase_order ASC;",
   475  				Expected: []sql.Row{
   476  					{"1", "pick", doltCommit, "inserting row 1"},
   477  					{"2", "pick", doltCommit, "updating row 1"},
   478  					{"3", "pick", doltCommit, "updating row 1"},
   479  				},
   480  			},
   481  			{
   482  				Query: "update dolt_rebase set rebase_order=3.5 where rebase_order=1;",
   483  				Expected: []sql.Row{{gmstypes.OkResult{RowsAffected: uint64(1), Info: plan.UpdateInfo{
   484  					Matched: 1,
   485  					Updated: 1,
   486  				}}}},
   487  			},
   488  			{
   489  				// Encountering a conflict during a rebase returns an error and aborts the rebase
   490  				Query:       "call dolt_rebase('--continue');",
   491  				ExpectedErr: dprocedures.ErrRebaseConflict,
   492  			},
   493  			{
   494  				// The rebase state has been cleared after hitting a conflict
   495  				Query:          "call dolt_rebase('--continue');",
   496  				ExpectedErrStr: "no rebase in progress",
   497  			},
   498  			{
   499  				// We're back to the original branch
   500  				Query:    "select active_branch();",
   501  				Expected: []sql.Row{{"branch1"}},
   502  			},
   503  			{
   504  				// The conflicts table should be empty, since the rebase was aborted
   505  				Query:    "select * from dolt_conflicts;",
   506  				Expected: []sql.Row{},
   507  			},
   508  		},
   509  	},
   510  	{
   511  		Name: "dolt_rebase: schema conflicts",
   512  		SetUpScript: []string{
   513  			"create table t (pk int primary key);",
   514  			"call dolt_commit('-Am', 'creating table t');",
   515  			"call dolt_branch('branch1');",
   516  
   517  			"insert into t values (0);",
   518  			"call dolt_commit('-am', 'inserting row 0');",
   519  
   520  			"call dolt_checkout('branch1');",
   521  			"insert into t values (1);",
   522  			"call dolt_commit('-am', 'inserting row 1');",
   523  			"alter table t add column c1 varchar(100) NOT NULL;",
   524  			"call dolt_commit('-am', 'adding column c1');",
   525  			"alter table t modify column c1 varchar(100) comment 'foo';",
   526  			"call dolt_commit('-am', 'altering column c1');",
   527  		},
   528  		Assertions: []queries.ScriptTestAssertion{
   529  			{
   530  				Query: "call dolt_rebase('-i', 'main');",
   531  				Expected: []sql.Row{{0, "interactive rebase started on branch dolt_rebase_branch1; " +
   532  					"adjust the rebase plan in the dolt_rebase table, then " +
   533  					"continue rebasing by calling dolt_rebase('--continue')"}},
   534  			},
   535  			{
   536  				Query: "select * from dolt_rebase order by rebase_order ASC;",
   537  				Expected: []sql.Row{
   538  					{"1", "pick", doltCommit, "inserting row 1"},
   539  					{"2", "pick", doltCommit, "adding column c1"},
   540  					{"3", "pick", doltCommit, "altering column c1"},
   541  				},
   542  			},
   543  			{
   544  				Query: "update dolt_rebase set rebase_order=3.1 where rebase_order=2;",
   545  				Expected: []sql.Row{{gmstypes.OkResult{RowsAffected: uint64(1), Info: plan.UpdateInfo{
   546  					Matched: 1,
   547  					Updated: 1,
   548  				}}}},
   549  			},
   550  			{
   551  				// Encountering a conflict during a rebase returns an error and aborts the rebase
   552  				Query:       "call dolt_rebase('--continue');",
   553  				ExpectedErr: dprocedures.ErrRebaseConflict,
   554  			},
   555  			{
   556  				// The rebase state has been cleared after hitting a conflict
   557  				Query:          "call dolt_rebase('--continue');",
   558  				ExpectedErrStr: "no rebase in progress",
   559  			},
   560  			{
   561  				// We're back to the original branch
   562  				Query:    "select active_branch();",
   563  				Expected: []sql.Row{{"branch1"}},
   564  			},
   565  			{
   566  				// The schema conflicts table should be empty, since the rebase was aborted
   567  				Query:    "select * from dolt_schema_conflicts;",
   568  				Expected: []sql.Row{},
   569  			},
   570  		},
   571  	},
   572  	{
   573  		// Tests that the rebase plan can be changed in non-standard ways, such as adding new commits to the plan
   574  		// and completely removing commits from the plan. These changes are also valid with Git.
   575  		Name: "dolt_rebase: non-standard plan changes",
   576  		SetUpScript: []string{
   577  			"create table t (pk int primary key);",
   578  			"call dolt_commit('-Am', 'creating table t');",
   579  			"call dolt_branch('branch1');",
   580  			"call dolt_branch('branch2');",
   581  
   582  			"insert into t values (0);",
   583  			"call dolt_commit('-am', 'inserting row 0');",
   584  
   585  			"call dolt_checkout('branch2');",
   586  			"insert into t values (999);",
   587  			"call dolt_commit('-am', 'inserting row 999');",
   588  
   589  			"call dolt_checkout('branch1');",
   590  			"insert into t values (1);",
   591  			"call dolt_commit('-am', 'inserting row 1');",
   592  			"insert into t values (2);",
   593  			"call dolt_commit('-am', 'inserting row 2');",
   594  			"insert into t values (3);",
   595  			"call dolt_commit('-am', 'inserting row 3');",
   596  		},
   597  		Assertions: []queries.ScriptTestAssertion{
   598  			{
   599  				Query:    "select active_branch();",
   600  				Expected: []sql.Row{{"branch1"}},
   601  			},
   602  			{
   603  				Query:    "select * from t;",
   604  				Expected: []sql.Row{{1}, {2}, {3}},
   605  			},
   606  			{
   607  				Query: "call dolt_rebase('-i', 'main');",
   608  				Expected: []sql.Row{{0, "interactive rebase started on branch dolt_rebase_branch1; " +
   609  					"adjust the rebase plan in the dolt_rebase table, then " +
   610  					"continue rebasing by calling dolt_rebase('--continue')"}},
   611  			},
   612  			{
   613  				Query: "select * from dolt_rebase order by rebase_order;",
   614  				Expected: []sql.Row{
   615  					{"1", "pick", doltCommit, "inserting row 1"},
   616  					{"2", "pick", doltCommit, "inserting row 2"},
   617  					{"3", "pick", doltCommit, "inserting row 3"},
   618  				},
   619  			},
   620  			{
   621  				Query:    "delete from dolt_rebase where rebase_order > 1;",
   622  				Expected: []sql.Row{{gmstypes.NewOkResult(2)}},
   623  			},
   624  			{
   625  				Query:    "insert into dolt_rebase values (2.12, 'pick', hashof('branch2'), 'inserting row 0');",
   626  				Expected: []sql.Row{{gmstypes.NewOkResult(1)}},
   627  			},
   628  			{
   629  				Query:    "call dolt_rebase('--continue');",
   630  				Expected: []sql.Row{{0, "Successfully rebased and updated refs/heads/branch1"}},
   631  			},
   632  			{
   633  				Query: "select message from dolt_log;",
   634  				Expected: []sql.Row{
   635  					{"inserting row 999"},
   636  					{"inserting row 1"},
   637  					{"inserting row 0"},
   638  					{"creating table t"},
   639  					{"Initialize data repository"},
   640  				},
   641  			},
   642  			{
   643  				Query:    "select * from t;",
   644  				Expected: []sql.Row{{0}, {1}, {999}},
   645  			},
   646  		},
   647  	},
   648  	{
   649  		// Merge commits are skipped during a rebase
   650  		Name: "dolt_rebase: merge commits",
   651  		SetUpScript: []string{
   652  			"create table t (pk int primary key);",
   653  			"call dolt_commit('-Am', 'creating table t');",
   654  			"call dolt_branch('branch1');",
   655  
   656  			"insert into t values (0);",
   657  			"call dolt_commit('-am', 'inserting row 0');",
   658  
   659  			"call dolt_checkout('branch1');",
   660  			"insert into t values (1);",
   661  			"call dolt_commit('-am', 'inserting row 1');",
   662  			"insert into t values (2);",
   663  			"call dolt_commit('-am', 'inserting row 2');",
   664  			"call dolt_merge('main');",
   665  			"insert into t values (3);",
   666  			"call dolt_commit('-am', 'inserting row 3');",
   667  		},
   668  		Assertions: []queries.ScriptTestAssertion{
   669  			{
   670  				Query: "select message from dolt_log;",
   671  				Expected: []sql.Row{
   672  					{"inserting row 3"},
   673  					{"Merge branch 'main' into branch1"},
   674  					{"inserting row 2"},
   675  					{"inserting row 0"},
   676  					{"inserting row 1"},
   677  					{"creating table t"},
   678  					{"Initialize data repository"},
   679  				},
   680  			},
   681  			{
   682  				Query: "call dolt_rebase('-i', 'main');",
   683  				Expected: []sql.Row{{0, "interactive rebase started on branch dolt_rebase_branch1; " +
   684  					"adjust the rebase plan in the dolt_rebase table, then " +
   685  					"continue rebasing by calling dolt_rebase('--continue')"}},
   686  			},
   687  			{
   688  				Query: "select * from dolt_rebase order by rebase_order;",
   689  				Expected: []sql.Row{
   690  					{"1", "pick", doltCommit, "inserting row 1"},
   691  					{"2", "pick", doltCommit, "inserting row 2"},
   692  					{"3", "pick", doltCommit, "inserting row 3"},
   693  				},
   694  			},
   695  			{
   696  				Query:    "call dolt_rebase('--continue');",
   697  				Expected: []sql.Row{{0, "Successfully rebased and updated refs/heads/branch1"}},
   698  			},
   699  			{
   700  				Query: "select message from dolt_log;",
   701  				Expected: []sql.Row{
   702  					{"inserting row 3"},
   703  					{"inserting row 2"},
   704  					{"inserting row 1"},
   705  					{"inserting row 0"},
   706  					{"creating table t"},
   707  					{"Initialize data repository"},
   708  				},
   709  			},
   710  		},
   711  	},
   712  }
   713  
   714  var DoltRebaseMultiSessionScriptTests = []queries.ScriptTest{
   715  	{
   716  		// When the branch HEAD is changed while a rebase is in progress, the rebase should fail
   717  		Name: "dolt_rebase errors: branch HEAD changed during rebase",
   718  		SetUpScript: []string{
   719  			"create table t (pk int primary key);",
   720  			"call dolt_commit('-Am', 'creating table t');",
   721  			"call dolt_checkout('-b', 'branch1');",
   722  			"insert into t values (1);",
   723  			"call dolt_commit('-am', 'inserting row 1');",
   724  			"insert into t values (2);",
   725  			"call dolt_commit('-am', 'inserting row 2');",
   726  			"insert into t values (3);",
   727  			"call dolt_commit('-am', 'inserting row 3');",
   728  		},
   729  		Assertions: []queries.ScriptTestAssertion{
   730  			{
   731  				Query:    "/* client a */ select active_branch();",
   732  				Expected: []sql.Row{{"branch1"}},
   733  			},
   734  			{
   735  				Query:    "/* client b */ call dolt_checkout('branch1');",
   736  				Expected: []sql.Row{{0, "Switched to branch 'branch1'"}},
   737  			},
   738  			{
   739  				Query:    "/* client b */ select active_branch();",
   740  				Expected: []sql.Row{{"branch1"}},
   741  			},
   742  			{
   743  				Query: "/* client a */ call dolt_rebase('-i', 'main');",
   744  				Expected: []sql.Row{{0, "interactive rebase started on branch dolt_rebase_branch1; " +
   745  					"adjust the rebase plan in the dolt_rebase table, then " +
   746  					"continue rebasing by calling dolt_rebase('--continue')"}},
   747  			},
   748  			{
   749  				Query:    "/* client b */ insert into t values (1000);",
   750  				Expected: []sql.Row{},
   751  			},
   752  			{
   753  				Query:            "/* client b */ call dolt_commit('-am', 'inserting row 1000');",
   754  				SkipResultsCheck: true,
   755  			},
   756  			{
   757  				Query:          "/* client a */ call dolt_rebase('--continue');",
   758  				ExpectedErrStr: "Error 1105 (HY000): rebase aborted due to changes in branch branch1",
   759  			},
   760  		},
   761  	},
   762  }