#!/usr/bin/env bats load $BATS_TEST_DIRNAME/helper/common.bash setup() { setup_common dolt sql < 3; SQL [ $status -eq 0 ] [[ ! "$output" =~ "4" ]] || false run dolt status [ $status -eq 0 ] [[ "$output" =~ "main" ]] || false run dolt checkout copy [ $status -eq 0 ] run dolt sql -q "SELECT * FROM test WHERE pk > 3;" [[ "$output" =~ "4" ]] || false } @test "sql-branch: CALL DOLT_BRANCH -c throws error on error cases" { run dolt status [[ "$output" =~ "main" ]] || false # branch copying from is empty run dolt sql -q "CALL DOLT_BRANCH('-c','','copy')" [ $status -eq 1 ] [[ "$output" =~ "error: cannot branch empty string" ]] # branch copying to is empty run dolt sql -q "CALL DOLT_BRANCH('-c','main','')" [ $status -eq 1 ] [[ "$output" =~ "error: cannot branch empty string" ]] dolt branch 'existing_branch' run dolt branch [[ "$output" =~ "main" ]] || false [[ "$output" =~ "existing_branch" ]] || false [[ ! "$output" =~ "original" ]] || false # branch copying from that don't exist run dolt sql -q "CALL DOLT_BRANCH('-c', 'original', 'copy');" [ $status -eq 1 ] [[ "$output" =~ "fatal: A branch named 'original' not found" ]] # branch copying to that exists run dolt sql -q "CALL DOLT_BRANCH('-c', 'main', 'existing_branch');" [ $status -eq 1 ] [[ "$output" =~ "fatal: A branch named 'existing_branch' already exists." ]] } @test "sql-branch: CALL DOLT_BRANCH works as insert into dolt_branches table" { dolt add . && dolt commit -m "1, 2, and 3 in test table" run dolt sql -q "SELECT hash FROM dolt_branches WHERE name='main';" [ $status -eq 0 ] mainhash=$output dolt sql -q "CALL DOLT_BRANCH('feature-branch');" run dolt sql -q "SELECT hash FROM dolt_branches WHERE name='feature-branch';" [ $status -eq 0 ] [ "$output" = "$mainhash" ] } @test "sql-branch: CALL DOLT_BRANCH to rename and delete" { dolt add . && dolt commit -m "1, 2, and 3 in test table" dolt branch new_branch run dolt sql -q "CALL DOLT_BRANCH('-m', 'new_branch', 'changed');" [ $status -eq 0 ] run dolt sql -q "CALL DOLT_BRANCH('-d', 'changed');" [ $status -eq 0 ] dolt branch branch_with_unpushed_commit dolt checkout branch_with_unpushed_commit dolt commit --allow-empty -am 'empty commit' dolt checkout main run dolt sql -q "CALL DOLT_BRANCH('-d', 'branch_with_unpushed_commit');" [ $status -eq 1 ] [[ "$output" =~ "not fully merged" ]] || false run dolt sql -q "CALL DOLT_BRANCH('-D', 'branch_with_unpushed_commit');" [ $status -eq 0 ] } @test "sql-branch: CALL DOLT_BRANCH -d error cases" { dolt add . && dolt commit -m "1, 2, and 3 in test table" dolt branch new_branch # Attempting to delete the db's default branch results in an error run dolt sql -q "CALL DOLT_BRANCH('-D', 'main');" [ $status -eq 1 ] [[ "$output" =~ "attempted to delete checked out branch" ]] || false }