tests: add --summary consistency check to dolt diff ignore test

This commit is contained in:
elianddb
2026-03-31 18:46:43 +00:00
parent 7dd08afabb
commit 9f922eec92
2 changed files with 19 additions and 25 deletions

View File

@@ -111,10 +111,8 @@ type diffDatasets struct {
toRef string
}
// involvesWorkingSet reports whether either side of the diff is the working set or staging area.
// Ignore patterns from the dolt_ignore table apply to the staging of untracked tables, so they
// are relevant only when the working set is part of the diff.
func (d *diffDatasets) involvesWorkingSet() bool {
// hasWorkingSet reports whether either side of the diff references the working set or staging area.
func (d *diffDatasets) hasWorkingSet() bool {
return d.fromRef == doltdb.Working || d.toRef == doltdb.Working ||
d.fromRef == doltdb.Staged || d.toRef == doltdb.Staged
}
@@ -914,10 +912,10 @@ func diffUserTables(queryist cli.Queryist, sqlCtx *sql.Context, dArgs *diffArgs)
return printDiffSummary(sqlCtx, deltas, dArgs)
}
// Load ignore patterns only when the diff includes the working set or staging area.
// Ignore patterns apply to the staging of untracked tables, not to committed history.
// Ignore patterns govern the staging of untracked tables and do not apply to committed history,
// so they are only loaded when the diff references the working set or staging area.
var ignoredTablePatterns doltdb.IgnorePatterns
if dArgs.involvesWorkingSet() {
if dArgs.hasWorkingSet() {
ignoredTablePatterns, err = getIgnoredTablePatternsFromSql(queryist, sqlCtx)
if err != nil {
return errhand.VerboseErrorFromError(fmt.Errorf("couldn't get ignored table patterns, cause: %w", err))
@@ -935,8 +933,8 @@ func diffUserTables(queryist cli.Queryist, sqlCtx *sql.Context, dArgs *diffArgs)
continue
}
// Skip tables that were added or dropped if they match an ignore pattern. The dolt_ignore
// table governs the staging of new tables and does not apply to existing tracked tables.
// Ignore patterns apply only to newly added or dropped tables. Modifications to already
// tracked tables are always shown regardless of the current dolt_ignore contents.
if delta.IsAdd() {
ignoreResult, err := ignoredTablePatterns.IsTableNameIgnored(delta.ToTableName)
if err != nil {

View File

@@ -516,48 +516,44 @@ SQL
}
@test "ignore: dolt show should display committed tables even after they are added to dolt_ignore" {
# Stage and commit the_table. It does not match any ignore pattern in the test setup,
# so it stages without --force.
dolt sql -q "CREATE TABLE the_table (pk INT PRIMARY KEY, name TEXT);"
dolt add the_table
dolt commit -m "add the_table"
# Verify the diff appears in the commit before the ignore pattern is added.
run dolt show HEAD
[ "$status" -eq 0 ]
[[ "$output" =~ "diff --dolt a/the_table b/the_table" ]] || false
# The test setup includes a "*_ignore" pattern that matches "dolt_ignore" itself,
# so --force is required to stage dolt_ignore.
# The setup adds a "*_ignore" pattern which matches "dolt_ignore" itself, so staging
# dolt_ignore requires --force.
dolt sql -q "INSERT INTO dolt_ignore VALUES ('the_table', true);"
dolt add --force dolt_ignore
dolt commit -m "ignore the_table"
# Use --summary to verify the_table is present in the commit.
# Confirm the_table is recorded in the earlier commit.
run dolt show --summary HEAD~1
[ "$status" -eq 0 ]
[[ "$output" =~ "the_table" ]] || false
# The commit predates the ignore pattern, so its diff must show the_table.
# the_table was committed before the ignore pattern existed, so its diff must still appear.
run dolt show HEAD~1
[ "$status" -eq 0 ]
[[ "$output" =~ "diff --dolt a/the_table b/the_table" ]] || false
}
@test "ignore: dolt diff should display committed tables even after they are added to dolt_ignore" {
# Stage and commit the_table. It does not match any ignore pattern in the test setup,
# so it stages without --force.
dolt sql -q "CREATE TABLE the_table (pk INT PRIMARY KEY, name TEXT);"
dolt add the_table
dolt commit -m "add the_table"
# The test setup includes a "*_ignore" pattern that matches "dolt_ignore" itself,
# so --force is required to stage dolt_ignore.
# The setup adds a "*_ignore" pattern which matches "dolt_ignore" itself, so staging
# dolt_ignore requires --force.
dolt sql -q "INSERT INTO dolt_ignore VALUES ('the_table', true);"
dolt add --force dolt_ignore
dolt commit -m "ignore the_table"
# The commit predates the ignore pattern, so the diff between the two commits must show the_table.
# Confirm the_table is recorded in the earlier commit.
run dolt diff --summary HEAD~2 HEAD~1
[ "$status" -eq 0 ]
[[ "$output" =~ "the_table" ]] || false
# the_table was committed before the ignore pattern existed, so its diff must still appear.
run dolt diff HEAD~2 HEAD~1
[ "$status" -eq 0 ]
[[ "$output" =~ "diff --dolt a/the_table b/the_table" ]] || false