From 290c2ff372e40e73848d9caa31f3cf2e8d8e3c65 Mon Sep 17 00:00:00 2001 From: Johan Geluk Date: Mon, 13 Feb 2017 22:08:54 +0100 Subject: [PATCH] Detect short SSH URLs properly --- pass-winmenu/src/ExternalPrograms/Git.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pass-winmenu/src/ExternalPrograms/Git.cs b/pass-winmenu/src/ExternalPrograms/Git.cs index a755e26..4346327 100644 --- a/pass-winmenu/src/ExternalPrograms/Git.cs +++ b/pass-winmenu/src/ExternalPrograms/Git.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Linq; +using System.Text.RegularExpressions; using LibGit2Sharp; using PassWinmenu.Configuration; @@ -27,14 +28,22 @@ public Git(string repositoryPath) // Only use the SSH credentials provider if the remote URL is an SSH url. // If it's not, we're better off letting libgit figure out how to deal with it. - var uri = new Uri(repo.Network.Remotes[repo.Head.RemoteName].Url); - if (uri.Scheme == "ssh") + if (IsSshUrl(repo.Network.Remotes[repo.Head.RemoteName].Url)) { fetchOptions.CredentialsProvider = SshCredentialsProvider; pushOptions.CredentialsProvider = SshCredentialsProvider; } } + private static bool IsSshUrl(string url) + { + // Git considers 'user@server:project.git' to be a valid remote URL, but it's + // not actually a URL, so parsing it as one would fail. + // Therefore, we need to check for this condition first. + if (Regex.IsMatch(url, @".*@.*:.*")) return true; + else return new Uri(url).Scheme == "git"; + } + private Signature BuildSignature() => repo.Config.BuildSignature(DateTimeOffset.Now); public void Rebase()