Skip to content

Commit bc1e4ec

Browse files
committed
add fix for detached head err on dolt_log(tag)
1 parent 544f298 commit bc1e4ec

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

go/libraries/doltcore/sqle/dtablefunctions/dolt_log.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,10 @@ func (ltf *LogTableFunction) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter
459459

460460
dbName := sess.Session.GetCurrentDatabase()
461461
headRef, err := sess.CWBHeadRef(ctx, dbName)
462-
if err != nil {
462+
if err == doltdb.ErrOperationNotSupportedInDetachedHead {
463+
// In detached HEAD state, we can still resolve commits without a branch ref
464+
headRef = nil
465+
} else if err != nil {
463466
return nil, err
464467
}
465468

go/libraries/doltcore/sqle/enginetest/dolt_queries.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4992,7 +4992,40 @@ var LogTableFunctionScriptTests = []queries.ScriptTest{
49924992
},
49934993
},
49944994
},
4995-
}
4995+
{
4996+
// https://github.com/dolthub/dolt/issues/9762
4997+
Name: "dolt_log function in detached head state",
4998+
SetUpScript: []string{
4999+
"CREATE TABLE test_table (id INT PRIMARY KEY, name VARCHAR(50));",
5000+
"CALL dolt_commit('-Am', 'create table');",
5001+
"CALL dolt_tag('mytag');",
5002+
"INSERT INTO test_table VALUES (1, 'test');",
5003+
"CALL dolt_commit('-Am', 'add data');",
5004+
"CALL dolt_tag('v2');",
5005+
},
5006+
Assertions: []queries.ScriptTestAssertion{
5007+
{
5008+
Query: "USE mydb/mytag;",
5009+
Expected: []sql.Row{},
5010+
},
5011+
{
5012+
Query: "SELECT COUNT(*) FROM dolt_log('mytag');",
5013+
Expected: []sql.Row{{2}},
5014+
},
5015+
{
5016+
Query: "USE mydb/v2;",
5017+
Expected: []sql.Row{},
5018+
},
5019+
{
5020+
Query: "SELECT COUNT(*) FROM dolt_log('v2');",
5021+
Expected: []sql.Row{{3}},
5022+
},
5023+
{
5024+
Query: "SELECT message FROM dolt_log('mytag') ORDER BY commit_order;",
5025+
Expected: []sql.Row{{"Initialize data repository"}, {"create table"}},
5026+
},
5027+
},
5028+
},}
49965029

49975030
var BranchStatusTableFunctionScriptTests = []queries.ScriptTest{
49985031
{

0 commit comments

Comments
 (0)