#!/usr/bin/env bats load $BATS_TEST_DIRNAME/helper/common.bash setup() { setup_common dolt sql < 6" dolt commit -am "Update a rows" dolt checkout main run dolt sql -q "CALL DOLT_CHERRY_PICK('branch1')" [ "$status" -eq "1" ] [[ "$output" =~ "table was modified in one branch and deleted in the other" ]] || false run dolt sql -q "SHOW TABLES" -r csv [[ ! "$output" =~ "branch1table" ]] || false dolt checkout branch1 dolt sql -q "DELETE FROM branch1table WHERE id > 8" dolt commit -am "Update and delete rows" dolt checkout main run dolt sql -q "CALL DOLT_CHERRY_PICK('branch1')" [ "$status" -eq "1" ] [[ "$output" =~ "table was modified in one branch and deleted in the other" ]] || false run dolt sql -q "SHOW TABLES" -r csv [[ ! "$output" =~ "branch1table" ]] || false dolt checkout branch1 dolt sql -q "ALTER TABLE branch1table ADD COLUMN col2 int" dolt commit -am "Alter table add column" dolt checkout main run dolt sql -q "CALL DOLT_CHERRY_PICK('branch1')" [ "$status" -eq "1" ] [[ "$output" =~ "merge aborted: schema conflict found for table branch1table" ]] || false [[ "$output" =~ "table was modified in one branch and deleted in the other" ]] || false run dolt sql -q "SHOW TABLES" -r csv [[ ! "$output" =~ "branch1table" ]] || false } @test "sql-cherry-pick: error when using --abort with no in-progress cherry-pick" { run dolt sql -q "call DOLT_CHERRY_PICK('--abort');" [ $status -eq 1 ] [[ $output =~ "error: There is no cherry-pick merge to abort" ]] || false [[ ! $output =~ "usage: dolt cherry-pick" ]] || false } @test "sql-cherry-pick: conflict resolution" { dolt sql -q "CREATE TABLE other (pk int primary key, v int)" dolt add . dolt sql -q "INSERT INTO other VALUES (1, 2)" dolt sql -q "INSERT INTO test VALUES (4,'f')" dolt commit -am "add other table" dolt checkout main dolt sql -q "CREATE TABLE other (pk int primary key, v int)" dolt add . dolt sql -q "INSERT INTO other VALUES (1, 3)" dolt sql -q "INSERT INTO test VALUES (4,'k')" dolt commit -am "add other table with conflict and test with conflict" run dolt sql <>> $output" [ $status -eq 0 ] [[ ! $output =~ "Changes to be committed" ]] || false [[ $output =~ "Unmerged paths" ]] || false [[ $output =~ "both modified: other" ]] || false [[ $output =~ "both modified: test" ]] || false dolt conflicts resolve --theirs . run dolt sql -q "select * from other" [ $status -eq 0 ] [[ $output =~ "1 | 2" ]] || false run dolt sql -q "select * from test" [ $status -eq 0 ] [[ $output =~ "4 | f" ]] || false dolt commit -m "committing cherry-picked change" } @test "sql-cherry-pick: commit with CREATE TABLE" { dolt sql -q "CREATE TABLE table_a (pk BIGINT PRIMARY KEY, v varchar(10))" dolt add . dolt sql -q "INSERT INTO table_a VALUES (11, 'aa'), (22, 'ab'), (33, 'ac')" dolt sql -q "DELETE FROM test WHERE pk = 2" dolt commit -am "Added table_a with rows and delete pk=2 from test" dolt checkout main run dolt sql -q "CALL DOLT_CHERRY_PICK('branch1')" [ "$status" -eq "0" ] run dolt sql -q "SHOW TABLES" -r csv [[ "$output" =~ "table_a" ]] || false run dolt sql -q "SELECT * FROM test" -r csv [[ ! "$output" =~ "1,a" ]] || false [[ ! "$output" =~ "2,b" ]] || false [[ ! "$output" =~ "3,c" ]] || false run dolt sql -q "SELECT * FROM table_a" -r csv [[ "$output" =~ "11,aa" ]] || false [[ "$output" =~ "22,ab" ]] || false [[ "$output" =~ "33,ac" ]] || false } @test "sql-cherry-pick: commit with DROP TABLE" { dolt sql -q "DROP TABLE test" dolt commit -am "Drop table test" run dolt sql -q "SHOW TABLES" -r csv [[ ! "$output" =~ "test" ]] || false dolt checkout main run dolt sql -q "SHOW TABLES" -r csv [[ "$output" =~ "test" ]] || false run dolt sql -q "CALL DOLT_CHERRY_PICK('branch1')" [ "$status" -eq "1" ] [[ "$output" =~ "table was modified in one branch and deleted in the other" ]] || false run dolt sql -q "SHOW TABLES" -r csv [[ "$output" =~ "test" ]] || false } @test "sql-cherry-pick: commit with ALTER TABLE rename table name" { # get main and branch1 in sync, so that the data on branch1 doesn't # cause a conflict when we cherry pick the table rename statement dolt checkout main dolt merge branch1 dolt checkout branch1 dolt sql -q "ALTER TABLE test RENAME TO new_name" dolt commit -Am "rename table name" dolt checkout main dolt sql -q "CALL DOLT_CHERRY_PICK('branch1')" run dolt sql -q "show tables;" [ $status -eq 0 ] [[ ! $output =~ "test" ]] || false [[ $output =~ "new_name" ]] || false } @test "sql-cherry-pick: cherry-pick commit is a merge commit" { dolt checkout -b branch2 dolt sql -q "INSERT INTO test VALUES (4, 'd'), (5, 'e')" dolt commit -am "add more rows in branch2" dolt checkout branch1 dolt sql -q "INSERT INTO test VALUES (6, 'f'), (7, 'g')" dolt commit -am "add more rows in branch1" dolt merge branch2 -m "merge branch2" dolt checkout main run dolt sql -q "CALL DOLT_CHERRY_PICK('branch1')" [ $status -eq 1 ] [[ $output =~ "cherry-picking a merge commit is not supported" ]] || false } @test "sql-cherry-pick: cherry-pick commit is a cherry-picked commit" { dolt checkout -b branch2 dolt sql -q "INSERT INTO test VALUES (4, 'd'), (5, 'e')" dolt commit -am "add more rows in branch2" dolt checkout branch1 dolt sql -q "INSERT INTO test VALUES (6, 'f'), (7, 'g')" dolt commit -am "add more rows in branch1" run dolt sql -q "CALL DOLT_CHERRY_PICK('branch2')" [ "$status" -eq "0" ] run dolt sql -q "SELECT * FROM test" -r csv [[ "$output" =~ "4,d" ]] || false [[ "$output" =~ "5,e" ]] || false dolt checkout main run dolt sql -q "CALL DOLT_CHERRY_PICK('branch1')" [ "$status" -eq "0" ] run dolt sql -q "SELECT * FROM test" -r csv [[ "$output" =~ "4,d" ]] || false [[ "$output" =~ "5,e" ]] || false } @test "sql-cherry-pick: add triggers" { dolt sql -q "CREATE TRIGGER trigger1 BEFORE INSERT ON test FOR EACH ROW SET new.v = concat(new.v, ' inserted')" dolt sql -q "CREATE view two as select 1+1" dolt sql -q "INSERT INTO test VALUES (4,'z')" run dolt sql -q "SELECT * FROM test" [[ "$output" =~ "z inserted" ]] || false dolt add . dolt commit -am "add trigger" dolt checkout main run dolt sql -q "SHOW TRIGGERS" [[ ! "$output" =~ "trigger1" ]] || false run dolt sql -q "CALL DOLT_CHERRY_PICK('branch1')" [ "$status" -eq "0" ] run dolt sql -q "SELECT * FROM test" [[ "$output" =~ "z inserted" ]] || false run dolt sql -q "SHOW TRIGGERS" [[ "$output" =~ "trigger1" ]] || false dolt checkout branch1 dolt sql -q "DROP TRIGGER trigger1" dolt commit -am "drop trigger" dolt checkout main run dolt sql -q "CALL DOLT_CHERRY_PICK('branch1')" [ "$status" -eq "0" ] run dolt sql -q "SHOW TRIGGERS" [[ ! "$output" =~ "trigger1" ]] || false } @test "sql-cherry-pick: add procedures" { dolt sql -q "CREATE PROCEDURE proc1 (in x int) select x from dual" run dolt sql -q "CALL proc1(434)" [[ "$output" =~ "434" ]] || false dolt add . dolt commit -am "add procedure" dolt checkout main run dolt sql -q "SHOW PROCEDURE STATUS" [[ ! "$output" =~ "proc1" ]] || false run dolt sql -q "CALL DOLT_CHERRY_PICK('branch1')" [ "$status" -eq "0" ] run dolt sql -q "SHOW PROCEDURE STATUS" [[ "$output" =~ "proc1" ]] || false run dolt sql -q "CALL proc1(434)" [[ "$output" =~ "434" ]] || false } @test "sql-cherry-pick: keyless table" { dolt checkout main dolt sql -q "CREATE TABLE keyless (id int, name varchar(10))" dolt add . dolt commit -am "add keyless table" dolt checkout -b branch2 dolt sql -q "INSERT INTO keyless VALUES (1,'1'), (2,'3')" dolt commit -am "insert into keyless table" dolt checkout main run dolt sql -q "CALL DOLT_CHERRY_PICK('branch1')" [ "$status" -eq "0" ] dolt sql -q "SELECT * FROM keyless" -r csv [[ ! "$output" =~ "1,1" ]] || false [[ ! "$output" =~ "2,3" ]] || false } @test "sql-cherry-pick: commit with ALTER TABLE add column" { dolt sql -q "ALTER TABLE test ADD COLUMN c int" dolt commit -am "alter table test add column c" dolt checkout main dolt sql -q "CALL DOLT_CHERRY_PICK('branch1')" run dolt sql -q "SHOW CREATE TABLE test;" [ $status -eq 0 ] [[ $output =~ '`c` int' ]] || false } @test "sql-cherry-pick: commit with ALTER TABLE change column" { dolt sql -q "ALTER TABLE test CHANGE COLUMN v c varchar(100)" dolt commit -am "alter table test change column v" dolt checkout main dolt sql -q "CALL DOLT_CHERRY_PICK('branch1')" run dolt sql -q "SHOW CREATE TABLE test;" [ $status -eq 0 ] [[ $output =~ '`c` varchar(100)' ]] || false [[ ! $output =~ '`v` varchar(10)' ]] || false } @test "sql-cherry-pick: commit with ALTER TABLE modify column" { dolt sql -q "UPDATE test SET v = '1' WHERE pk < 4" dolt sql -q "ALTER TABLE test MODIFY COLUMN v int" dolt commit -am "alter table test modify column v" # TODO: Incompatible type changes currently trigger an error response, instead of # being tracked as a schema conflict artifact. Once we fix that, update this test. dolt checkout main run dolt sql -q "CALL DOLT_CHERRY_PICK('branch1')" [ $status -eq 1 ] [[ $output =~ "merge aborted: schema conflict found for table test" ]] || false } @test "sql-cherry-pick: commit with ALTER TABLE drop column" { # get main and branch1 in sync, so that the data on branch1 doesn't # cause a conflict when we cherry pick the alter table statement dolt checkout main dolt merge branch1 # Drop column v on branch1 dolt checkout branch1 dolt sql -q "ALTER TABLE test DROP COLUMN v" dolt commit -am "alter table test drop column v" # Cherry pick the drop column change to main dolt checkout main dolt sql -q "CALL DOLT_CHERRY_PICK('branch1');" # Assert that column v is gone run dolt sql -q "SHOW CREATE TABLE test;" [ $status -eq 0 ] [[ ! $output =~ '`v` varchar(10)' ]] || false } @test "sql-cherry-pick: commit with ALTER TABLE rename column" { dolt sql -q "ALTER TABLE test RENAME COLUMN v TO c" dolt commit -am "alter table test rename column v" dolt checkout main dolt sql -q "CALL DOLT_CHERRY_PICK('branch1')" run dolt sql -q "SHOW CREATE TABLE test;" [ $status -eq 0 ] [[ ! $output =~ '`v` varchar(10)' ]] || false [[ $output =~ '`c` varchar(10)' ]] || false } @test "sql-cherry-pick: commit with ALTER TABLE drop and add primary key" { dolt sql -q "ALTER TABLE test DROP PRIMARY KEY, ADD PRIMARY KEY (pk, v)" dolt commit -am "alter table test drop and add primary key" dolt checkout main run dolt sql -q "CALL DOLT_CHERRY_PICK('branch1')" [ $status -eq 1 ] [[ $output =~ "error: cannot merge because table test has different primary keys" ]] || false }