Skip to content

Commit

Permalink
Detect short SSH URLs properly
Browse files Browse the repository at this point in the history
  • Loading branch information
geluk committed Feb 13, 2017
1 parent c76d0d9 commit 290c2ff
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pass-winmenu/src/ExternalPrograms/Git.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using LibGit2Sharp;
using PassWinmenu.Configuration;

Expand All @@ -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()
Expand Down

0 comments on commit 290c2ff

Please sign in to comment.