Skip to content

Commit 5d85602

Browse files
author
Oleksandr Dzhychko
authored
Merge pull request #611 from modelix/do-not-create-extra-empty-version-when-writing-on-branch
fix(model-client): do not create an empty version when making no chan…
2 parents 3e4f00b + 0b99c1a commit 5d85602

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

model-client/src/commonMain/kotlin/org/modelix/model/client2/ModelClientV2.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,9 @@ suspend fun <T> IModelClientV2.runWriteOnBranch(branchRef: BranchReference, body
542542
body(branch)
543543
}
544544
val (ops, newTree) = branch.getPendingChanges()
545+
if (ops.isEmpty()) {
546+
return result
547+
}
545548
val newVersion = CLVersion.createRegularVersion(
546549
id = client.getIdGenerator().generate(),
547550
author = client.getUserId(),

model-server/src/test/kotlin/org/modelix/model/server/ModelClientV2Test.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import org.modelix.model.api.ITree
2929
import org.modelix.model.api.PBranch
3030
import org.modelix.model.client2.ModelClientV2
3131
import org.modelix.model.client2.runWrite
32+
import org.modelix.model.client2.runWriteOnBranch
3233
import org.modelix.model.lazy.CLTree
3334
import org.modelix.model.lazy.CLVersion
3435
import org.modelix.model.lazy.RepositoryId
@@ -216,4 +217,24 @@ class ModelClientV2Test {
216217
}
217218
checkAllReferencedEntriesExistInStore(versionPulled.data!!)
218219
}
220+
221+
@Test
222+
fun `writing no data does not create empty versions`() = runTest {
223+
// Arrange
224+
val url = "http://localhost/v2"
225+
val modelClient = ModelClientV2.builder().url(url).client(client).build().also { it.init() }
226+
val repositoryId = RepositoryId("repo1")
227+
val branchId = repositoryId.getBranchReference("master")
228+
modelClient.initRepository(repositoryId)
229+
val versionAfterBeforeWrite = modelClient.pullIfExists(branchId)!!
230+
231+
// Act
232+
modelClient.runWriteOnBranch(branchId) {
233+
// do nothing
234+
}
235+
236+
// Assert
237+
val versionAfterRunWrite = modelClient.pullIfExists(branchId)!!
238+
assertEquals(versionAfterBeforeWrite.getContentHash(), versionAfterRunWrite.getContentHash())
239+
}
219240
}

0 commit comments

Comments
 (0)