mirror of
https://github.com/dolthub/dolt.git
synced 2025-12-30 16:12:39 -06:00
Add BATS tests for dolt_ignore AS OF
This commit is contained in:
@@ -63,325 +63,64 @@ get_conflict_tables() {
|
||||
'
|
||||
}
|
||||
|
||||
@test "ignore: simple matches" {
|
||||
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE ignoreme (pk int);
|
||||
CREATE TABLE dontignore (pk int);
|
||||
CREATE TABLE nomatch (pk int);
|
||||
SQL
|
||||
|
||||
dolt add -A
|
||||
@test "ignore: allow using dolt_ignore with AS OF" {
|
||||
|
||||
staged=$(get_staged_tables)
|
||||
ignored=$(get_ignored_tables)
|
||||
dolt branch start
|
||||
|
||||
[[ ! -z $(echo "$ignored" | grep "ignoreme") ]] || false
|
||||
[[ ! -z $(echo "$staged" | grep "dontignore") ]] || false
|
||||
[[ ! -z $(echo "$staged" | grep "nomatch") ]] || false
|
||||
}
|
||||
|
||||
@test "ignore: specific overrides" {
|
||||
dolt sql -q "INSERT INTO dolt_ignore VALUES ('dolt_ignore', false)"
|
||||
dolt sql -q "INSERT INTO dolt_ignore VALUES ('test1', true)"
|
||||
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE please_ignore (pk int);
|
||||
CREATE TABLE please_ignore_too (pk int);
|
||||
CREATE TABLE do_not_ignore (pk int);
|
||||
CREATE TABLE commit_me (pk int);
|
||||
CREATE TABLE commit_me_not(pk int);
|
||||
SQL
|
||||
dolt add dolt_ignore
|
||||
dolt commit -m "Insert into dolt_ignore"
|
||||
|
||||
dolt add -A
|
||||
dolt sql -q "INSERT INTO dolt_ignore VALUES ('test2', true)"
|
||||
dolt add dolt_ignore
|
||||
|
||||
ignored=$(get_ignored_tables)
|
||||
staged=$(get_staged_tables)
|
||||
dolt sql -q "INSERT INTO dolt_ignore VALUES ('test3', true)"
|
||||
|
||||
[[ ! -z $(echo "$ignored" | grep "please_ignore") ]] || false
|
||||
[[ ! -z $(echo "$ignored" | grep "please_ignore_too") ]] || false
|
||||
[[ ! -z $(echo "$staged" | grep "do_not_ignore") ]] || false
|
||||
[[ ! -z $(echo "$staged" | grep "commit_me") ]] || false
|
||||
[[ ! -z $(echo "$ignored" | grep "commit_me_not") ]] || false
|
||||
}
|
||||
|
||||
@test "ignore: conflict" {
|
||||
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE commit_ignore (pk int);
|
||||
SQL
|
||||
|
||||
run dolt add -A
|
||||
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "the table commit_ignore matches conflicting patterns in dolt_ignore" ]] || false
|
||||
[[ "$output" =~ "ignored: *_ignore" ]] || false
|
||||
[[ "$output" =~ "not ignored: commit_*" ]] || false
|
||||
|
||||
}
|
||||
|
||||
@test "ignore: question mark" {
|
||||
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE test (pk int);
|
||||
CREATE TABLE test1 (pk int);
|
||||
CREATE TABLE test11 (pk int);
|
||||
SQL
|
||||
|
||||
dolt add -A
|
||||
|
||||
ignored=$(get_ignored_tables)
|
||||
staged=$(get_staged_tables)
|
||||
|
||||
[[ ! -z $(echo "$ignored" | grep "test$") ]] || false
|
||||
[[ ! -z $(echo "$ignored" | grep "test1$") ]] || false
|
||||
[[ ! -z $(echo "$staged" | grep "test11$") ]] || false
|
||||
}
|
||||
|
||||
@test "ignore: don't stash ignored tables" {
|
||||
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE ignoreme (pk int);
|
||||
SQL
|
||||
|
||||
run dolt stash -u
|
||||
run dolt sql -q "SELECT * FROM dolt_ignore AS OF 'WORKING'"
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "No local changes to save" ]] || false
|
||||
}
|
||||
[[ "$output" =~ "test1" ]] || false
|
||||
[[ "$output" =~ "test2" ]] || false
|
||||
[[ "$output" =~ "test3" ]] || false
|
||||
|
||||
@test "ignore: error when trying to stash table with dolt_ignore conflict" {
|
||||
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE commit_ignore (pk int);
|
||||
SQL
|
||||
|
||||
run dolt stash -u
|
||||
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "the table commit_ignore matches conflicting patterns in dolt_ignore" ]] || false
|
||||
[[ "$output" =~ "ignored: *_ignore" ]] || false
|
||||
[[ "$output" =~ "not ignored: commit_*" ]] || false
|
||||
}
|
||||
|
||||
@test "ignore: stash ignored and untracked tables when --all is passed" {
|
||||
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE ignoreme (pk int);
|
||||
CREATE TABLE dontignore (pk int);
|
||||
SQL
|
||||
|
||||
dolt stash -a
|
||||
|
||||
working=$(get_working_tables)
|
||||
ignored=$(get_ignored_tables)
|
||||
|
||||
[[ -z $(echo "$ignored" | grep "ignoreme") ]] || false
|
||||
[[ -z $(echo "$working" | grep "dontignore") ]] || false
|
||||
|
||||
dolt stash pop
|
||||
|
||||
working=$(get_working_tables)
|
||||
ignored=$(get_ignored_tables)
|
||||
|
||||
[[ ! -z $(echo "$ignored" | grep "ignoreme") ]] || false
|
||||
[[ ! -z $(echo "$working" | grep "dontignore") ]] || false
|
||||
}
|
||||
|
||||
@test "ignore: stash table with dolt_ignore conflict when --all is passed" {
|
||||
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE commit_ignore (pk int);
|
||||
SQL
|
||||
|
||||
dolt stash -a
|
||||
|
||||
conflicts=$(get_conflict_tables)
|
||||
|
||||
[[ -z $(echo "$conflicts" | grep "commit_ignore") ]] || false
|
||||
|
||||
dolt stash pop
|
||||
|
||||
conflicts=$(get_conflict_tables)
|
||||
|
||||
[[ ! -z $(echo "$conflicts" | grep "commit_ignore") ]] || false
|
||||
|
||||
}
|
||||
|
||||
@test "ignore: allow staging ignored tables if 'add --force' is supplied" {
|
||||
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE ignoreme (pk int);
|
||||
SQL
|
||||
|
||||
dolt add -A --force
|
||||
|
||||
staged=$(get_staged_tables)
|
||||
|
||||
[[ ! -z $(echo "$staged" | grep "ignoreme") ]] || false
|
||||
}
|
||||
|
||||
@test "ignore: don't auto-stage ignored tables" {
|
||||
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE ignoreme (pk int);
|
||||
CREATE TABLE nomatch (pk int);
|
||||
SQL
|
||||
|
||||
dolt commit -m "commit1" -A
|
||||
|
||||
run dolt show
|
||||
run dolt sql -q "SELECT * FROM dolt_ignore AS OF 'STAGED'"
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "test1" ]] || false
|
||||
[[ "$output" =~ "test2" ]] || false
|
||||
[[ ! "$output" =~ "test3" ]] || false
|
||||
|
||||
! [["$output" =~ "diff --dolt a/ignoreme b/ignoreme"]] || false
|
||||
|
||||
}
|
||||
|
||||
@test "ignore: dolt status doesn't show ignored tables when --ignored is not supplied" {
|
||||
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE ignoreme (pk int);
|
||||
CREATE TABLE nomatch (pk int);
|
||||
SQL
|
||||
|
||||
run dolt status
|
||||
run dolt sql -q "SELECT * FROM dolt_ignore AS OF 'HEAD'"
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "test1" ]] || false
|
||||
[[ ! "$output" =~ "test2" ]] || false
|
||||
[[ ! "$output" =~ "test3" ]] || false
|
||||
|
||||
[[ "$output" =~ "nomatch" ]] || false
|
||||
! [["$output" =~ "Ignored tables"]] || false
|
||||
! [["$output" =~ "ignoreme"]] || false
|
||||
|
||||
}
|
||||
|
||||
@test "ignore: dolt status shows ignored tables when --ignored is not supplied" {
|
||||
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE ignoreme (pk int);
|
||||
CREATE TABLE nomatch (pk int);
|
||||
SQL
|
||||
|
||||
run dolt status --ignored
|
||||
run dolt sql -q "SELECT * FROM dolt_ignore AS OF 'main'"
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "test1" ]] || false
|
||||
[[ ! "$output" =~ "test2" ]] || false
|
||||
[[ ! "$output" =~ "test3" ]] || false
|
||||
|
||||
[[ "$output" =~ "nomatch" ]] || false
|
||||
[[ "$output" =~ "Ignored tables" ]] || false
|
||||
[[ "$output" =~ "ignoreme" ]] || false
|
||||
|
||||
}
|
||||
|
||||
@test "ignore: don't display new but ignored tables in dolt diff" {
|
||||
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE ignoreme (pk int);
|
||||
CREATE TABLE nomatch (pk int);
|
||||
SQL
|
||||
|
||||
run dolt diff
|
||||
run dolt sql -q "SELECT * FROM dolt_ignore AS OF 'start'"
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "$output" =~ "test1" ]] || false
|
||||
[[ ! "$output" =~ "test2" ]] || false
|
||||
[[ ! "$output" =~ "test3" ]] || false
|
||||
|
||||
[[ "$output" =~ "nomatch" ]] || false
|
||||
! [["$output" =~ "ignoreme"]] || false
|
||||
}
|
||||
|
||||
@test "ignore: don't display new but ignored tables in reverse diff" {
|
||||
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE ignoreme (pk int);
|
||||
CREATE TABLE nomatch (pk int);
|
||||
SQL
|
||||
|
||||
run dolt diff -R
|
||||
run dolt sql -q "SELECT * FROM dolt_ignore AS OF 'HEAD^'"
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
[[ "$output" =~ "nomatch" ]] || false
|
||||
! [["$output" =~ "ignoreme"]] || false
|
||||
}
|
||||
|
||||
@test "ignore: DO display modified ignored tables in dolt diff after staging" {
|
||||
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE ignoreme (pk int);
|
||||
SQL
|
||||
|
||||
dolt add --force ignoreme
|
||||
|
||||
dolt sql <<SQL
|
||||
INSERT INTO ignoreme VALUES (1);
|
||||
SQL
|
||||
|
||||
run dolt diff
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
echo "$output"
|
||||
|
||||
[[ "$output" =~ "ignoreme" ]] || false
|
||||
}
|
||||
|
||||
@test "ignore: DO display modified ignored tables in reverse diff after staging" {
|
||||
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE ignoreme (pk int);
|
||||
SQL
|
||||
|
||||
dolt add --force ignoreme
|
||||
|
||||
dolt sql <<SQL
|
||||
INSERT INTO ignoreme VALUES (1);
|
||||
SQL
|
||||
|
||||
run dolt diff -R
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
echo "$output"
|
||||
|
||||
[[ "$output" =~ "ignoreme" ]] || false
|
||||
}
|
||||
|
||||
@test "ignore: DO display modified ignored tables in dolt diff after committing" {
|
||||
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE ignoreme (pk int);
|
||||
SQL
|
||||
|
||||
dolt add --force ignoreme
|
||||
dolt commit -m "commit1"
|
||||
|
||||
dolt sql <<SQL
|
||||
INSERT INTO ignoreme VALUES (1);
|
||||
SQL
|
||||
|
||||
run dolt diff
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
echo "$output"
|
||||
|
||||
[[ "$output" =~ "ignoreme" ]] || false
|
||||
}
|
||||
|
||||
@test "ignore: detect when equivalent patterns have different values" {
|
||||
|
||||
dolt sql <<SQL
|
||||
INSERT INTO dolt_ignore VALUES
|
||||
("**_test", true),
|
||||
("*_test", false),
|
||||
|
||||
("*_foo", true),
|
||||
("%_foo", false);
|
||||
CREATE TABLE a_test (pk int);
|
||||
CREATE TABLE a_foo (pk int);
|
||||
SQL
|
||||
|
||||
conflict=$(get_conflict_tables)
|
||||
|
||||
echo "$conflict"
|
||||
|
||||
[[ ! -z $(echo "$conflict" | grep "a_test") ]] || false
|
||||
[[ ! -z $(echo "$conflict" | grep "a_foo") ]] || false
|
||||
[[ ! "$output" =~ "test1" ]] || false
|
||||
[[ ! "$output" =~ "test2" ]] || false
|
||||
[[ ! "$output" =~ "test3" ]] || false
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user