add Commit.ParentRefName()

This commit is contained in:
Ryooooooga 2022-03-26 22:03:32 +09:00 committed by Jesse Duffield
parent 99ecc1cfdf
commit 30be50b641
4 changed files with 49 additions and 14 deletions

View file

@ -6,6 +6,9 @@ import (
"github.com/jesseduffield/lazygit/pkg/utils"
)
// Special commit hash for empty tree object
const EmptyTreeCommitHash = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
// Commit : A git commit
type Commit struct {
Sha string
@ -29,6 +32,17 @@ func (c *Commit) RefName() string {
return c.Sha
}
func (c *Commit) ParentRefName() string {
if c.IsFirstCommit() {
return EmptyTreeCommitHash
}
return c.RefName() + "^"
}
func (c *Commit) IsFirstCommit() bool {
return len(c.Parents) == 0
}
func (c *Commit) ID() string {
return c.RefName()
}