Warn users about lone dolt_checkout() in dolt sql -q#11012
Conversation
|
Hi @kevglynn, thanks for the contribution. Sorry for the delay in response! I like this idea, but the implementation requires parsing the query string an additional time. We already parse all queries in given to Please make that change and mention me when you have, and I'll take another look for merging. |
79644c6 to
ab8061f
Compare
|
@zachmu Thanks for the review! Good catch — I've refactored the implementation to eliminate the redundant parse. What changed:
No extra parse. Same observable behavior. Unit tests and BATS tests still pass. |
ab8061f to
d5ea106
Compare
Running `dolt sql -q "call dolt_checkout('branch')"` is a common
source of confusion because the branch change only persists for
the session that exits immediately after execution.
Detect when `dolt sql -q` is invoked with a single CALL
dolt_checkout() statement and print a warning to stderr suggesting
`dolt checkout <branch>` instead. Multi-statement queries are not
warned about since combining dolt_checkout() with other statements
in a single invocation is valid usage.
The detection reuses the already-parsed sqlparser.Statement from
execBatchMode via a batchExecInfo struct, avoiding a redundant
parse of the query string.
Closes dolthub#6876
Co-authored-by: Cursor <cursoragent@cursor.com>
d5ea106 to
f945af0
Compare
|
@zachmu Rebased onto latest main — the refactored implementation (using |
Summary
dolt sql -q "call dolt_checkout('branch')"is run as a single statement, print a yellow warning to stderr explaining that the branch change only persists for the current sessioncall dolt_checkout('branch'); select * from t) do NOT trigger the warning, since combiningdolt_checkout()with other statements in a single invocation is valid usagedolt checkout <branch>instead for persistent branch changesChanges
go/cmd/dolt/commands/sql.go: AddedwarnIfLoneDoltCheckout()andisLoneDoltCheckoutCall()— called fromqueryModebefore executing the querygo/cmd/dolt/commands/sql_test.go: AddedTestIsLoneDoltCheckoutCallwith 11 test cases (single call, uppercase, mixed case,-bflag, different procedures, multi-statement, empty, bad syntax)integration-tests/bats/sql-checkout.bats: Added 2 BATS integration tests — one confirming the warning appears for a lone checkout, one confirming it does NOT appear with multiple statementsTest plan
go test -run TestIsLoneDoltCheckoutCall ./cmd/dolt/commands/— all 11 cases passdolt_checkout(), does not appear for other procedures or multi-statement inputsql-checkoutsuiteCloses #6876