Skip to content

Commit c392e14

Browse files
authored
Merge pull request #194 from raboof/fix-invalid-.git-capture
Fix invalid .git capture
2 parents 457d8e7 + c5c539d commit c392e14

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ git.baseVersion := "1.0"
1515

1616
libraryDependencies ++= Seq(
1717
"org.eclipse.jgit" % "org.eclipse.jgit" % "5.11.0.202103091610-r",
18-
"com.michaelpollmeier" % "versionsort" % "1.0.0"
18+
"com.michaelpollmeier" % "versionsort" % "1.0.0",
19+
"org.scalameta" %% "munit" % "0.7.29" % Test
1920
)
2021

2122
scriptedLaunchOpts += s"-Dproject.version=${version.value}"

src/main/scala/com/typesafe/sbt/SbtGit.scala

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,30 +121,32 @@ object SbtGit {
121121
gitCurrentTags := gitReader.value.withGit(_.currentTags),
122122
gitCurrentBranch := Option(gitReader.value.withGit(_.branch)).getOrElse(""),
123123
gitUncommittedChanges in ThisBuild := gitReader.value.withGit(_.hasUncommittedChanges),
124-
scmInfo := {
125-
val user = """(?:[^@\/]+@)?"""
126-
val domain = """([^\/]+)"""
127-
val gitPath = """(.*)(?:\.git)?\/?"""
128-
val unauthenticated = raw"""(?:git|https?|ftps?)\:\/\/$domain\/$gitPath""".r
129-
val ssh = raw"""ssh\:\/\/$user$domain\/$gitPath""".r
130-
val headlessSSH = raw"""$user$domain:$gitPath""".r
131-
132-
def buildScmInfo(domain: String, repo: String) = Option(
133-
ScmInfo(
134-
url(s"https://$domain/$repo"),
135-
s"scm:git:https://$domain/$repo.git",
136-
Some(s"scm:git:git@$domain:$repo.git")
137-
)
124+
scmInfo := parseScmInfo(gitReader.value.withGit(_.remoteOrigin))
125+
)
126+
private[sbt] def parseScmInfo(remoteOrigin: String): Option[ScmInfo] = {
127+
val user = """(?:[^@\/]+@)?"""
128+
val domain = """([^\/]+)"""
129+
val gitPath = """(.*?)(?:\.git)?\/?$"""
130+
val unauthenticated = raw"""(?:git|https?|ftps?)\:\/\/$domain\/$gitPath""".r
131+
val ssh = raw"""ssh\:\/\/$user$domain\/$gitPath""".r
132+
val headlessSSH = raw"""$user$domain:$gitPath""".r
133+
134+
def buildScmInfo(domain: String, repo: String): Option[ScmInfo] = Option(
135+
ScmInfo(
136+
url(s"https://$domain/$repo"),
137+
s"scm:git:https://$domain/$repo.git",
138+
Some(s"scm:git:git@$domain:$repo.git")
138139
)
140+
)
139141

140-
gitReader.value.withGit(_.remoteOrigin) match {
141-
case unauthenticated(domain, repo) => buildScmInfo(domain,repo)
142-
case ssh(domain, repo) => buildScmInfo(domain,repo)
143-
case headlessSSH(domain, repo) => buildScmInfo(domain,repo)
144-
case _ => None
145-
}
142+
remoteOrigin match {
143+
case unauthenticated(domain, repo) => buildScmInfo(domain,repo)
144+
case ssh(domain, repo) => buildScmInfo(domain,repo)
145+
case headlessSSH(domain, repo) => buildScmInfo(domain,repo)
146+
case _ => None
146147
}
147-
)
148+
}
149+
148150
val projectSettings = Seq(
149151
// Input task to run git commands directly.
150152
commands += GitCommand.command
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.typesafe.sbt
2+
3+
import sbt.ScmInfo
4+
import sbt.url
5+
6+
class SbtGitSuite extends munit.FunSuite {
7+
val expectedScmInfo = Some(ScmInfo(
8+
browseUrl = url("https://github.com/akka/akka"),
9+
connection = "scm:git:https://github.com/akka/akka.git",
10+
devConnection = Some("scm:git:[email protected]:akka/akka.git")
11+
))
12+
13+
test("a git URL with the .git postfix") {
14+
assertEquals(SbtGit.parseScmInfo("[email protected]:akka/akka.git"), expectedScmInfo)
15+
}
16+
test("a git URL without the .git postfix") {
17+
assertEquals(SbtGit.parseScmInfo("[email protected]:akka/akka"), expectedScmInfo)
18+
}
19+
test("a https URL with the .git postfix") {
20+
assertEquals(SbtGit.parseScmInfo("https://github.com/akka/akka.git"), expectedScmInfo)
21+
}
22+
test("a https URL without the .git postfix") {
23+
assertEquals(SbtGit.parseScmInfo("https://github.com/akka/akka"), expectedScmInfo)
24+
}
25+
}

0 commit comments

Comments
 (0)