#! /usr/bin/env bats load $BATS_TEST_DIRNAME/helper/common.bash load $BATS_TEST_DIRNAME/helper/query-server-common.bash make_repo() { mkdir "$1" cd "$1" dolt init dolt sql -q "create table $1_tbl (id int)" dolt sql <...\" to unstage)" ]] || false [[ "$output" =~ " modified: table1" ]] || false [[ "$output" =~ "Changes not staged for commit:" ]] || false [[ "$output" =~ " (use \"dolt add \" to update what will be committed)" ]] || false [[ "$output" =~ " (use \"dolt checkout
\" to discard changes in working directory)" ]] || false [[ "$output" =~ " modified: table2" ]] || false [[ "$output" =~ "Untracked tables:" ]] || false [[ "$output" =~ " (use \"dolt add
\" to include in what will be committed)" ]] || false [[ "$output" =~ " new table: table3" ]] || false ! [[ "$output" =~ " new table: generated_foo" ]] || false remoteOutput=$output run dolt status --ignored [ "$status" -eq 0 ] || false [[ "$output" =~ "On branch main" ]] || false [[ "$output" =~ "Changes to be committed:" ]] || false [[ "$output" =~ " (use \"dolt reset
...\" to unstage)" ]] || false [[ "$output" =~ " modified: table1" ]] || false [[ "$output" =~ "Changes not staged for commit:" ]] || false [[ "$output" =~ " (use \"dolt add
\" to update what will be committed)" ]] || false [[ "$output" =~ " (use \"dolt checkout
\" to discard changes in working directory)" ]] || false [[ "$output" =~ " modified: table2" ]] || false [[ "$output" =~ "Untracked tables:" ]] || false [[ "$output" =~ " (use \"dolt add
\" to include in what will be committed)" ]] || false [[ "$output" =~ " new table: table3" ]] || false [[ "$output" =~ "Ignored tables:" ]] || false [[ "$output" =~ " (use \"dolt add -f
\" to include in what will be committed)" ]] || false [[ "$output" =~ " new table: generated_foo" ]] || false remoteIgnoredOutput=$output stop_sql_server 1 run dolt status [ "$status" -eq 0 ] || false localOutput=$output run dolt status --ignored [ "$status" -eq 0 ] || false localIgnoredOutput=$output [[ "$remoteOutput" == "$localOutput" ]] || false [[ "$remoteIgnoredOutput" == "$localIgnoredOutput" ]] || false } @test "sql-local-remote: verify dolt commit behavior is identical in switch between server/no server" { cd altDB dolt sql -q "create table test1 (pk int primary key)" dolt sql -q "create table test2 (pk int primary key)" dolt add test1 cd .. start_sql_server altDB cd altDB run dolt --verbose-engine-setup commit -m "committing remotely" [ "$status" -eq 0 ] [[ "$output" =~ "committing remotely" ]] || false stop_sql_server 1 run dolt log [ "$status" -eq 0 ] [[ "$output" =~ "committing remotely" ]] || false run dolt add test2 [ "$status" -eq 0 ] run dolt --verbose-engine-setup commit -m "committing locally" [ "$status" -eq 0 ] [[ "$output" =~ "starting local mode" ]] || false run dolt log [ "$status" -eq 0 ] [[ "$output" =~ "committing locally" ]] || false } @test "sql-local-remote: verify dolt commit print" { run dolt --use-db altDB commit -A -m "Wonderful Commit" [[ "${lines[0]}" =~ "commit " ]] || false [[ "${lines[1]}" =~ "Author: Bats Tests " ]] || false [[ "${lines[2]}" =~ "Date: " ]] || false [[ "${lines[3]}" =~ " Wonderful Commit" ]] || false } @test "sql-local-remote: verify simple dolt branch behavior." { start_sql_server altDB cd altDB run dolt --verbose-engine-setup branch b1 [ "$status" -eq 0 ] [[ "$output" =~ "starting remote mode" ]] || false run dolt --verbose-engine-setup branch [ "$status" -eq 0 ] [[ "$output" =~ "starting remote mode" ]] || false [[ "$output" =~ "main" ]] || false [[ "$output" =~ "b1" ]] || false stop_sql_server 1 run dolt --verbose-engine-setup branch b2 [ "$status" -eq 0 ] [[ "$output" =~ "starting local mode" ]] || false run dolt --verbose-engine-setup branch [ "$status" -eq 0 ] [[ "$output" =~ "starting local mode" ]] || false [[ "$output" =~ "main" ]] || false [[ "$output" =~ "b2" ]] || false } @test "sql-local-remote: verify dolt diff behavior with data and schema changes" { start_sql_server defaultDB cd defaultDB dolt sql < | 4 | 100 | NULL | NULL | | + | 7 | 8 | NULL | 9 | +---+----+-----+------+------+ EOF ) dolt diff run dolt diff [ "$status" -eq 0 ] || false [[ "$output" =~ "$EXPECTED" ]] || false remoteOutput=$output stop_sql_server 1 run dolt diff [ "$status" -eq 0 ] || false localOutput=$output [[ "$remoteOutput" == "$localOutput" ]] || false } @test "sql-local-remote: verify dolt show behavior" { cd defaultDB dolt commit --allow-empty -m "commit: initialize table1" run dolt show --no-pretty [ "$status" -eq 0 ] || false [[ "$output" =~ "SerialMessage" ]] || false assert_has_key "Name" "$output" assert_has_key_value "Name" "Bats Tests" "$output" assert_has_key_value "Desc" "commit: initialize table1" "$output" assert_has_key_value "Name" "Bats Tests" "$output" assert_has_key_value "Email" "bats@email.fake" "$output" assert_has_key "Timestamp" "$output" assert_has_key "UserTimestamp" "$output" assert_has_key_value "Height" "3" "$output" assert_has_key "RootValue" "$output" assert_has_key "Parents" "$output" assert_has_key "ParentClosure" "$output" parentHash=$(extract_value Parents "$output") parentClosureHash=$(extract_value ParentClosure "$output") rootValue=$(extract_value RootValue "$output") run dolt show "$parentHash" [ "$status" -eq 0 ] || false [[ "$output" =~ "tables table1, table2" ]] || false run dolt show "$rootValue" [ "$status" -eq 0 ] || false run dolt show "$parentClosureHash" [ "$status" -eq 0 ] || false start_sql_server defaultDB run dolt show --no-pretty [ $status -eq 1 ] || false [[ "$output" =~ '`dolt show --no-pretty` or `dolt show (BRANCHNAME)` only supported in local mode.' ]] || false run dolt show "$parentHash" [ $status -eq 0 ] || false [[ "$output" =~ "tables table1, table2" ]] || false run dolt show "$parentClosureHash" [ $status -eq 1 ] || false [[ "$output" =~ '`dolt show (NON_COMMIT_HASH)` only supported in local mode.' ]] || false run dolt show "$rootValue" [ $status -eq 1 ] || false [[ "$output" =~ '`dolt show (NON_COMMIT_HASH)` only supported in local mode.' ]] || false stop_sql_server 1 } @test "sql-local-remote: verify dolt conflicts cat behavior" { cd defaultDB dolt sql << SQL CREATE TABLE people ( id INT NOT NULL, last_name VARCHAR(120), first_name VARCHAR(120), birthday DATETIME(6), age INT DEFAULT '0', PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin; SQL dolt add . dolt commit -am "base" dolt checkout -b right dolt sql <" ]] || false [[ $output =~ "verbose: starting local mode" ]] || false # add tag with commit run dolt tag v2_tag $secondCommit [ $status -eq 0 ] # list tags and check new tag is present run dolt tag --verbose [ $status -eq 0 ] [[ $output =~ "v1_tag"$'\t'"$headCommit" ]] || false [[ $output =~ "v2_tag"$'\t'"$secondCommit" ]] || false # add tag with message run dolt tag v3_tag -m "tag message" [ $status -eq 0 ] # list tags and check new tag is present run dolt tag --verbose [ $status -eq 0 ] [[ $output =~ "v3_tag"$'\t'"$headCommit" ]] || false [[ $output =~ "tag message" ]] || false # add tag with message and commit run dolt tag v4_tag $secondCommit -m "second message" [ $status -eq 0 ] # list tags and check new tag is present run dolt tag --verbose [ $status -eq 0 ] [[ $output =~ "v4_tag"$'\t'"$secondCommit" ]] || false [[ $output =~ "second message" ]] || false # add tag with author run dolt tag v5_tag --author "John Doe " [ $status -eq 0 ] # list tags and check new tag is present run dolt tag --verbose [ $status -eq 0 ] [[ $output =~ "v5_tag"$'\t'"$headCommit" ]] || false [[ $output =~ "Tagger: John Doe " ]] || false # delete tag run dolt tag -d v2_tag [ $status -eq 0 ] # list tags and check deleted tag is not present run dolt tag --verbose [ $status -eq 0 ] [[ $output =~ "v1_tag"$'\t'"$headCommit" ]] || false [[ ! $output =~ "v2_tag" ]] || false [[ $output =~ "v3_tag"$'\t'"$headCommit" ]] || false [[ $output =~ "v4_tag"$'\t'"$secondCommit" ]] || false [[ $output =~ "tag message" ]] || false [[ $output =~ "second message" ]] || false [[ $output =~ "Tagger: John Doe " ]] || false cd ../defaultDB start_sql_server defaultDB # get commit hashes headCommit=$(get_commit_hash_at HEAD) secondCommit=$(get_commit_hash_at HEAD~1) # show tags run dolt --verbose-engine-setup tag [ $status -eq 0 ] [[ $output =~ "verbose: starting remote mode" ]] || false # add tag without message run dolt --verbose-engine-setup tag v1_tag [ $status -eq 0 ] [[ $output =~ "verbose: starting remote mode" ]] || false # list tags and check new tag is present run dolt tag [ $status -eq 0 ] [[ $output =~ "v1_tag" ]] || false # list tags with verbose flag and check new tag is present run dolt --verbose-engine-setup tag --verbose [ $status -eq 0 ] [[ $output =~ "v1_tag"$'\t'"$headCommit" ]] || false [[ $output =~ "Tagger: Bats Tests " ]] || false [[ $output =~ "verbose: starting remote mode" ]] || false # add tag with commit run dolt tag v2_tag $secondCommit [ $status -eq 0 ] # list tags and check new tag is present run dolt tag --verbose [ $status -eq 0 ] [[ $output =~ "v1_tag"$'\t'"$headCommit" ]] || false [[ $output =~ "v2_tag"$'\t'"$secondCommit" ]] || false # add tag with message run dolt tag v3_tag -m "tag message" [ $status -eq 0 ] # list tags and check new tag is present run dolt tag --verbose [ $status -eq 0 ] [[ $output =~ "v3_tag"$'\t'"$headCommit" ]] || false [[ $output =~ "tag message" ]] || false # add tag with message and commit run dolt tag v4_tag $secondCommit -m "second message" [ $status -eq 0 ] # list tags and check new tag is present run dolt tag --verbose [ $status -eq 0 ] [[ $output =~ "v4_tag"$'\t'"$secondCommit" ]] || false [[ $output =~ "second message" ]] || false # add tag with author run dolt tag v5_tag --author "John Doe " [ $status -eq 0 ] # list tags and check new tag is present run dolt tag --verbose [ $status -eq 0 ] [[ $output =~ "v5_tag"$'\t'"$headCommit" ]] || false [[ $output =~ "Tagger: John Doe " ]] || false # delete tag run dolt tag -d v2_tag [ $status -eq 0 ] # list tags and check deleted tag is not present run dolt tag --verbose [ $status -eq 0 ] [[ $output =~ "v1_tag"$'\t'"$headCommit" ]] || false [[ ! $output =~ "v2_tag" ]] || false [[ $output =~ "v3_tag"$'\t'"$headCommit" ]] || false [[ $output =~ "v4_tag"$'\t'"$secondCommit" ]] || false [[ $output =~ "tag message" ]] || false [[ $output =~ "second message" ]] || false [[ $output =~ "Tagger: John Doe " ]] || false } @test "sql-local-remote: verify dolt cherry-pick behavior" { cd altDB # setup for cherry-pick.bats dolt clean -x dolt sql -q "CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10), index(v))" dolt add . dolt commit -am "Created table" dolt checkout -b branch1 dolt sql -q "INSERT INTO test VALUES (1, 'a')" dolt commit -am "Inserted 1" dolt sql -q "INSERT INTO test VALUES (2, 'b')" dolt commit -am "Inserted 2" dolt sql -q "INSERT INTO test VALUES (3, 'c')" dolt commit -am "Inserted 3" run dolt sql -q "SELECT * FROM test" -r csv [[ "$output" =~ "1,a" ]] || false [[ "$output" =~ "2,b" ]] || false [[ "$output" =~ "3,c" ]] || false # setup for "cherry-pick: schema change, with data conflict" test dolt checkout main dolt sql -q "CREATE TABLE other (pk int primary key, c1 int, c2 int)" dolt sql -q "INSERT INTO other VALUES (1, 2, 3)" dolt commit -Am "add other table (on main)" # Create two commits on branch2: one to assert does NOT get included, and one to cherry pick dolt checkout -b branch2 dolt sql -q "INSERT INTO other VALUES (100, 200, 300);" dolt commit -am "add row 100 to other (on branch2)" # This ALTER TABLE statement modifies other rows that aren't included in the cherry-picked # commit – row (100, 200, 300) is modified to (100, 400). This shows up as a conflict # in the cherry-pick (modified row on one side, row doesn't exist on the other side). dolt sql -q "ALTER TABLE other DROP COLUMN c1;" dolt sql -q "UPDATE other SET c2 = 400 WHERE pk = 100" dolt sql -q "INSERT INTO other VALUES (10, 30);" dolt sql -q "INSERT INTO test VALUES (100, 'q');" dolt commit -am "alter table, add row 10 to other, add row 100 to test (on branch2)" # actual cherry-pick test dolt checkout main run dolt cherry-pick branch2 [ $status -eq 1 ] [[ $output =~ "Unable to apply commit cleanly due to conflicts or constraint violations" ]] || false localCherryPickOutput=$output # Assert that table 'test' is staged, but table 'other' is not staged, since it had conflicts run dolt sql -q "SELECT table_name, case when staged = 0 then 'staged' else 'working' end as location, status from dolt_status;" [ $status -eq 0 ] [[ $output =~ "| test | working | modified |" ]] || false [[ $output =~ "| other | staged | modified |" ]] || false # setup for remote test dolt checkout main dolt reset --hard main # start server start_sql_server altDB run dolt cherry-pick branch2 [ $status -eq 1 ] [[ $output =~ "Unable to apply commit cleanly due to conflicts or constraint violations" ]] || false remoteCherryPickOutput=$output # Assert that table 'test' is staged, but table 'other' is not staged, since it had conflicts run dolt sql -q "SELECT table_name, case when staged = 0 then 'staged' else 'working' end as location, status from dolt_status;" [ $status -eq 0 ] [[ $output =~ "| test | working | modified |" ]] || false [[ $output =~ "| other | staged | modified |" ]] || false [[ "$localCherryPickOutput" == "$remoteCherryPickOutput" ]] || false } @test "sql-local-remote: verify checkout will fail early when a server is running" { cd altDB dolt reset --hard # Ensure database is clean to start. start_sql_server altDB dolt branch br run dolt checkout br [ $status -eq 1 ] [[ $output =~ "dolt checkout can not currently be used when there is a local server running. Please stop your dolt sql-server or connect using \`dolt sql\` instead." ]] || false } @test "sql-local-remote: verify unmigrated command will fail with warning" { cd altDB start_sql_server altDB run dolt --user dolt profile [ $status -eq 1 ] [[ "$output" =~ "Global arguments are not supported for this command" ]] || false } @test "sql-local-remote: verify commands without global arg support will fail with warning" { cd altDB start_sql_server altDB run dolt --user dolt version [ $status -eq 1 ] [[ "$output" =~ "This command does not support global arguments." ]] || false } @test "sql-local-remote: verify dolt log behavior" { cd altDB run dolt --verbose-engine-setup log [ $status -eq 0 ] [[ "$output" =~ "starting local mode" ]] || false [[ "$output" =~ "tables table1, table2" ]] || false run dolt log [ $status -eq 0 ] localOutput=$output start_sql_server altDB run dolt --verbose-engine-setup log [ $status -eq 0 ] [[ "$output" =~ "starting remote mode" ]] || false [[ "$output" =~ "tables table1, table2" ]] || false run dolt log [ $status -eq 0 ] remoteOutput=$output [[ "$localOutput" == "$remoteOutput" ]] || false } @test "sql-local-remote: verify dolt fetch behavior" { mkdir remote cd altDB dolt remote add origin file://../remote dolt commit --allow-empty -m "cm1" dolt push origin main cd ../defaultDB dolt remote add origin file://../remote dolt fetch run dolt log origin/main [ $status -eq 0 ] [[ "$output" =~ "cm1" ]] || false cd ../altDB dolt commit --allow-empty -m "cm2" dolt push origin main cd ../defaultDB start_sql_server defaultDB dolt fetch run dolt log origin/main [ $status -eq 0 ] [[ "$output" =~ "cm2" ]] || false } @test "sql-local-remote: verify dolt push behavior" { mkdir remote cd altDB dolt remote add origin file://../remote dolt commit --allow-empty -m "cm1" dolt push origin main cd .. dolt clone file://./remote repo cd repo run dolt log [ $status -eq 0 ] [[ "$output" =~ "cm1" ]] || false cd ../altDB start_sql_server altDB dolt commit --allow-empty -m "cm2" dolt push origin main cd ../repo dolt pull run dolt log [ $status -eq 0 ] [[ "$output" =~ "cm2" ]] || false } @test "sql-local-remote: verify dolt pull behavior" { mkdir remote cd altDB dolt remote add origin file://../remote dolt commit --allow-empty -m "cm1" dolt push origin main cd .. dolt clone file://./remote repo cd altDB dolt commit --allow-empty -m "cm2" dolt push origin main cd ../repo dolt pull run dolt log [ $status -eq 0 ] [[ "$output" =~ "cm2" ]] || false cd ../altDB dolt commit --allow-empty -m "cm3" dolt push origin main cd ../repo start_sql_server repo dolt pull origin main run dolt log [ $status -eq 0 ] [[ "$output" =~ "cm3" ]] || false } @test "sql-local-remote: verify dolt ls behavior" { cd altDB run dolt --verbose-engine-setup ls [ $status -eq 0 ] [[ "$output" =~ "starting local mode" ]] || false [[ "$output" =~ "altDB_tbl" ]] || false [[ "$output" =~ "generated_foo" ]] || false [[ "$output" =~ "table1" ]] || false [[ "$output" =~ "table2" ]] || false [[ "$output" =~ "table3" ]] || false run dolt ls [ $status -eq 0 ] localOutput=$output start_sql_server altDB run dolt --verbose-engine-setup ls [ $status -eq 0 ] [[ "$output" =~ "starting remote mode" ]] || false [[ "$output" =~ "altDB_tbl" ]] || false [[ "$output" =~ "generated_foo" ]] || false [[ "$output" =~ "table1" ]] || false [[ "$output" =~ "table2" ]] || false [[ "$output" =~ "table3" ]] || false run dolt ls [ $status -eq 0 ] remoteOutput=$output [[ "$localOutput" == "$remoteOutput" ]] || false } @test "sql-local-remote: verify dolt merge-base behavior" { cd altDB dolt checkout -b feature dolt sql -q "create table table4 (pk int PRIMARY KEY)" dolt add . dolt commit -m "created table3" run dolt --verbose-engine-setup merge-base main feature [ $status -eq 0 ] [[ "$output" =~ "starting local mode" ]] || false localOutput="${lines[1]}" start_sql_server altDB run dolt --verbose-engine-setup merge-base main feature [ $status -eq 0 ] [[ "$output" =~ "starting remote mode" ]] || false remoteOutput="${lines[1]}" [[ "$localOutput" == "$remoteOutput" ]] || false } @test "sql-local-remote: verify dolt reflog behavior" { cd altDB dolt sql -q "create table t (i int primary key, j int);" dolt sql -q "insert into t values (1, 1), (2, 2), (3, 3)"; dolt commit -Am "initial commit" run dolt --verbose-engine-setup reflog [ $status -eq 0 ] [[ "$output" =~ "starting local mode" ]] || false [[ "$output" =~ "initial commit" ]] || false run dolt reflog localOutput=$output start_sql_server altDB run dolt --verbose-engine-setup reflog [ $status -eq 0 ] [[ "$output" =~ "starting remote mode" ]] || false [[ "$output" =~ "initial commit" ]] || false run dolt reflog remoteOutput=$output [[ "$localOutput" == "$remoteOutput" ]] || false } @test "sql-local-remote: verify dolt gc behavior" { cd altDB dolt sql <> rebaseScript.sh chmod +x rebaseScript.sh export EDITOR=$PWD/rebaseScript.sh export DOLT_TEST_FORCE_OPEN_EDITOR="1" run dolt --verbose-engine-setup rebase -i main [ "$status" -eq 0 ] [[ "$output" =~ "starting local mode" ]] || false [[ "$output" =~ "Successfully rebased and updated refs/heads/b1" ]] || false run dolt log [ "$status" -eq 0 ] [[ "$output" =~ "main commit 2" ]] || false [[ "$output" =~ "b1 commit 1" ]] || false dolt checkout main dolt sql -q "create table t3 (pk int primary key)" dolt add . dolt commit -m "main commit 3" dolt checkout b1 start_sql_server altDB run dolt --verbose-engine-setup rebase -i main [ "$status" -eq 1 ] [[ "$output" =~ "starting remote mode" ]] || false [[ "$output" =~ "dolt rebase can not currently be used when there is a local server running" ]] || false }