Dolt clean (#3440)

* Dolt clean

CLI and sql clean function. Clears untracked tables by finding the
difference betewen HEAD and the current working set and then deleting
the result.

Optionally specify `--dry-run` to avoid persisting the result root.

Optionally pass a list of table names to filter for deletion if
untracked.

* [ga-format-pr] Run go/utils/repofmt/format_repo.sh and go/Godeps/update.sh

* zach comments

* need clean func for proc

* fix andy's PR

Co-authored-by: max-hoffman <max-hoffman@users.noreply.github.com>
This commit is contained in:
Maximilian Hoffman
2022-05-17 18:38:24 -07:00
committed by GitHub
parent 5e333b0e8f
commit f4dd4c7d6b
20 changed files with 436 additions and 49 deletions
+7
View File
@@ -77,6 +77,7 @@ const (
CommitMessageArg = "message"
AuthorParam = "author"
ForceFlag = "force"
DryRunFlag = "dry-run"
SetUpstreamFlag = "set-upstream"
AllFlag = "all"
HardResetParam = "hard"
@@ -138,6 +139,12 @@ func CreateResetArgParser() *argparser.ArgParser {
return ap
}
func CreateCleanArgParser() *argparser.ArgParser {
ap := argparser.NewArgParser()
ap.SupportsFlag(DryRunFlag, "", "Tests removing untracked tables without modifying the working set.")
return ap
}
func CreateCheckoutArgParser() *argparser.ArgParser {
ap := argparser.NewArgParser()
ap.SupportsString(CheckoutCoBranch, "", "branch", "Create a new branch named {{.LessThan}}new_branch{{.GreaterThan}} and start it at {{.LessThan}}start_point{{.GreaterThan}}.")
+95
View File
@@ -0,0 +1,95 @@
// Copyright 2022 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package commands
import (
"context"
"io"
"github.com/dolthub/dolt/go/cmd/dolt/cli"
"github.com/dolthub/dolt/go/cmd/dolt/errhand"
"github.com/dolthub/dolt/go/libraries/doltcore/env"
"github.com/dolthub/dolt/go/libraries/doltcore/env/actions"
"github.com/dolthub/dolt/go/libraries/utils/argparser"
)
const (
DryrunCleanParam = "dry-run"
)
var cleanDocContent = cli.CommandDocumentationContent{
ShortDesc: "Deletes untracked working tables",
LongDesc: "{{.EmphasisLeft}}dolt clean [--dry-run]{{.EmphasisRight}}\n\n" +
"The default (parameterless) form clears the values for all untracked working {{.LessThan}}tables{{.GreaterThan}} ." +
"This command permanently deletes unstaged or uncommitted tables.\n\n" +
"The {{.EmphasisLeft}}--dry-run{{.EmphasisRight}} flag can be used to test whether the clean can succeed without " +
"deleting any tables from the current working set.\n\n" +
"{{.EmphasisLeft}}dolt clean [--dry-run] {{.LessThan}}tables{{.GreaterThan}}...{{.EmphasisRight}}\n\n" +
"If {{.LessThan}}tables{{.GreaterThan}} is specified, only those table names are considered for deleting.\n\n",
Synopsis: []string{
"[--dry-run]",
"[--dry-run] {{.LessThan}}tables{{.GreaterThan}}...",
},
}
type CleanCmd struct{}
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
func (cmd CleanCmd) Name() string {
return "clean"
}
// Description returns a description of the command
func (cmd CleanCmd) Description() string {
return "Remove untracked tables from working set."
}
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
func (cmd CleanCmd) CreateMarkdown(wr io.Writer, commandStr string) error {
ap := cli.CreateCleanArgParser()
return CreateMarkdown(wr, cli.GetCommandDocumentation(commandStr, cleanDocContent, ap))
}
func (cmd CleanCmd) ArgParser() *argparser.ArgParser {
return cli.CreateCleanArgParser()
}
// Exec executes the command
func (cmd CleanCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
ap := cli.CreateCleanArgParser()
help, usage := cli.HelpAndUsagePrinters(cli.GetCommandDocumentation(commandStr, cleanDocContent, ap))
apr := cli.ParseArgsOrDie(ap, args, help)
roots, err := dEnv.Roots(ctx)
if err != nil {
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
}
ws, err := dEnv.WorkingSet(ctx)
if err != nil {
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
}
roots, err = actions.CleanUntracked(ctx, roots, apr.Args, apr.Contains(DryrunCleanParam))
if err != nil {
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
}
err = dEnv.UpdateWorkingSet(ctx, ws.WithWorkingRoot(roots.Working).WithStagedRoot(roots.Staged).ClearMerge())
if err != nil {
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
}
return handleResetError(err, usage)
}
+1
View File
@@ -65,6 +65,7 @@ var doltCommand = cli.NewSubCommandHandler("dolt", "it's git for data", []cli.Co
commands.AddCmd{},
commands.DiffCmd{},
commands.ResetCmd{},
commands.CleanCmd{},
commands.CommitCmd{},
commands.SqlCmd{VersionStr: Version},
sqlserver.SqlServerCmd{VersionStr: Version},
+1 -1
View File
@@ -1055,7 +1055,7 @@ func (root *RootValue) RemoveTables(ctx context.Context, skipFKHandling bool, al
return nil, err
}
if a.IsEmpty() {
return nil, ErrTableNotFound
return nil, fmt.Errorf("%w: '%s'", ErrTableNotFound, name)
}
edits[i].name = name
}
+53
View File
@@ -17,6 +17,7 @@ package actions
import (
"context"
"errors"
"fmt"
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
"github.com/dolthub/dolt/go/libraries/doltcore/doltdocs"
@@ -272,3 +273,55 @@ func ValidateIsRef(ctx context.Context, cSpecStr string, ddb *doltdb.DoltDB, rsr
return true
}
// CleanUntracked deletes untracked tables from the working root.
// Evaluates untracked tables as: all working tables - all staged tables.
func CleanUntracked(ctx context.Context, roots doltdb.Roots, tables []string, dryrun bool) (doltdb.Roots, error) {
untrackedTables := make(map[string]struct{})
var err error
if len(tables) == 0 {
tables, err = roots.Working.GetTableNames(ctx)
if err != nil {
return doltdb.Roots{}, nil
}
}
for i := range tables {
name := tables[i]
_, _, err = roots.Working.GetTable(ctx, name)
if err != nil {
return doltdb.Roots{}, err
}
untrackedTables[name] = struct{}{}
}
// untracked tables = working tables - staged tables
headTblNames, err := roots.Staged.GetTableNames(ctx)
if err != nil {
return doltdb.Roots{}, err
}
for _, name := range headTblNames {
delete(untrackedTables, name)
}
delete(untrackedTables, doltdb.DocTableName)
newRoot := roots.Working
var toDelete []string
for t := range untrackedTables {
toDelete = append(toDelete, t)
}
newRoot, err = newRoot.RemoveTables(ctx, false, false, toDelete...)
if err != nil {
return doltdb.Roots{}, fmt.Errorf("failed to remove tables; %w", err)
}
if dryrun {
return roots, nil
}
roots.Working = newRoot
return roots, nil
}
@@ -0,0 +1,118 @@
// Copyright 2020 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package dfunctions
import (
"fmt"
"strings"
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/dolt/go/cmd/dolt/cli"
"github.com/dolthub/dolt/go/libraries/doltcore/env/actions"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
)
const DoltCleanFuncName = "dolt_clean"
// Deprecated: please use the version in the dprocedures package
type DoltCleanFunc struct {
children []sql.Expression
}
func (d DoltCleanFunc) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
args, err := getDoltArgs(ctx, row, d.Children())
if err != nil {
return 1, err
}
return DoDoltClean(ctx, args)
}
func DoDoltClean(ctx *sql.Context, args []string) (int, error) {
dbName := ctx.GetCurrentDatabase()
if len(dbName) == 0 {
return 1, fmt.Errorf("Empty database name.")
}
dSess := dsess.DSessFromSess(ctx.Session)
apr, err := cli.CreateCleanArgParser().Parse(args)
if err != nil {
return 1, err
}
// Get all the needed roots.
roots, ok := dSess.GetRoots(ctx, dbName)
if !ok {
return 1, fmt.Errorf("Could not load database %s", dbName)
}
roots, err = actions.CleanUntracked(ctx, roots, apr.Args, apr.ContainsAll(cli.DryRunFlag))
if err != nil {
return 1, fmt.Errorf("failed to clean; %w", err)
}
err = dSess.SetRoots(ctx, dbName, roots)
if err != nil {
return 1, err
}
return 0, nil
}
func (d DoltCleanFunc) Resolved() bool {
for _, child := range d.Children() {
if !child.Resolved() {
return false
}
}
return true
}
func (d DoltCleanFunc) String() string {
childrenStrings := make([]string, len(d.children))
for i, child := range d.children {
childrenStrings[i] = child.String()
}
return fmt.Sprintf("DOLT_CLEAN(%s)", strings.Join(childrenStrings, ","))
}
func (d DoltCleanFunc) Type() sql.Type {
return sql.Int8
}
func (d DoltCleanFunc) IsNullable() bool {
for _, child := range d.Children() {
if child.IsNullable() {
return true
}
}
return false
}
func (d DoltCleanFunc) Children() []sql.Expression {
return d.children
}
func (d DoltCleanFunc) WithChildren(children ...sql.Expression) (sql.Expression, error) {
return NewDoltCleanFunc(children...)
}
// Deprecated: please use the version in the dprocedures package
func NewDoltCleanFunc(args ...sql.Expression) (sql.Expression, error) {
return DoltCleanFunc{children: args}, nil
}
@@ -20,8 +20,8 @@ import (
"github.com/dolthub/go-mysql-server/sql"
)
// dolt_add is the stored procedure version of the function `dolt_add`.
func dolt_add(ctx *sql.Context, args ...string) (sql.RowIter, error) {
// doltAdd is the stored procedure version of the function `dolt_add`.
func doltAdd(ctx *sql.Context, args ...string) (sql.RowIter, error) {
res, err := dfunctions.DoDoltAdd(ctx, args)
if err != nil {
return nil, err
@@ -20,8 +20,8 @@ import (
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions"
)
// dolt_branch is the stored procedure version of the function `dolt_branch`.
func dolt_branch(ctx *sql.Context, args ...string) (sql.RowIter, error) {
// doltBranch is the stored procedure version of the function `dolt_branch`.
func doltBranch(ctx *sql.Context, args ...string) (sql.RowIter, error) {
res, err := dfunctions.DoDoltBranch(ctx, args)
if err != nil {
return nil, err
@@ -20,8 +20,8 @@ import (
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions"
)
// dolt_checkout is the stored procedure version of the function `dolt_checkout`.
func dolt_checkout(ctx *sql.Context, args ...string) (sql.RowIter, error) {
// doltCheckout is the stored procedure version of the function `dolt_checkout`.
func doltCheckout(ctx *sql.Context, args ...string) (sql.RowIter, error) {
res, err := dfunctions.DoDoltCheckout(ctx, args)
if err != nil {
return nil, err
@@ -0,0 +1,30 @@
// Copyright 2022 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package dprocedures
import (
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions"
)
// doltClean is the stored procedure version of the function `dolt_clean`.
func doltClean(ctx *sql.Context, args ...string) (sql.RowIter, error) {
res, err := dfunctions.DoDoltClean(ctx, args)
if err != nil {
return nil, err
}
return rowToIter(int64(res)), nil
}
@@ -20,8 +20,8 @@ import (
"github.com/dolthub/go-mysql-server/sql"
)
// dolt_commit is the stored procedure version of the functions `commit` and `dolt_commit`.
func dolt_commit(ctx *sql.Context, args ...string) (sql.RowIter, error) {
// doltCommit is the stored procedure version of the functions `commit` and `dolt_commit`.
func doltCommit(ctx *sql.Context, args ...string) (sql.RowIter, error) {
res, err := dfunctions.DoDoltCommit(ctx, args)
if err != nil {
return nil, err
@@ -20,8 +20,8 @@ import (
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions"
)
// dolt_fetch is the stored procedure version of the function `dolt_fetch`.
func dolt_fetch(ctx *sql.Context, args ...string) (sql.RowIter, error) {
// doltFetch is the stored procedure version of the function `dolt_fetch`.
func doltFetch(ctx *sql.Context, args ...string) (sql.RowIter, error) {
res, err := dfunctions.DoDoltFetch(ctx, args)
if err != nil {
return nil, err
@@ -20,8 +20,8 @@ import (
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions"
)
// dolt_merge is the stored procedure version of the functions `merge` and `dolt_merge`.
func dolt_merge(ctx *sql.Context, args ...string) (sql.RowIter, error) {
// doltMerge is the stored procedure version of the functions `merge` and `dolt_merge`.
func doltMerge(ctx *sql.Context, args ...string) (sql.RowIter, error) {
res, err := dfunctions.DoDoltMerge(ctx, args)
if err != nil {
return nil, err
@@ -20,8 +20,8 @@ import (
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions"
)
// dolt_pull is the stored procedure version of the function `dolt_pull`.
func dolt_pull(ctx *sql.Context, args ...string) (sql.RowIter, error) {
// doltPull is the stored procedure version of the function `dolt_pull`.
func doltPull(ctx *sql.Context, args ...string) (sql.RowIter, error) {
res, err := dfunctions.DoDoltPull(ctx, args)
if err != nil {
return nil, err
@@ -20,8 +20,8 @@ import (
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions"
)
// dolt_push is the stored procedure version of the function `dolt_push`.
func dolt_push(ctx *sql.Context, args ...string) (sql.RowIter, error) {
// doltPush is the stored procedure version of the function `dolt_push`.
func doltPush(ctx *sql.Context, args ...string) (sql.RowIter, error) {
res, err := dfunctions.DoDoltPush(ctx, args)
if err != nil {
return nil, err
@@ -20,8 +20,8 @@ import (
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions"
)
// dolt_reset is the stored procedure version of the function `dolt_reset`.
func dolt_reset(ctx *sql.Context, args ...string) (sql.RowIter, error) {
// doltReset is the stored procedure version of the function `dolt_reset`.
func doltReset(ctx *sql.Context, args ...string) (sql.RowIter, error) {
res, err := dfunctions.DoDoltReset(ctx, args)
if err != nil {
return nil, err
@@ -20,8 +20,8 @@ import (
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions"
)
// dolt_revert is the stored procedure version of the function `revert`.
func dolt_revert(ctx *sql.Context, args ...string) (sql.RowIter, error) {
// doltRevert is the stored procedure version of the function `revert` and `dolt_revert`.
func doltRevert(ctx *sql.Context, args ...string) (sql.RowIter, error) {
res, err := dfunctions.DoDoltRevert(ctx, nil, args)
if err != nil {
return nil, err
@@ -20,8 +20,8 @@ import (
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions"
)
// dolt_verify_constraints is the stored procedure version of the function `constraints_verify`.
func dolt_verify_constraints(ctx *sql.Context, args ...string) (sql.RowIter, error) {
// doltVerifyConstraints is the stored procedure version of the function `constraints_verify`.
func doltVerifyConstraints(ctx *sql.Context, args ...string) (sql.RowIter, error) {
res, err := dfunctions.DoDoltConstraintsVerify(ctx, false, args)
if err != nil {
return nil, err
@@ -29,8 +29,8 @@ func dolt_verify_constraints(ctx *sql.Context, args ...string) (sql.RowIter, err
return rowToIter(int64(res)), nil
}
// dolt_verify_all_constraints is the stored procedure version of the function `constraints_verify_all`.
func dolt_verify_all_constraints(ctx *sql.Context, args ...string) (sql.RowIter, error) {
// doltVerifyAllConstraints is the stored procedure version of the function `constraints_verify_all`.
func doltVerifyAllConstraints(ctx *sql.Context, args ...string) (sql.RowIter, error) {
res, err := dfunctions.DoDoltConstraintsVerify(ctx, true, args)
if err != nil {
return nil, err
+26 -24
View File
@@ -17,30 +17,32 @@ package dprocedures
import "github.com/dolthub/go-mysql-server/sql"
var DoltProcedures = []sql.ExternalStoredProcedureDetails{
{Name: "dolt_add", Schema: int64Schema("status"), Function: dolt_add},
{Name: "dolt_branch", Schema: int64Schema("status"), Function: dolt_branch},
{Name: "dolt_checkout", Schema: int64Schema("status"), Function: dolt_checkout},
{Name: "dolt_commit", Schema: stringSchema("hash"), Function: dolt_commit},
{Name: "dolt_fetch", Schema: int64Schema("success"), Function: dolt_fetch},
{Name: "dolt_merge", Schema: int64Schema("no_conflicts"), Function: dolt_merge},
{Name: "dolt_pull", Schema: int64Schema("no_conflicts"), Function: dolt_pull},
{Name: "dolt_push", Schema: int64Schema("success"), Function: dolt_push},
{Name: "dolt_reset", Schema: int64Schema("status"), Function: dolt_reset},
{Name: "dolt_revert", Schema: int64Schema("status"), Function: dolt_revert},
{Name: "dolt_verify_constraints", Schema: int64Schema("no_violations"), Function: dolt_verify_constraints},
{Name: "dolt_verify_all_constraints", Schema: int64Schema("no_violations"), Function: dolt_verify_all_constraints},
{Name: "dadd", Schema: int64Schema("status"), Function: dolt_add},
{Name: "dbranch", Schema: int64Schema("status"), Function: dolt_branch},
{Name: "dcheckout", Schema: int64Schema("status"), Function: dolt_checkout},
{Name: "dcommit", Schema: stringSchema("hash"), Function: dolt_commit},
{Name: "dfetch", Schema: int64Schema("success"), Function: dolt_fetch},
{Name: "dmerge", Schema: int64Schema("no_conflicts"), Function: dolt_merge},
{Name: "dpull", Schema: int64Schema("no_conflicts"), Function: dolt_pull},
{Name: "dpush", Schema: int64Schema("success"), Function: dolt_push},
{Name: "dreset", Schema: int64Schema("status"), Function: dolt_reset},
{Name: "drevert", Schema: int64Schema("status"), Function: dolt_revert},
{Name: "dverify_constraints", Schema: int64Schema("no_violations"), Function: dolt_verify_constraints},
{Name: "dverify_all_constraints", Schema: int64Schema("no_violations"), Function: dolt_verify_all_constraints},
{Name: "dolt_add", Schema: int64Schema("status"), Function: doltAdd},
{Name: "dolt_branch", Schema: int64Schema("status"), Function: doltBranch},
{Name: "dolt_checkout", Schema: int64Schema("status"), Function: doltCheckout},
{Name: "dolt_clean", Schema: int64Schema("status"), Function: doltClean},
{Name: "dolt_commit", Schema: stringSchema("hash"), Function: doltCommit},
{Name: "dolt_fetch", Schema: int64Schema("success"), Function: doltFetch},
{Name: "dolt_merge", Schema: int64Schema("no_conflicts"), Function: doltMerge},
{Name: "dolt_pull", Schema: int64Schema("no_conflicts"), Function: doltPull},
{Name: "dolt_push", Schema: int64Schema("success"), Function: doltPush},
{Name: "dolt_reset", Schema: int64Schema("status"), Function: doltReset},
{Name: "dolt_revert", Schema: int64Schema("status"), Function: doltRevert},
{Name: "dolt_verify_constraints", Schema: int64Schema("no_violations"), Function: doltVerifyConstraints},
{Name: "dolt_verify_all_constraints", Schema: int64Schema("no_violations"), Function: doltVerifyAllConstraints},
{Name: "dadd", Schema: int64Schema("status"), Function: doltAdd},
{Name: "dbranch", Schema: int64Schema("status"), Function: doltBranch},
{Name: "dcheckout", Schema: int64Schema("status"), Function: doltCheckout},
{Name: "dclean", Schema: int64Schema("status"), Function: doltClean},
{Name: "dcommit", Schema: stringSchema("hash"), Function: doltCommit},
{Name: "dfetch", Schema: int64Schema("success"), Function: doltFetch},
{Name: "dmerge", Schema: int64Schema("no_conflicts"), Function: doltMerge},
{Name: "dpull", Schema: int64Schema("no_conflicts"), Function: doltPull},
{Name: "dpush", Schema: int64Schema("success"), Function: doltPush},
{Name: "dreset", Schema: int64Schema("status"), Function: doltReset},
{Name: "drevert", Schema: int64Schema("status"), Function: doltRevert},
{Name: "dverify_constraints", Schema: int64Schema("no_violations"), Function: doltVerifyConstraints},
{Name: "dverify_all_constraints", Schema: int64Schema("no_violations"), Function: doltVerifyAllConstraints},
}
// stringSchema returns a non-nullable schema with all columns as LONGTEXT.
+81
View File
@@ -0,0 +1,81 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
skip_nbf_dolt_1
dolt sql <<SQL
CREATE TABLE test (
pk int primary key
);
SQL
dolt commit -a -m "Add a table"
}
teardown() {
assert_feature_version
teardown_common
}
@test "sql-clean: DOLT_CLEAN clears unstaged tables" {
# call proc
dolt sql -q "create table test2 (pk int primary key)"
run dolt sql -q "call dolt_clean()"
[ $status -eq 0 ]
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "On branch main" ]] || false
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
# call dproc
dolt sql -q "create table test2 (pk int primary key)"
run dolt sql -q "call dclean('--dry-run')"
[ $status -eq 0 ]
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "new table: test2" ]] || false
dolt sql -q "call dclean('test2')"
# dolt cli
dolt sql -q "create table test2 (pk int primary key)"
dolt sql -q "create table test3 (pk int primary key)"
dolt clean test3
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "new table: test2" ]] || false
[[ ! "$output" =~ "new table: test3" ]] || false
# don't touch staged root
dolt add test2
dolt clean
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "new table: test2" ]] || false
}
@test "sql-clean: DOLT_CLEAN unknown table name" {
dolt sql -q "create table test2 (pk int primary key)"
run dolt sql -q "call dclean('unknown')"
[ $status -eq 1 ]
[[ "$output" =~ "table not found: 'unknown'" ]] || false
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "new table: test2" ]] || false
run dolt clean unknown
[ $status -eq 1 ]
[[ "$output" =~ "table not found: 'unknown'" ]] || false
run dolt status
[ "$status" -eq 0 ]
[[ "$output" =~ "new table: test2" ]] || false
}