init: keep dots in detected repository names
This commit is contained in:
@@ -89,7 +89,7 @@ class InitCommand(
|
|||||||
if (url == null) return DetectedValues()
|
if (url == null) return DetectedValues()
|
||||||
|
|
||||||
if (url.startsWith("http")) {
|
if (url.startsWith("http")) {
|
||||||
val regex = Regex("""https?://(?:([^@]+)@)?([^/]+)/([^/]+)/([^/.]+)(?:\.git)?""")
|
val regex = Regex("""https?://(?:([^@]+)@)?([^/]+)/([^/]+)/(.+?)(?:\.git)?$""")
|
||||||
val match = regex.find(url)
|
val match = regex.find(url)
|
||||||
if (match != null) {
|
if (match != null) {
|
||||||
val (user, host, owner, repo) = match.destructured
|
val (user, host, owner, repo) = match.destructured
|
||||||
@@ -102,7 +102,7 @@ class InitCommand(
|
|||||||
}
|
}
|
||||||
} else if (url.contains("@") && url.contains(":")) {
|
} else if (url.contains("@") && url.contains(":")) {
|
||||||
// Assume SSH: git@host:owner/repo.git
|
// Assume SSH: git@host:owner/repo.git
|
||||||
val regex = Regex("""([^@]+)@([^:]+):([^/]+)/([^/.]+)(?:\.git)?""")
|
val regex = Regex("""([^@]+)@([^:]+):([^/]+)/(.+?)(?:\.git)?$""")
|
||||||
val match = regex.find(url)
|
val match = regex.find(url)
|
||||||
if (match != null) {
|
if (match != null) {
|
||||||
val (_, host, owner, repo) = match.destructured
|
val (_, host, owner, repo) = match.destructured
|
||||||
|
|||||||
@@ -109,6 +109,21 @@ class InitCommandTest : FunSpec() {
|
|||||||
projectContent shouldContain "repo: my-repo"
|
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") {
|
test("does not overwrite existing files") {
|
||||||
val tempDir = Files.createTempDirectory("werkator-init-test")
|
val tempDir = Files.createTempDirectory("werkator-init-test")
|
||||||
initCommand.workingDir = tempDir
|
initCommand.workingDir = tempDir
|
||||||
|
|||||||
Reference in New Issue
Block a user