Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions internal/ui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Quit
}
}
commitMessage = trimTrailingSpaces(commitMessage)
commitMessage = strings.ReplaceAll(commitMessage, "\n\n\n", "\n\n")

if m.yolo {
Expand Down Expand Up @@ -377,3 +378,11 @@ func (m *Model) Action() Action {
func (m *Model) CommitMessage() string {
return m.commitMessage
}

func trimTrailingSpaces(s string) string {
lines := strings.Split(s, "\n")
for i := range lines {
lines[i] = strings.TrimRight(lines[i], " \t\r")
}
return strings.Join(lines, "\n")
}
21 changes: 21 additions & 0 deletions internal/ui/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (m *MockGitClient) Commit(ctx context.Context, message string, skipCI, noVe
args := m.Called(ctx, message, skipCI, noVerify)
return args.Error(0)
}

func (m *MockGitClient) RecentCommits(ctx context.Context, count int) ([]string, error) {
args := m.Called(ctx, count)
return args.Get(0).([]string), args.Error(1)
Expand Down Expand Up @@ -418,3 +419,23 @@ func (m *mockTeaModel) View() tea.View {
}
return tea.NewView("")
}

func TestTrimTrailingSpaces(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{"no trailing spaces", "hello\nworld", "hello\nworld"},
{"trailing spaces on some lines", "hello \nworld \n ", "hello\nworld\n"},
{"tabs and carriage returns", "line1\t\r\nline2 \n", "line1\nline2\n"},
{"empty string", "", ""},
{"single line with space", "hello ", "hello"},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, trimTrailingSpaces(tt.input))
})
}
}
Loading