Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions go/libraries/doltcore/sqle/dprocedures/dolt_checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ func checkoutNewBranch(
}

// checkoutExistingBranch updates the active branch reference to point to an already existing branch.
// If the existing branch does not have a valid working set initialized yet, a
// doltdb.ErrWorkingSetNotFound error is returned.
func checkoutExistingBranch(
ctx *sql.Context,
dbName string,
Expand All @@ -510,6 +512,15 @@ func checkoutExistingBranch(
if apr.Contains(cli.MoveFlag) {
return doGlobalCheckout(ctx, branchName, apr.Contains(cli.ForceFlag), false)
} else {
// Ensure that the working set is available
ddb, ok := dSess.GetDoltDB(ctx, dbName)
if !ok {
return fmt.Errorf("could not load database %s", dbName)
}
if _, err = ddb.ResolveWorkingSet(ctx, wsRef); err != nil {
return err
}

err = dSess.SwitchWorkingSet(ctx, dbName, wsRef)
if err != nil {
return err
Expand Down
29 changes: 27 additions & 2 deletions integration-tests/bats/sql-server-remotesrv.bats
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,33 @@ call dolt_commit('-am', 'add some vals');
[[ "$output" =~ "10" ]] || false
}

# Asserts we can use dolt_checkout() to check out a new branch that was pushed to a running
# sql-server, and that the branch has a valid, writeable working set.
@test "sql-server-remotesrv: can checkout a new branch pushed to a sql-server remote" {
mkdir -p db/remote
cd db/remote
dolt init
dolt sql-server --remotesapi-port 50051 &
srv_pid=$!
cd ../..

# By cloning here, we have a near-at-hand way to wait for the server to be ready.
dolt clone http://localhost:50051/remote cloned_remote
cd cloned_remote

dolt checkout -b new_branch
dolt push origin new_branch

# Check out the new branch and do a test write
cd ../db/remote
run dolt sql -q "
CALL dolt_checkout('new_branch');
CREATE TABLE t123 (pk int primary key);
SELECT 'abcdefg';"
[ "$status" -eq 0 ]
[[ "$output" =~ "abcdefg" ]] || false
}

@test "sql-server-remotesrv: can access a created database from sql-server with --remotesapi-port" {
mkdir -p db/remote
cd db/remote
Expand Down Expand Up @@ -451,7 +478,6 @@ call dolt_commit('-am', 'add one val');"
! [[ "$output" =~ "zeek" ]] || false
}


@test "sql-server-remotesrv: push to remotesapi port as super user non-fast-forward" {
mkdir remote
cd remote
Expand Down Expand Up @@ -695,4 +721,3 @@ GRANT CLONE_ADMIN ON *.* TO clone_admin_user@'localhost';
[[ "$output" =~ "new_branch" ]] || false
[[ "$output" =~ "main" ]] || false
}

Loading