Skip to content

Commit d691762

Browse files
committed
Improve newline handling in diff()
1 parent e910528 commit d691762

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

pipeline.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,23 @@ func diff(command string) ([]string, error) {
105105
return nil, fmt.Errorf("diff command failed: %v", err)
106106
}
107107

108-
trimmed := strings.Trim(output, " \t\r\v\f")
109-
if trimmed == "" {
108+
hasNewlines := strings.ContainsRune(output, '\n')
109+
output = strings.TrimRight(output, "\n")
110+
if output == "" {
110111
return []string{}, nil
111112
}
112113

113114
var fields []string
114-
if strings.Contains(trimmed, "\n") {
115-
for _, line := range strings.Split(trimmed, "\n") {
115+
if hasNewlines {
116+
for _, line := range strings.Split(output, "\n") {
116117
line = strings.TrimSpace(line)
117118
if line != "" {
118119
fields = append(fields, line)
119120
}
120121
}
121122
} else {
122-
fields = strings.Fields(trimmed)
123+
// Single line without newline — legacy compat for custom diff commands
124+
fields = strings.Fields(output)
123125
}
124126

125127
paths := make([]string, 0, len(fields))

0 commit comments

Comments
 (0)