Skip to content

Commit

Permalink
Fix GitRepository when origin url is a ssh url withouy username
Browse files Browse the repository at this point in the history
  • Loading branch information
arodus committed Oct 9, 2018
1 parent f2b740d commit cdc7672
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions source/Nuke.Common.Tests/GitRepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public class GitRepositoryTest
[InlineData("[email protected]/test/", "git.test.org", "test")]
[InlineData("[email protected]/test.git", "git.test.org", "test")]
[InlineData("ssh://[email protected]/test.git", "git.test.org", "test")]
[InlineData("ssh://[email protected]: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);
Expand Down
13 changes: 4 additions & 9 deletions source/Nuke.Common/Git/GitRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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@(?<endpoint>[^:/]+?)(:|/)(?<identifier>.+?)/?(\.git)?$",
@"^https?://([^:]+:[^:@]+@)?(?<endpoint>[^/]+?)/(?<identifier>.+?)/?(\.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);
}

Expand Down

0 comments on commit cdc7672

Please sign in to comment.