Skip to content

Commit

Permalink
fix(diff): fix file rename message formatting
Browse files Browse the repository at this point in the history
The diff simplifier was not correctly formatting the file rename message. This commit fixes the issue by adding "from" and "to" keywords to the message.
  • Loading branch information
phodal committed Jan 11, 2024
1 parent 8ea8b3f commit 2039103
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Expand Up @@ -97,7 +97,7 @@ class DiffSimplifier(val project: Project) {
continue
}

if (line.startsWith("--- /dev/null")) {
if (line.startsWith("---\t/dev/null")) {
index++
continue
}
Expand Down Expand Up @@ -129,7 +129,7 @@ class DiffSimplifier(val project: Project) {
if (nextLine.startsWith("rename to")) {
val from = line.substring("rename from ".length)
val to = nextLine.substring("rename to ".length)
destination.add("rename file $from $to")
destination.add("rename file from $from to $to")
// The next value will be "---" and the value after that will be "+++".
index += 4
continue
Expand Down Expand Up @@ -218,8 +218,11 @@ class DiffSimplifier(val project: Project) {
val nextLine = lines[index + 1]
if (nextLine.startsWith("+++")) {
// remove end date
val startLine = line.substring("--- a/".length).trim()
val withoutEnd = nextLine.substring("+++ b/".length, nextLine.indexOf("(date ")).trim()
val substringBefore = line.substringBefore("(revision")

val startLine = substringBefore
.substring("--- a/".length).trim()
val withoutEnd = nextLine.substring("+++ b/".length, nextLine.indexOf("(date")).trim()

if (startLine == withoutEnd) {
index += 2
Expand Down
Expand Up @@ -37,7 +37,7 @@ class DiffSimplifierTest {
val postProcess = DiffSimplifier.postProcess(diff)
assertEquals(
postProcess,
"""rename file server/src/main/kotlin/com/thoughtworks/archguard/code/module/domain/model/LeafManger.kt server/metric-service/src/main/kotlin/org/archguard/arch/LeafManger.kt""".trimMargin()
"""rename file from server/src/main/kotlin/com/thoughtworks/archguard/code/module/domain/model/LeafManger.kt to server/metric-service/src/main/kotlin/org/archguard/arch/LeafManger.kt""".trimMargin()
)
}

Expand Down Expand Up @@ -106,7 +106,7 @@ change import from com.thoughtworks.archguard.code.module.domain.dubbo.ServiceCo
val postProcess = DiffSimplifier.postProcess(code)
assertEquals(
postProcess,
"""rename file server/src/main/kotlin/com/thoughtworks/archguard/code/module/domain/model/LeafManger.kt server/metric-service/src/main/kotlin/org/archguard/arch/LeafManger.kt
"""rename file from server/src/main/kotlin/com/thoughtworks/archguard/code/module/domain/model/LeafManger.kt to server/metric-service/src/main/kotlin/org/archguard/arch/LeafManger.kt
change import from com.thoughtworks.archguard.code.module.domain.dubbo.ServiceConfig to org.archguard.protocol.dubbo.ServiceConfig"""
)
}
Expand Down

0 comments on commit 2039103

Please sign in to comment.