From 8050d5a2aba3adbbc93ba5a6e707826e2f2e1999 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 12 Oct 2020 09:58:39 +0800 Subject: [PATCH] fix: do NOT check remote name if only edit it's URL --- src/Helpers/Validations.cs | 9 ++++++--- src/UI/Remote.xaml.cs | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Helpers/Validations.cs b/src/Helpers/Validations.cs index a92425b7..04ba8319 100644 --- a/src/Helpers/Validations.cs +++ b/src/Helpers/Validations.cs @@ -31,6 +31,7 @@ namespace SourceGit.Helpers { /// public class RemoteNameRule : ValidationRule { public Git.Repository Repo { get; set; } + public Git.Remote Old { get; set; } public override ValidationResult Validate(object value, CultureInfo cultureInfo) { var regex = new Regex(@"^[\w\-\.]+$"); @@ -40,9 +41,11 @@ namespace SourceGit.Helpers { if (string.IsNullOrEmpty(name)) return new ValidationResult(false, "Remote name can NOT be null"); if (!regex.IsMatch(name)) return new ValidationResult(false, $"Bad name for remote. Regex: ^[\\w\\-\\.]+$"); - foreach (var t in remotes) { - if (t.Name == name) { - return new ValidationResult(false, $"Remote '{name}' already exists"); + if (Old == null || name != Old.Name) { + foreach (var t in remotes) { + if (t.Name == name) { + return new ValidationResult(false, $"Remote '{name}' already exists"); + } } } diff --git a/src/UI/Remote.xaml.cs b/src/UI/Remote.xaml.cs index c612eab5..4d675be2 100644 --- a/src/UI/Remote.xaml.cs +++ b/src/UI/Remote.xaml.cs @@ -30,6 +30,7 @@ namespace SourceGit.UI { InitializeComponent(); nameValidator.Repo = repo; + nameValidator.Old = remote; if (remote != null) { title.Content = "Edit Remote";