style: add .editorconfig for code formatting. see issu #25

This commit is contained in:
leo 2024-03-18 09:37:06 +08:00
parent a8eeea4f78
commit 18aaa0a143
225 changed files with 7781 additions and 3911 deletions

View file

@ -1,42 +1,52 @@
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
namespace SourceGit.ViewModels {
public class AddRemote : Popup {
namespace SourceGit.ViewModels
{
public class AddRemote : Popup
{
[Required(ErrorMessage = "Remote name is required!!!")]
[RegularExpression(@"^[\w\-\.]+$", ErrorMessage = "Bad remote name format!!!")]
[CustomValidation(typeof(AddRemote), nameof(ValidateRemoteName))]
public string Name {
public string Name
{
get => _name;
set => SetProperty(ref _name, value, true);
}
[Required(ErrorMessage = "Remote URL is required!!!")]
[CustomValidation(typeof(AddRemote), nameof(ValidateRemoteURL))]
public string Url {
public string Url
{
get => _url;
set {
set
{
if (SetProperty(ref _url, value, true)) UseSSH = Models.Remote.IsSSH(value);
}
}
public bool UseSSH {
public bool UseSSH
{
get => _useSSH;
set => SetProperty(ref _useSSH, value);
}
public string SSHKey {
public string SSHKey
{
get;
set;
}
public AddRemote(Repository repo) {
public AddRemote(Repository repo)
{
_repo = repo;
View = new Views.AddRemote() { DataContext = this };
}
public static ValidationResult ValidateRemoteName(string name, ValidationContext ctx) {
if (ctx.ObjectInstance is AddRemote add) {
public static ValidationResult ValidateRemoteName(string name, ValidationContext ctx)
{
if (ctx.ObjectInstance is AddRemote add)
{
var exists = add._repo.Remotes.Find(x => x.Name == name);
if (exists != null) return new ValidationResult("A remote with given name already exists!!!");
}
@ -44,8 +54,10 @@ namespace SourceGit.ViewModels {
return ValidationResult.Success;
}
public static ValidationResult ValidateRemoteURL(string url, ValidationContext ctx) {
if (ctx.ObjectInstance is AddRemote add) {
public static ValidationResult ValidateRemoteURL(string url, ValidationContext ctx)
{
if (ctx.ObjectInstance is AddRemote add)
{
if (!Models.Remote.IsValidURL(url)) return new ValidationResult("Bad remote URL format!!!");
var exists = add._repo.Remotes.Find(x => x.URL == url);
@ -55,22 +67,27 @@ namespace SourceGit.ViewModels {
return ValidationResult.Success;
}
public override Task<bool> Sure() {
public override Task<bool> Sure()
{
_repo.SetWatcherEnabled(false);
ProgressDescription = "Adding remote ...";
return Task.Run(() => {
return Task.Run(() =>
{
var succ = new Commands.Remote(_repo.FullPath).Add(_name, _url);
if (succ) {
if (succ)
{
SetProgressDescription("Fetching from added remote ...");
new Commands.Fetch(_repo.FullPath, _name, true, SetProgressDescription).Exec();
if (_useSSH) {
if (_useSSH)
{
SetProgressDescription("Post processing ...");
new Commands.Config(_repo.FullPath).Set($"remote.{_name}.sshkey", SSHKey);
}
}
CallUIThread(() => {
CallUIThread(() =>
{
_repo.MarkBranchesDirtyManually();
_repo.SetWatcherEnabled(true);
});
@ -78,9 +95,9 @@ namespace SourceGit.ViewModels {
});
}
private Repository _repo = null;
private readonly Repository _repo = null;
private string _name = string.Empty;
private string _url = string.Empty;
private bool _useSSH = false;
}
}
}