From 0f9f119687e9b349996789fffd5b1622cb00e335 Mon Sep 17 00:00:00 2001 From: mhoennig Date: Sat, 5 Sep 2026 15:15:12 +0200 Subject: [PATCH] init: keep dots in detected repository names --- .../de/hoennig/werkator/commands/InitCommand.kt | 4 ++-- .../hoennig/werkator/commands/InitCommandTest.kt | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/de/hoennig/werkator/commands/InitCommand.kt b/src/main/kotlin/de/hoennig/werkator/commands/InitCommand.kt index f3c86f7..b9cbf44 100644 --- a/src/main/kotlin/de/hoennig/werkator/commands/InitCommand.kt +++ b/src/main/kotlin/de/hoennig/werkator/commands/InitCommand.kt @@ -89,7 +89,7 @@ class InitCommand( if (url == null) return DetectedValues() if (url.startsWith("http")) { - val regex = Regex("""https?://(?:([^@]+)@)?([^/]+)/([^/]+)/([^/.]+)(?:\.git)?""") + val regex = Regex("""https?://(?:([^@]+)@)?([^/]+)/([^/]+)/(.+?)(?:\.git)?$""") val match = regex.find(url) if (match != null) { val (user, host, owner, repo) = match.destructured @@ -102,7 +102,7 @@ class InitCommand( } } else if (url.contains("@") && url.contains(":")) { // Assume SSH: git@host:owner/repo.git - val regex = Regex("""([^@]+)@([^:]+):([^/]+)/([^/.]+)(?:\.git)?""") + val regex = Regex("""([^@]+)@([^:]+):([^/]+)/(.+?)(?:\.git)?$""") val match = regex.find(url) if (match != null) { val (_, host, owner, repo) = match.destructured diff --git a/src/test/kotlin/de/hoennig/werkator/commands/InitCommandTest.kt b/src/test/kotlin/de/hoennig/werkator/commands/InitCommandTest.kt index a2f289f..9705d0e 100644 --- a/src/test/kotlin/de/hoennig/werkator/commands/InitCommandTest.kt +++ b/src/test/kotlin/de/hoennig/werkator/commands/InitCommandTest.kt @@ -109,6 +109,21 @@ class InitCommandTest : FunSpec() { projectContent shouldContain "repo: my-repo" } + test("keeps dots in repository names") { + val tempDir = Files.createTempDirectory("werkator-init-test") + initCommand.workingDir = tempDir + + every { gitService.getTopLevel(tempDir) } returns tempDir + every { gitService.getOriginUrl(tempDir) } returns "https://git.example.org/mi/michael.hoennig.de.git" + + initCommand.run() + + val projectConfig = tempDir.resolve(".werkator.yml") + val projectContent = projectConfig.toFile().readText() + projectContent shouldContain "owner: mi" + projectContent shouldContain "repo: michael.hoennig.de" + } + test("does not overwrite existing files") { val tempDir = Files.createTempDirectory("werkator-init-test") initCommand.workingDir = tempDir