Skip to content

Commit

Permalink
fix reflog (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 20, 2023
1 parent 0fe43a2 commit 55c6c0e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions internal/store/reflog.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

type LogRecord struct {
Hash sha.SHA1
isHead bool
Head string
references []string
recType log.RecordType
message string
Expand Down Expand Up @@ -71,7 +71,7 @@ func (r *Reflog) load(rootGoitPath string, head *Head, refs *Refs) error {

// references
if head.Commit.Hash.Compare(hash) {
record.isHead = true
record.Head = color.GreenString(head.Reference)
}
branches := refs.getBranchesByHash(hash)
for _, branch := range branches {
Expand Down Expand Up @@ -115,10 +115,16 @@ func (r *Reflog) Show() {

var referenceString string
if len(record.references) > 0 {
referenceString = strings.Join(record.references, ", ")
var refsExceptHead []string
for _, ref := range record.references {
if ref != record.Head {
refsExceptHead = append(refsExceptHead, ref)
}
}
referenceString = strings.Join(refsExceptHead, ", ")
}
if record.isHead {
referenceString = color.BlueString("HEAD -> ") + referenceString
if record.Head != "" {
referenceString = color.BlueString("HEAD -> ") + fmt.Sprintf("%s, ", record.Head) + referenceString
}

if referenceString == "" {
Expand Down

0 comments on commit 55c6c0e

Please sign in to comment.