diff --git a/integration-tests/bats/reflog.bats b/integration-tests/bats/reflog.bats old mode 100644 new mode 100755 index 38d5a7e34e..d8906f4794 --- a/integration-tests/bats/reflog.bats +++ b/integration-tests/bats/reflog.bats @@ -1,45 +1,32 @@ #!/usr/bin/env bats load $BATS_TEST_DIRNAME/helper/common.bash +setup() { + setup_common +} + teardown() { assert_feature_version teardown_common } -# Asserts that when DOLT_DISABLE_REFLOG is set, the dolt_reflog() table -# function returns an empty result set with no error. +# Asserts that when DOLT_DISABLE_REFLOG is set, dolt reflog returns nothing with no error. @test "reflog: disabled with DOLT_DISABLE_REFLOG" { export DOLT_DISABLE_REFLOG=true - setup_common dolt sql -q "create table t (i int primary key, j int);" dolt sql -q "insert into t values (1, 1), (2, 2), (3, 3)"; dolt commit -Am "initial commit" dolt commit --allow-empty -m "test commit 1" - run dolt sql -q "select * from dolt_reflog();" + run dolt reflog [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] } -# Sanity check for the most basic case of querying the Dolt reflog -@test "reflog: enabled by default" { - setup_common - dolt sql -q "create table t (i int primary key, j int);" - dolt sql -q "insert into t values (1, 1), (2, 2), (3, 3)"; - dolt commit -Am "initial commit" - - run dolt sql -q "select * from dolt_reflog();" - [ "$status" -eq 0 ] - [ "${#lines[@]}" -eq 6 ] - [[ "$output" =~ "initial commit" ]] || false - [[ "$output" =~ "Initialize data repository" ]] || false -} - # Asserts that when DOLT_REFLOG_RECORD_LIMIT has been set, the reflog only contains the # most recent entries and is limited by the env var's value. @test "reflog: set DOLT_REFLOG_RECORD_LIMIT" { export DOLT_REFLOG_RECORD_LIMIT=2 - setup_common dolt sql -q "create table t (i int primary key, j int);" dolt sql -q "insert into t values (1, 1), (2, 2), (3, 3)"; dolt commit -Am "initial commit" @@ -47,10 +34,198 @@ teardown() { dolt commit --allow-empty -m "test commit 2" # Only the most recent two ref changes should appear in the log - run dolt sql -q "select * from dolt_reflog();" + run dolt reflog [ "$status" -eq 0 ] [[ "$output" =~ "test commit 1" ]] || false [[ "$output" =~ "test commit 2" ]] || false [[ ! "$output" =~ "initial commit" ]] || false [[ ! "$output" =~ "Initialize data repository" ]] || false } + +@test "reflog: simple reflog" { + dolt sql -q "create table t (i int primary key, j int);" + dolt sql -q "insert into t values (1, 1), (2, 2), (3, 3)"; + dolt commit -Am "initial commit" + + run dolt reflog + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 2 ] + out=$(echo "$output" | sed -E 's/\x1b\[[0-9;]*m//g') # remove special characters for color + [[ "$out" =~ "(HEAD -> main) HEAD@{0}: initial commit" ]] || false + [[ "$out" =~ "HEAD@{1}: Initialize data repository" ]] || false +} + +@test "reflog: reflog with ref given" { + dolt sql < main) HEAD@{0}: inserting row 1" ]] || false + [[ "$out" =~ "HEAD@{1}: creating table t1" ]] || false + [[ "$out" =~ "HEAD@{2}: Initialize data repository" ]] || false + + # ref is case-insensitive + run dolt reflog rEFs/heAdS/MAIN + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 3 ] + out=$(echo "$output" | sed -E 's/\x1b\[[0-9;]*m//g') # remove special characters for color + [[ "$out" =~ "(HEAD -> main) HEAD@{0}: inserting row 1" ]] || false + [[ "$out" =~ "HEAD@{1}: creating table t1" ]] || false + [[ "$out" =~ "HEAD@{2}: Initialize data repository" ]] || false + + run dolt reflog main + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 3 ] + out=$(echo "$output" | sed -E 's/\x1b\[[0-9;]*m//g') # remove special characters for color + [[ "$out" =~ "(HEAD -> main) HEAD@{0}: inserting row 1" ]] || false + [[ "$out" =~ "HEAD@{1}: creating table t1" ]] || false + [[ "$out" =~ "HEAD@{2}: Initialize data repository" ]] || false + + # ref is case-insensitive + run dolt reflog MaIn + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 3 ] + out=$(echo "$output" | sed -E 's/\x1b\[[0-9;]*m//g') # remove special characters for color + [[ "$out" =~ "(HEAD -> main) HEAD@{0}: inserting row 1" ]] || false + [[ "$out" =~ "HEAD@{1}: creating table t1" ]] || false + [[ "$out" =~ "HEAD@{2}: Initialize data repository" ]] || false + + run dolt reflog refs/heads/branch1 + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 3 ] + out=$(echo "$output" | sed -E 's/\x1b\[[0-9;]*m//g') # remove special characters for color + [[ "$out" =~ "(branch1) HEAD@{0}: inserting row 3" ]] || false + [[ "$out" =~ "HEAD@{1}: inserting row 2" ]] || false + [[ "$out" =~ "HEAD@{2}: inserting row 1" ]] || false + + run dolt reflog branch1 + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 3 ] + out=$(echo "$output" | sed -E 's/\x1b\[[0-9;]*m//g') # remove special characters for color + [[ "$out" =~ "(branch1) HEAD@{0}: inserting row 3" ]] || false + [[ "$out" =~ "HEAD@{1}: inserting row 2" ]] || false + [[ "$out" =~ "HEAD@{2}: inserting row 1" ]] || false + + run dolt reflog refs/tags/tag1 + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 2 ] + out=$(echo "$output" | sed -E 's/\x1b\[[0-9;]*m//g') # remove special characters for color + [[ "$out" =~ "(tag: tag1) HEAD@{0}: inserting row 3" ]] || false + [[ "$out" =~ "HEAD@{1}: inserting row 1" ]] || false + + # ref is case-insensitive + run dolt reflog Refs/tAGs/TaG1 + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 2 ] + out=$(echo "$output" | sed -E 's/\x1b\[[0-9;]*m//g') # remove special characters for color + [[ "$out" =~ "(tag: tag1) HEAD@{0}: inserting row 3" ]] || false + [[ "$out" =~ "HEAD@{1}: inserting row 1" ]] || false + + run dolt reflog tag1 + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 2 ] + out=$(echo "$output" | sed -E 's/\x1b\[[0-9;]*m//g') # remove special characters for color + [[ "$out" =~ "(tag: tag1) HEAD@{0}: inserting row 3" ]] || false + [[ "$out" =~ "HEAD@{1}: inserting row 1" ]] || false + + # ref is case-insensitive + run dolt reflog TAg1 + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 2 ] + out=$(echo "$output" | sed -E 's/\x1b\[[0-9;]*m//g') # remove special characters for color + [[ "$out" =~ "(tag: tag1) HEAD@{0}: inserting row 3" ]] || false + [[ "$out" =~ "HEAD@{1}: inserting row 1" ]] || false + + dolt branch -D branch1 + + run dolt reflog branch1 + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 3 ] + out=$(echo "$output" | sed -E 's/\x1b\[[0-9;]*m//g') # remove special characters for color + [[ "$out" =~ "(branch1) HEAD@{0}: inserting row 3" ]] || false + [[ "$out" =~ "HEAD@{1}: inserting row 2" ]] || false + [[ "$out" =~ "HEAD@{2}: inserting row 1" ]] || false + + dolt tag -d tag1 + run dolt reflog tag1 + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 2 ] + out=$(echo "$output" | sed -E 's/\x1b\[[0-9;]*m//g') # remove special characters for color + [[ "$out" =~ "(tag: tag1) HEAD@{0}: inserting row 3" ]] || false + [[ "$out" =~ "HEAD@{1}: inserting row 1" ]] || false +} + +@test "reflog: garbage collection with no newgen data" { + run dolt reflog + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 1 ] + out=$(echo "$output" | sed -E 's/\x1b\[[0-9;]*m//g') # remove special characters for color + [[ "$out" =~ "(HEAD -> main) HEAD@{0}: Initialize data repository" ]] || false + + dolt gc + + run dolt reflog + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 0 ] +} + +@test "reflog: garbage collection with newgen data" { + dolt sql < main) HEAD@{0}: inserting row 2" ]] || false + [[ "$out" =~ "HEAD@{1}: inserting row 1" ]] || false + [[ "$out" =~ "HEAD@{2}: creating table t1" ]] || false + [[ "$out" =~ "HEAD@{3}: Initialize data repository" ]] || false + + dolt gc + + run dolt reflog main + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 0 ] +} + +@test "reflog: too many arguments given" { + run dolt reflog foo bar + [ "$status" -eq 1 ] + [[ "$output" =~ "error: reflog has too many positional arguments" ]] +} + +@test "reflog: unknown ref returns nothing" { + dolt sql -q "create table t (i int primary key, j int);" + dolt sql -q "insert into t values (1, 1), (2, 2), (3, 3)"; + dolt commit -Am "initial commit" + + run dolt reflog foo + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 0 ] +} diff --git a/integration-tests/bats/sql-reflog.bats b/integration-tests/bats/sql-reflog.bats new file mode 100644 index 0000000000..bac628f016 --- /dev/null +++ b/integration-tests/bats/sql-reflog.bats @@ -0,0 +1,57 @@ +#!/usr/bin/env bats +load $BATS_TEST_DIRNAME/helper/common.bash + +setup() { + setup_common +} + +teardown() { + assert_feature_version + teardown_common +} + +# Asserts that when DOLT_DISABLE_REFLOG is set, the dolt_reflog() table +# function returns an empty result set with no error. +@test "sql-reflog: disabled with DOLT_DISABLE_REFLOG" { + export DOLT_DISABLE_REFLOG=true + dolt sql -q "create table t (i int primary key, j int);" + dolt sql -q "insert into t values (1, 1), (2, 2), (3, 3)"; + dolt commit -Am "initial commit" + dolt commit --allow-empty -m "test commit 1" + + run dolt sql -q "select * from dolt_reflog();" + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 0 ] +} + +# Sanity check for the most basic case of querying the Dolt reflog +@test "sql-reflog: enabled by default" { + dolt sql -q "create table t (i int primary key, j int);" + dolt sql -q "insert into t values (1, 1), (2, 2), (3, 3)"; + dolt commit -Am "initial commit" + + run dolt sql -q "select * from dolt_reflog();" + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 6 ] + [[ "$output" =~ "initial commit" ]] || false + [[ "$output" =~ "Initialize data repository" ]] || false +} + +# Asserts that when DOLT_REFLOG_RECORD_LIMIT has been set, the reflog only contains the +# most recent entries and is limited by the env var's value. +@test "sql-reflog: set DOLT_REFLOG_RECORD_LIMIT" { + export DOLT_REFLOG_RECORD_LIMIT=2 + dolt sql -q "create table t (i int primary key, j int);" + dolt sql -q "insert into t values (1, 1), (2, 2), (3, 3)"; + dolt commit -Am "initial commit" + dolt commit --allow-empty -m "test commit 1" + dolt commit --allow-empty -m "test commit 2" + + # Only the most recent two ref changes should appear in the log + run dolt sql -q "select * from dolt_reflog();" + [ "$status" -eq 0 ] + [[ "$output" =~ "test commit 1" ]] || false + [[ "$output" =~ "test commit 2" ]] || false + [[ ! "$output" =~ "initial commit" ]] || false + [[ ! "$output" =~ "Initialize data repository" ]] || false +}