Skip to content
Open
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
9 changes: 9 additions & 0 deletions go/cmd/dolt/commands/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os/signal"
"path/filepath"
"strings"
"sync"
"syscall"
"time"

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -411,6 +414,12 @@ func queryMode(
return sqlHandleVErrAndExitCode(qryist, errhand.VerboseErrorFromError(err), usage)
}

if strings.Contains(strings.ToLower(query), "dolt_checkout") {
Comment thread
superShen0916 marked this conversation as resolved.
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
}

Expand Down
8 changes: 8 additions & 0 deletions integration-tests/bats/sql.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down