diff --git a/src/integTest/groovy/nebula/plugin/info/scm/GitScmProviderLauncherSpec.groovy b/src/integTest/groovy/nebula/plugin/info/scm/GitScmProviderLauncherSpec.groovy index b4d9173..2d594c8 100644 --- a/src/integTest/groovy/nebula/plugin/info/scm/GitScmProviderLauncherSpec.groovy +++ b/src/integTest/groovy/nebula/plugin/info/scm/GitScmProviderLauncherSpec.groovy @@ -2,7 +2,9 @@ package nebula.plugin.info.scm import nebula.plugin.info.GitSetupLauncherSpec import nebula.plugin.info.InfoBrokerPlugin +import org.eclipse.jgit.api.RemoteRemoveCommand import org.gradle.api.plugins.JavaPlugin +import spock.lang.Unroll class GitScmProviderLauncherSpec extends GitSetupLauncherSpec { @Override @@ -29,4 +31,25 @@ class GitScmProviderLauncherSpec extends GitSetupLauncherSpec { then: result.standardOutput.contains('Full-Change:') } + + @Unroll + def 'should normalize origin url'() { + given: "a git repository with a remote origin" + RemoteRemoveCommand remoteRemoveCommand = git.repository.jgit.remoteRemove() + remoteRemoveCommand.setRemoteName('origin') + remoteRemoveCommand.call() + git.remote.add(name: 'origin', url: url) + + when: "building the project" + def result = runTasks('build') + + then: "the origin url should be normalized" + result.standardOutput.contains('Module-Origin:https://something.com/repo.git,') + + where: + url << [ + 'https://something.com/repo.git', + 'https://something.com/repo' + ] + } } diff --git a/src/main/groovy/nebula/plugin/info/scm/GitScmProvider.groovy b/src/main/groovy/nebula/plugin/info/scm/GitScmProvider.groovy index 7f3414e..4441fdc 100644 --- a/src/main/groovy/nebula/plugin/info/scm/GitScmProvider.groovy +++ b/src/main/groovy/nebula/plugin/info/scm/GitScmProvider.groovy @@ -44,7 +44,8 @@ class GitScmProvider extends AbstractScmProvider { def user = url.getUserInfo().split(":").first() url = new URL(url.protocol, user + "@" + url.host, url.port, url.file) } - return url.toExternalForm() + String urlAsExternalForm = url.toExternalForm() + return urlAsExternalForm.endsWith('.git') ? url.toExternalForm() : urlAsExternalForm + ".git" } catch (MalformedURLException ignore) { return remoteOriginUrl }