Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion go/libraries/doltcore/sqle/dtablefunctions/dolt_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,10 @@ func (ltf *LogTableFunction) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter

dbName := sess.Session.GetCurrentDatabase()
headRef, err := sess.CWBHeadRef(ctx, dbName)
if err != nil {
if err == doltdb.ErrOperationNotSupportedInDetachedHead {
// In detached HEAD state, we can still resolve commits without a branch ref
headRef = nil
} else if err != nil {
return nil, err
}

Expand Down
34 changes: 34 additions & 0 deletions go/libraries/doltcore/sqle/enginetest/dolt_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -4992,6 +4992,40 @@ var LogTableFunctionScriptTests = []queries.ScriptTest{
},
},
},
{
// https://github.com/dolthub/dolt/issues/9762
Name: "dolt_log function in detached head state",
SetUpScript: []string{
"CREATE TABLE test_table (id INT PRIMARY KEY, name VARCHAR(50));",
"CALL dolt_commit('-Am', 'create table');",
"CALL dolt_tag('mytag');",
"INSERT INTO test_table VALUES (1, 'test');",
"CALL dolt_commit('-Am', 'add data');",
"CALL dolt_tag('v2');",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "USE mydb/mytag;",
Expected: []sql.Row{},
},
{
Query: "SELECT COUNT(*) FROM dolt_log('mytag');",
Expected: []sql.Row{{2}},
},
{
Query: "USE mydb/v2;",
Expected: []sql.Row{},
},
{
Query: "SELECT COUNT(*) FROM dolt_log('v2');",
Expected: []sql.Row{{3}},
},
{
Query: "SELECT message FROM dolt_log('mytag') ORDER BY commit_order;",
Expected: []sql.Row{{"Initialize data repository"}, {"create table"}},
},
},
},
}

var BranchStatusTableFunctionScriptTests = []queries.ScriptTest{
Expand Down
Loading