Skip to content

Commit 94079e9

Browse files
committed
fix(model-server): fix master branch appearing in available branches after removal
The empty string got mapped to a BranchReference and resolved to the DEFAULT_BRANCH.
1 parent 5a75024 commit 94079e9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

model-server/src/main/kotlin/org/modelix/model/server/handlers/RepositoriesManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class RepositoriesManager(val client: LocalModelClient) : IRepositoriesManager {
181181
}
182182

183183
fun getBranchNames(repositoryId: RepositoryId): Set<String> {
184-
return store.getGenericStore()[branchListKey(repositoryId)]?.lines()?.toSet().orEmpty()
184+
return store.getGenericStore()[branchListKey(repositoryId)]?.ifEmpty { null }?.lines()?.toSet().orEmpty()
185185
}
186186

187187
override fun getBranches(repositoryId: RepositoryId): Set<BranchReference> {

model-server/src/test/kotlin/org/modelix/model/server/handlers/RepositoriesManagerTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ class RepositoriesManagerTest {
2626
store.close()
2727
}
2828

29+
@Test
30+
fun `deleting default branch works`() = runTest {
31+
val repoId = RepositoryId("branch-removal")
32+
initRepository(repoId)
33+
repoManager.removeBranches(repoId, setOf("master"))
34+
val branches = repoManager.getBranches(repoId)
35+
36+
assertTrue { branches.none { it.branchName == "master" } }
37+
}
38+
2939
@Test
3040
fun `repository data is removed when removing repository`() = runTest {
3141
val repoId = RepositoryId("abc")

0 commit comments

Comments
 (0)