#!/usr/bin/env bats load $BATS_TEST_DIRNAME/helper/common.bash remotesrv_pid= setup() { skiponwindows "tests are flaky on Windows" setup_common cd $BATS_TMPDIR mkdir remotes-$$ mkdir remotes-$$/empty echo remotesrv log available here $BATS_TMPDIR/remotes-$$/remotesrv.log remotesrv --http-port 1234 --dir ./remotes-$$ &> ./remotes-$$/remotesrv.log 3>&- & remotesrv_pid=$! cd dolt-repo-$$ mkdir "dolt-repo-clones" } teardown() { kill $remotesrv_pid wait $remotesrv_pid || : remotesrv_pid="" teardown_common rm -rf $BATS_TMPDIR/remotes-$$ } @test "remotes: dolt remotes server is running" { ps -p $remotesrv_pid | grep remotesrv } @test "remotes: cli 'dolt checkout new_branch' without -b flag creates new branch and sets upstream if there is a remote branch with matching name" { mkdir remote mkdir repo1 cd repo1 dolt init dolt remote add origin file://../remote dolt push origin main dolt checkout -b other dolt push --set-upstream origin other cd .. dolt clone file://./remote repo2 cd repo2 dolt commit --allow-empty -m "a commit for main from repo2" dolt push run dolt branch [[ ! "$output" =~ "other" ]] || false run dolt checkout other [ "$status" -eq 0 ] [[ "$output" =~ "branch 'other' set up to track 'origin/other'." ]] || false run dolt status [[ "$output" =~ "Your branch is up to date with 'origin/other'." ]] || false } @test "remotes: guessing the remote branch fails if there are multiple remotes with branches with matching name" { mkdir remote mkdir repo1 cd repo1 dolt init dolt remote add origin file://../remote dolt push origin main dolt checkout -b other dolt push origin other cd .. dolt clone file://./remote repo2 cd repo2 dolt remote add test-remote file://../remote dolt fetch test-remote run dolt branch -a [[ "$output" =~ "remotes/origin/other" ]] || false [[ "$output" =~ "remotes/test-remote/other" ]] || false run dolt branch [[ ! "$output" =~ "other" ]] || false run dolt checkout other [ "$status" -eq 1 ] [[ "$output" =~ "'other' matched multiple (2) remote tracking branches" ]] || false } @test "remotes: cli 'dolt checkout -b new_branch' should not set upstream if there is a remote branch with matching name" { mkdir remote mkdir repo1 cd repo1 dolt init dolt remote add origin file://../remote dolt sql -q "CREATE TABLE a (pk int)" dolt add . dolt commit -am "add table a" dolt push --set-upstream origin main dolt checkout -b other dolt push --set-upstream origin other cd .. dolt clone file://./remote repo2 cd repo2 dolt branch [[ ! "$output" =~ "other" ]] || false run dolt checkout -b other [ "$status" -eq 0 ] [[ ! "$output" =~ "branch 'other' set up to track 'origin/other'." ]] || false run dolt status [[ ! "$output" =~ "Your branch is up to date with 'origin/other'." ]] || false cd ../repo1 dolt checkout other dolt sql -q "INSERT INTO a VALUES (1), (2)" dolt commit -am "add table a" dolt push cd ../repo2 dolt checkout other run dolt pull [ "$status" -eq 1 ] [[ "$output" =~ "There is no tracking information for the current branch." ]] || false } @test "remotes: call dolt_checkout('new_branch') without '-b' sets upstream if there is a remote branch with matching name" { mkdir remote mkdir repo1 cd repo1 dolt init dolt remote add test-remote http://localhost:50051/test-org/test-repo dolt sql -q "CREATE TABLE test (pk INT)" dolt add . dolt commit -am "main commit" dolt push test-remote main run dolt branch -a [ "$status" -eq 0 ] [[ ! "$output" =~ "remotes/test-remote/test-branch" ]] || false cd .. dolt clone --remote=test-remote http://localhost:50051/test-org/test-repo repo2 run dolt branch -a [ "$status" -eq 0 ] [[ ! "$output" =~ "test-branch" ]] || false [[ ! "$output" =~ "remotes/test-remote/test-branch" ]] || false cd repo1 dolt checkout -b test-branch dolt sql -q "INSERT INTO test VALUES (1);" dolt commit -am "test commit" dolt push test-remote test-branch cd ../repo2 dolt fetch test-remote run dolt branch [[ ! "$output" =~ "test-branch" ]] || false run dolt sql << SQL call dolt_checkout('test-branch'); SELECT * FROM test; call dolt_pull(); SQL [ "$status" -eq 0 ] [[ "$output" =~ "pk" ]] || false [[ "$output" =~ "1" ]] || false run dolt branch [[ "$output" =~ "test-branch" ]] || false dolt checkout test-branch run dolt status [ "$status" -eq 0 ] [[ "$output" =~ "Your branch is up to date with 'test-remote/test-branch'." ]] || false } @test "remotes: select 'DOLT_CHECKOUT('-b','new_branch') should not set upstream if there is a remote branch with matching name" { mkdir remote mkdir repo1 cd repo1 dolt init dolt remote add origin file://../remote dolt sql -q "CREATE TABLE a (pk int)" dolt add . dolt commit -am "add table a" dolt push --set-upstream origin main dolt checkout -b other dolt push --set-upstream origin other cd .. dolt clone file://./remote repo2 cd repo2 dolt branch [[ ! "$output" =~ "other" ]] || false # Checkout with DOLT_CHECKOUT and confirm the table has the row added in the remote run dolt sql << SQL call dolt_checkout('-b','other'); call dolt_pull(); SQL [ "$status" -eq 1 ] [[ "$output" =~ "There is no tracking information for the current branch." ]] || false } @test "remotes: add a remote using dolt remote" { run dolt remote add test-remote http://localhost:50051/test-org/test-repo [ "$status" -eq 0 ] [ "$output" = "" ] run dolt remote -v [ "$status" -eq 0 ] [[ "$output" =~ "test-remote" ]] || false run dolt remote add test-remote [ "$status" -eq 1 ] [[ "$output" =~ "usage:" ]] || false } @test "remotes: remove a remote" { dolt remote add test-remote http://localhost:50051/test-org/test-repo run dolt remote remove test-remote [ "$status" -eq 0 ] [ "$output" = "" ] run dolt remote -v [ "$status" -eq 0 ] [[ ! "$output" =~ "test-remote" ]] || false run dolt remote remove poop [ "$status" -eq 1 ] [[ "$output" =~ "unknown remote: 'poop'" ]] || false } @test "remotes: clone a remote" { dolt remote add test-remote http://localhost:50051/test-org/test-repo dolt sql < LICENSE.md dolt docs upload LICENSE.md LICENSE.md echo "readme-text" > README.md dolt docs upload README.md README.md dolt add . dolt commit -m "test doc commit" dolt push test-remote main cd "dolt-repo-clones" run dolt clone http://localhost:50051/test-org/test-repo [ "$status" -eq 0 ] [[ "$output" =~ "cloning http://localhost:50051/test-org/test-repo" ]] || false cd test-repo run dolt log [ "$status" -eq 0 ] [[ "$output" =~ "test doc commit" ]] || false run dolt status [ "$status" -eq 0 ] [[ ! "$output" =~ "LICENSE.md" ]] || false [[ ! "$output" =~ "README.md" ]] || false dolt docs print LICENSE.md > LICENSE.md dolt docs print README.md > README.md run ls [ "$status" -eq 0 ] [[ "$output" =~ "LICENSE.md" ]] || false [[ "$output" =~ "README.md" ]] || false run cat LICENSE.md [ "$status" -eq 0 ] [[ "$output" =~ "license-text" ]] || false run cat README.md [ "$status" -eq 0 ] [[ "$output" =~ "readme-text" ]] || false } @test "remotes: clone an empty remote" { run dolt clone http://localhost:50051/test-org/empty [ "$status" -eq 1 ] [[ "$output" =~ "clone failed" ]] || false [[ "$output" =~ "remote at that url contains no Dolt data" ]] || false } @test "remotes: clone a non-existent remote" { dolt remote add test-remote http://localhost:50051/test-org/test-repo cd "dolt-repo-clones" run dolt clone http://localhost:50051/foo/bar [ "$status" -eq 1 ] [[ "$output" =~ "clone failed" ]] || false [[ "$output" =~ "remote at that url contains no Dolt data" ]] || false } @test "remotes: clone a different branch than main" { dolt remote add test-remote http://localhost:50051/test-org/test-repo dolt checkout -b test-branch dolt sql < LICENSE.md dolt docs upload LICENSE.md LICENSE.md echo "initial-readme" > README.md dolt docs upload README.md README.md dolt add . dolt commit -m "initial doc commit" dolt remote add test-remote http://localhost:50051/test-org/test-repo dolt push test-remote main run dolt fetch test-remote [ "$status" -eq 0 ] [ "$output" != "" ] # spinner output run cat README.md [ "$status" -eq 0 ] [[ "$output" =~ "initial-readme" ]] || false run cat LICENSE.md [ "$status" -eq 0 ] [[ "$output" =~ "initial-license" ]] || false # Clone the initial docs/repo into dolt-repo-clones/test-repo cd "dolt-repo-clones" run dolt clone http://localhost:50051/test-org/test-repo cd test-repo dolt docs print LICENSE.md > LICENSE.md dolt docs print README.md > README.md run cat LICENSE.md [ "$status" -eq 0 ] [[ "$output" =~ "initial-license" ]] || false run cat README.md [ "$status" -eq 0 ] [[ "$output" =~ "initial-readme" ]] || false # Change the docs echo "dolt-repo-clones-license" > LICENSE.md dolt docs upload LICENSE.md LICENSE.md echo "dolt-repo-clones-readme" > README.md dolt docs upload README.md README.md dolt add . dolt commit -m "dolt-repo-clones updated docs" # Go back to original repo, and change the docs again cd ../../ echo "initial-license-updated" > LICENSE.md dolt docs upload LICENSE.md LICENSE.md echo "initial-readme-updated" > README.md dolt docs upload README.md README.md dolt add . dolt commit -m "update initial doc values in test-org/test-repo" # Go back to dolt-repo-clones/test-repo and fetch the test-remote cd dolt-repo-clones/test-repo run dolt fetch test-remote run cat LICENSE.md [ "$status" -eq 0 ] [[ "$output" =~ "dolt-repo-clones-license" ]] || false run cat README.md [ "$status" -eq 0 ] [[ "$output" =~ "dolt-repo-clones-readme" ]] || false } @test "remotes: dolt merge with origin/main syntax." { dolt remote add test-remote http://localhost:50051/test-org/test-repo dolt push test-remote main dolt fetch test-remote cd "dolt-repo-clones" dolt clone http://localhost:50051/test-org/test-repo cd .. dolt sql <