Match hunk edit format and upload build artifacts
This commit is contained in:
@@ -51,9 +51,7 @@ internal object InteractiveAddEngine {
|
||||
command = command,
|
||||
kind = GitEditorCommandKind.PATCH_HUNK,
|
||||
title = "Edit Patch Hunk",
|
||||
initialContent = patchHunkLines(file)
|
||||
.dropLastWhile { it == PatchHunkPrompt }
|
||||
.joinToString("\n"),
|
||||
initialContent = editablePatchHunkContent(file),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -208,21 +206,44 @@ internal object InteractiveAddEngine {
|
||||
}
|
||||
|
||||
private fun patchHunkLines(file: GitFile): List<String> {
|
||||
return patchDiffHeaderLines(file) + patchHunkBodyLines(file) + PatchHunkPrompt
|
||||
}
|
||||
|
||||
private fun editablePatchHunkContent(file: GitFile): String {
|
||||
return buildList {
|
||||
add("# Manual hunk edit mode -- see bottom for a quick guide.")
|
||||
addAll(patchHunkBodyLines(file))
|
||||
add("# ---")
|
||||
add("# To remove '-' lines, make them ' ' lines (context).")
|
||||
add("# To remove '+' lines, delete them.")
|
||||
add("# Lines starting with # will be removed.")
|
||||
add("# If the patch applies cleanly, the edited hunk will immediately be marked for staging.")
|
||||
add("# If it does not apply cleanly, you will be given an opportunity to")
|
||||
add("# edit again. If all lines of the hunk are removed, then the edit is")
|
||||
add("# aborted and the hunk is left unchanged.")
|
||||
}.joinToString("\n")
|
||||
}
|
||||
|
||||
private fun patchDiffHeaderLines(file: GitFile): List<String> {
|
||||
return listOf(
|
||||
"diff --git a/${file.name} b/${file.name}",
|
||||
"index 0000000..0000001 100644",
|
||||
"--- a/${file.name}",
|
||||
"+++ b/${file.name}",
|
||||
)
|
||||
}
|
||||
|
||||
private fun patchHunkBodyLines(file: GitFile): List<String> {
|
||||
val lines = file.content.lines()
|
||||
val nonEmptyLines = lines.dropLastWhile { it.isEmpty() }
|
||||
val addedCount = nonEmptyLines.size.coerceAtLeast(1)
|
||||
return buildList {
|
||||
add("diff --git a/${file.name} b/${file.name}")
|
||||
add("index 0000000..0000001 100644")
|
||||
add("--- a/${file.name}")
|
||||
add("+++ b/${file.name}")
|
||||
add("@@ -1 +1,$addedCount @@")
|
||||
if (nonEmptyLines.isEmpty()) {
|
||||
add("+")
|
||||
} else {
|
||||
nonEmptyLines.forEach { line -> add("+$line") }
|
||||
}
|
||||
add(PatchHunkPrompt)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user