Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 34 additions & 16 deletions commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ import (
)

type commitModel struct {
path string
editor *editor
diffVP viewport.Model
diffRaw string
diffReady bool
infoLines []string
infoRaw string
author string
date time.Time
people *peopleStore
width int
height int
saved bool
err error
diffFocus bool
path string
editor *editor
diffVP viewport.Model
diffRaw string
diffReady bool
diffFromGit bool
infoLines []string
infoRaw string
author string
date time.Time
people *peopleStore
width int
height int
saved bool
err error
diffFocus bool
}

func newCommitModel(path string) *commitModel {
Expand Down Expand Up @@ -109,7 +110,24 @@ func (m *commitModel) parseCommitFile(content string) {
if diffStart < len(lines) {
m.diffRaw = strings.Join(lines[diffStart:], "\n")
m.prepareDiffView()
} else {
m.loadDiffFromGit()
}
}

func (m *commitModel) loadDiffFromGit() {
cmd := exec.Command("git", "diff", "--cached", "--no-color")
output, err := cmd.Output()
if err != nil {
return
}
diff := strings.TrimSpace(string(output))
if diff == "" {
return
}
m.diffRaw = diff
m.diffFromGit = true
m.prepareDiffView()
}

func (m *commitModel) prepareDiffView() {
Expand Down Expand Up @@ -223,7 +241,7 @@ func (m *commitModel) save() tea.Cmd {
if m.infoRaw != "" {
content = content + "\n" + m.infoRaw + "\n"
}
if m.diffRaw != "" {
if m.diffRaw != "" && !m.diffFromGit {
content = content + m.diffRaw
}
if err := os.WriteFile(m.path, []byte(content), 0644); err != nil {
Expand Down
Loading