diff --git a/CHANGELOG.md b/CHANGELOG.md index b638a26ab..4a696cf72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [vNext] +- Fixed `GitRepository` when origin url is a ssh url without username. ## [0.10.3] / 2018-10-05 - Fixed `WinRelativePath` and `UnixRelativePath` to use correct separator diff --git a/source/Nuke.Common.Tests/GitRepositoryTest.cs b/source/Nuke.Common.Tests/GitRepositoryTest.cs index 9ac30c920..7575c646a 100644 --- a/source/Nuke.Common.Tests/GitRepositoryTest.cs +++ b/source/Nuke.Common.Tests/GitRepositoryTest.cs @@ -26,6 +26,12 @@ public class GitRepositoryTest [InlineData("git@git.test.org/test/", "git.test.org", "test")] [InlineData("git@git.test.org/test.git", "git.test.org", "test")] [InlineData("ssh://git@git.test.org/test.git", "git.test.org", "test")] + [InlineData("ssh://git@git.test.org:1234/test.git", "git.test.org", "test")] + [InlineData("ssh://git.test.org/test/test", "git.test.org", "test/test")] + [InlineData("ssh://git.test.org:1234/test/test", "git.test.org", "test/test")] + [InlineData("https://git.test.org:1234/test/test", "git.test.org", "test/test")] + [InlineData("git://git.test.org:1234/test/test", "git.test.org", "test/test")] + [InlineData("git://git.test.org/test/test", "git.test.org", "test/test")] public void FromUrlTest(string url, string endpoint, string identifier) { var repository = GitRepository.FromUrl(url); diff --git a/source/Nuke.Common/Git/GitRepository.cs b/source/Nuke.Common/Git/GitRepository.cs index 3c3d81071..c5e059126 100644 --- a/source/Nuke.Common/Git/GitRepository.cs +++ b/source/Nuke.Common/Git/GitRepository.cs @@ -61,15 +61,10 @@ public static GitRepository FromLocalDirectory(string directory, string branch = private static (string endpoint, string identifier) ParseUrl(string url) { - var match = new[] - { - @"git@(?[^:/]+?)(:|/)(?.+?)/?(\.git)?$", - @"^https?://([^:]+:[^:@]+@)?(?[^/]+?)/(?.+?)/?(\.git)?$" - } - .Select(x => Regex.Match(url.Trim(), x)) - .FirstOrDefault(x => x.Success); - ControlFlow.Assert(match != null, $"Url '{url}' could not be parsed."); - + var regex = new Regex(@"^(?'protocol'\w+\:\/\/)?(?>(?'user'.*)@)?(?'endpoint'[^\/:]+)(?>\:(?'port'\d+))?[\/:](?'identifier'.*?)\/?(?>\.git)?$"); + var match = regex.Match(url.Trim()); + + ControlFlow.Assert(match.Success, $"Url '{url}' could not be parsed."); return (match.Groups["endpoint"].Value, match.Groups["identifier"].Value); }