Demonstrate that the graph continues the line below a root commit

If a root commit isn't the last one in the list, the graph draws a
vertical line below it in every row that follows, although nothing
comes after a root commit. This happens in repos with more than one
root commit, for example when showing all branches of a repo with a
gh-pages branch, or after merging an unrelated history.

Also, a commit that no line leads to is placed to the right of the
lines that ended in the row before it, although their columns are free
again.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-10-04 18:47:01 +02:00
co-authored by Claude Opus 5.5
parent 4dc619c081
commit cee602c029
+45
View File
@@ -94,6 +94,48 @@ func TestRenderCommitGraph(t *testing.T) {
5 ○───╯ │
6 ○ ╭───╯`,
},
{
name: "with a root commit followed by an unrelated history",
commitOpts: []models.NewCommitOpts{
{Hash: "1", Parents: []string{"2"}},
{Hash: "2"},
{Hash: "A", Parents: []string{"B"}},
{Hash: "B"},
},
/* EXPECTED:
expectedOutput: `
1 ○
2 ○
A ○
B ○`,
ACTUAL: */
expectedOutput: `
1 ○
2 ○
A │ ○
B │ ○`,
},
{
name: "with a merge of an unrelated history",
commitOpts: []models.NewCommitOpts{
{Hash: "1", Parents: []string{"2", "A"}},
{Hash: "2", Parents: []string{"3"}},
{Hash: "A"},
{Hash: "3"},
},
/* EXPECTED:
expectedOutput: `
1 ◎─╮
2 ○ │
A │ ○
3 ○`,
ACTUAL: */
expectedOutput: `
1 ◎─╮
2 ○ │
A │ ○
3 ○ │`,
},
{
name: "with a path that has room to move to the left and continues",
commitOpts: []models.NewCommitOpts{
@@ -528,6 +570,9 @@ func TestGetNextPipes(t *testing.T) {
Parents: []string{},
}),
expected: []Pipe{
/* EXPECTED:
{fromPos: 0, toPos: 0, fromHash: pool("root"), toHash: pool(models.EmptyTreeCommitHash), kind: STARTS, style: &style.FgDefault},
ACTUAL: */
{fromPos: 1, toPos: 1, fromHash: pool("root"), toHash: pool(models.EmptyTreeCommitHash), kind: STARTS, style: &style.FgDefault},
},
},