Files
dolt/integration-tests/bats/sql-clean.bats
T
Maximilian Hoffman f4dd4c7d6b 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>
2022-05-17 18:38:24 -07:00

82 lines
1.9 KiB
Bash

#!/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
}