| 54 | } |
| 55 | |
| 56 | func synthesizeNewFileDiff(path, content string) string { |
| 57 | lines := difflib.SplitLines(content) |
| 58 | var out string |
| 59 | out += "--- /dev/null\n" |
| 60 | out += "+++ " + path + " (new file)\n" |
| 61 | out += fmt.Sprintf("@@ -0,0 +1,%d @@\n", len(lines)) |
| 62 | for _, l := range lines { |
| 63 | out += "+" + l |
| 64 | // SplitLines preserves trailing newlines; if the last line lacked |
| 65 | // one, the next iteration would concatenate without a break. |
| 66 | } |
| 67 | if len(lines) > 0 && lines[len(lines)-1] != "" && lines[len(lines)-1][len(lines[len(lines)-1])-1] != '\n' { |
| 68 | out += "\n" |
| 69 | } |
| 70 | return out |
| 71 | } |