summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-06-01 21:38:16 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-06-01 22:20:30 +1000
commit5df27c61ed27afeffda50e527c8845ccb7570aca (patch)
tree0c8ad67ac81341c5c27529834a4a1e787acecd6c /pkg
parentc9136538b5cd2d86c90ed0921ba5f716f3cb6d85 (diff)
Apply correct styling to root commit in graph
The root commit is special in that it has no parents. So we need to add a pipe that's headed for a commit that doesn't actually exist i.e. the mythical empty tree commit. We're using the actual hash of that pseudo-commit, but it's not being read anywhere.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/gui/presentation/graph/graph.go11
-rw-r--r--pkg/gui/presentation/graph/graph_test.go12
2 files changed, 22 insertions, 1 deletions
diff --git a/pkg/gui/presentation/graph/graph.go b/pkg/gui/presentation/graph/graph.go
index 392af8984..65141946c 100644
--- a/pkg/gui/presentation/graph/graph.go
+++ b/pkg/gui/presentation/graph/graph.go
@@ -139,7 +139,7 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
// a traversed spot is one where a current pipe is starting on, ending on, or passing through
traversedSpots := set.New[int]()
- if len(commit.Parents) > 0 {
+ if len(commit.Parents) > 0 { // merge commit
newPipes = append(newPipes, &Pipe{
fromPos: pos,
toPos: pos,
@@ -148,6 +148,15 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
kind: STARTS,
style: getStyle(commit),
})
+ } else if len(commit.Parents) == 0 { // root commit
+ newPipes = append(newPipes, &Pipe{
+ fromPos: pos,
+ toPos: pos,
+ fromSha: commit.Sha,
+ toSha: models.EmptyTreeCommitHash,
+ kind: STARTS,
+ style: getStyle(commit),
+ })
}
traversedSpotsForContinuingPipes := set.New[int]()
diff --git a/pkg/gui/presentation/graph/graph_test.go b/pkg/gui/presentation/graph/graph_test.go
index 27ec8652b..834575d7b 100644
--- a/pkg/gui/presentation/graph/graph_test.go
+++ b/pkg/gui/presentation/graph/graph_test.go
@@ -509,6 +509,18 @@ func TestGetNextPipes(t *testing.T) {
{fromPos: 1, toPos: 1, fromSha: "d", toSha: "e", kind: STARTS, style: style.FgDefault},
},
},
+ {
+ prevPipes: []*Pipe{
+ {fromPos: 0, toPos: 0, fromSha: "a", toSha: "root", kind: TERMINATES, style: style.FgDefault},
+ },
+ commit: &models.Commit{
+ Sha: "root",
+ Parents: []string{},
+ },
+ expected: []*Pipe{
+ {fromPos: 1, toPos: 1, fromSha: "root", toSha: models.EmptyTreeCommitHash, kind: STARTS, style: style.FgDefault},
+ },
+ },
}
for _, test := range tests {