diff --git a/go/cmd/dolt/commands/sql.go b/go/cmd/dolt/commands/sql.go index 4a1101d562e..2b48d4dcb03 100644 --- a/go/cmd/dolt/commands/sql.go +++ b/go/cmd/dolt/commands/sql.go @@ -23,6 +23,7 @@ import ( "os/signal" "path/filepath" "strings" + "sync" "syscall" "time" @@ -74,6 +75,8 @@ If a server is running for the database in question, then the query will go thro var ErrMultipleDoltCfgDirs = errors.NewKind("multiple .doltcfg directories detected: '%s' and '%s'; pass one of the directories using option --doltcfg-dir") +var doltCheckoutWarned sync.Once + const ( QueryFlag = "query" FormatFlag = "result-format" @@ -411,6 +414,12 @@ func queryMode( return sqlHandleVErrAndExitCode(qryist, errhand.VerboseErrorFromError(err), usage) } + if strings.Contains(strings.ToLower(query), "dolt_checkout") { + doltCheckoutWarned.Do(func() { + cli.PrintErrf("warning: dolt_checkout() only affects the current session. To persist the branch change, include additional statements in the same -q invocation or use 'dolt checkout' instead.\n") + }) + } + return 0 } diff --git a/integration-tests/bats/sql.bats b/integration-tests/bats/sql.bats index 836405704bf..805f7f531ac 100755 --- a/integration-tests/bats/sql.bats +++ b/integration-tests/bats/sql.bats @@ -1855,6 +1855,14 @@ CALL dolt_checkout('feature-branch'); SQL } +@test "sql: DOLT_CHECKOUT warning is emitted once across multiple -q invocations" { + run dolt sql -q "call dolt_checkout('-b', 'feature-branch')" -q "call dolt_checkout('main')" + [ $status -eq 0 ] + + warning_count=$(printf '%s\n' "$output" | grep -c "warning: dolt_checkout() only affects the current session") + [ "$warning_count" -eq 1 ] +} + @test "sql: USE fake hash throws error" { dolt add .; dolt commit -m 'commit tables'