mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
feature<GitURL>: supports for providing user on the HTTP/HTTPS git URL
This commit is contained in:
parent
1c10d9a286
commit
697879b6a5
3 changed files with 20 additions and 19 deletions
|
@ -1,8 +1,6 @@
|
|||
using Microsoft.Win32;
|
||||
using SourceGit.Views.Validations;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
@ -13,11 +11,6 @@ namespace SourceGit.Views {
|
|||
/// 克隆
|
||||
/// </summary>
|
||||
public partial class Clone : Controls.Window {
|
||||
private static readonly Regex[] SSH_PROTOCOAL = new Regex[] {
|
||||
new Regex(@"^[\w\-]+@[\w\.\-]+(\:[0-9]+)?:[\w\-]+/[\w\-]+\.git$"),
|
||||
new Regex(@"^ssh://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-]+/[\w\-]+\.git$"),
|
||||
};
|
||||
|
||||
public string Uri { get; set; }
|
||||
public string Folder { get; set; }
|
||||
public string LocalName { get; set; }
|
||||
|
@ -118,14 +111,12 @@ namespace SourceGit.Views {
|
|||
}
|
||||
|
||||
private void OnUrlChanged(object sender, TextChangedEventArgs e) {
|
||||
foreach (var check in SSH_PROTOCOAL) {
|
||||
if (check.IsMatch(txtUrl.Text)) {
|
||||
rowSSHKey.Height = new GridLength(32, GridUnitType.Pixel);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
rowSSHKey.Height = new GridLength(0, GridUnitType.Pixel);
|
||||
var isSSHProtocal = Validations.GitURL.IsSSH(txtUrl.Text);
|
||||
if (isSSHProtocal) {
|
||||
rowSSHKey.Height = new GridLength(32, GridUnitType.Pixel);
|
||||
} else {
|
||||
rowSSHKey.Height = new GridLength(0, GridUnitType.Pixel);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCloseException(object s, RoutedEventArgs e) {
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace SourceGit.Views.Popups {
|
|||
InitializeComponent();
|
||||
|
||||
ruleName.Repo = repo;
|
||||
if (!string.IsNullOrEmpty(RemoteURL) && RemoteURL.StartsWith("git@")) {
|
||||
if (Validations.GitURL.IsSSH(RemoteURL)) {
|
||||
txtSSHKey.Text = new Commands.Config(repo.Path).Get($"remote.{remote.Name}.sshkey");
|
||||
} else {
|
||||
txtSSHKey.Text = "";
|
||||
|
@ -94,8 +94,8 @@ namespace SourceGit.Views.Popups {
|
|||
}
|
||||
|
||||
private void OnUrlChanged(object sender, TextChangedEventArgs e) {
|
||||
if (!string.IsNullOrEmpty(txtUrl.Text)) {
|
||||
rowSSHKey.Height = new GridLength(txtUrl.Text.StartsWith("git@") ? 32 : 0, GridUnitType.Pixel);
|
||||
if (Validations.GitURL.IsSSH(txtUrl.Text)) {
|
||||
rowSSHKey.Height = new GridLength(32, GridUnitType.Pixel);
|
||||
} else {
|
||||
rowSSHKey.Height = new GridLength(0, GridUnitType.Pixel);
|
||||
}
|
||||
|
|
|
@ -6,11 +6,21 @@ namespace SourceGit.Views.Validations {
|
|||
|
||||
public class GitURL : ValidationRule {
|
||||
private static readonly Regex[] VALID_FORMATS = new Regex[] {
|
||||
new Regex(@"^http[s]?://[\w\.\-]+(\:[0-9]+)?/[\w\-]+/[\w\-]+\.git$"),
|
||||
new Regex(@"^http[s]?://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-]+/[\w\-]+\.git$"),
|
||||
new Regex(@"^[\w\-]+@[\w\.\-]+(\:[0-9]+)?:[\w\-]+/[\w\-]+\.git$"),
|
||||
new Regex(@"^ssh://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-]+/[\w\-]+\.git$"),
|
||||
};
|
||||
|
||||
public static bool IsSSH(string url) {
|
||||
if (string.IsNullOrEmpty(url)) return false;
|
||||
|
||||
for (int i = 1; i < VALID_FORMATS.Length; i++) {
|
||||
if (VALID_FORMATS[i].IsMatch(url)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo) {
|
||||
string url = value as string;
|
||||
if (!string.IsNullOrEmpty(url)) {
|
||||
|
|
Loading…
Reference in a new issue