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,36 +1,44 @@
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
namespace SourceGit.ViewModels {
public class CreateBranch : Popup {
namespace SourceGit.ViewModels
{
public class CreateBranch : Popup
{
[Required(ErrorMessage = "Branch name is required!")]
[RegularExpression(@"^[\w\-/\.]+$", ErrorMessage = "Bad branch name format!")]
[CustomValidation(typeof(CreateBranch), nameof(ValidateBranchName))]
public string Name {
public string Name
{
get => _name;
set => SetProperty(ref _name, value, true);
}
public object BasedOn {
public object BasedOn
{
get;
private set;
}
public bool CheckoutAfterCreated {
public bool CheckoutAfterCreated
{
get;
set;
} = true;
public bool AutoStash {
public bool AutoStash
{
get;
set;
} = true;
public CreateBranch(Repository repo, Models.Branch branch) {
public CreateBranch(Repository repo, Models.Branch branch)
{
_repo = repo;
_baseOnRevision = branch.FullName;
if (!branch.IsLocal && repo.Branches.Find(x => x.IsLocal && x.Name == branch.Name) == null) {
if (!branch.IsLocal && repo.Branches.Find(x => x.IsLocal && x.Name == branch.Name) == null)
{
Name = branch.Name;
}
@ -38,7 +46,8 @@ namespace SourceGit.ViewModels {
View = new Views.CreateBranch() { DataContext = this };
}
public CreateBranch(Repository repo, Models.Commit commit) {
public CreateBranch(Repository repo, Models.Commit commit)
{
_repo = repo;
_baseOnRevision = commit.SHA;
@ -46,7 +55,8 @@ namespace SourceGit.ViewModels {
View = new Views.CreateBranch() { DataContext = this };
}
public CreateBranch(Repository repo, Models.Tag tag) {
public CreateBranch(Repository repo, Models.Tag tag)
{
_repo = repo;
_baseOnRevision = tag.SHA;
@ -54,11 +64,13 @@ namespace SourceGit.ViewModels {
View = new Views.CreateBranch() { DataContext = this };
}
public static ValidationResult ValidateBranchName(string name, ValidationContext ctx) {
public static ValidationResult ValidateBranchName(string name, ValidationContext ctx)
{
var creator = ctx.ObjectInstance as CreateBranch;
if (creator == null) return new ValidationResult("Missing runtime context to create branch!");
foreach (var b in creator._repo.Branches) {
foreach (var b in creator._repo.Branches)
{
var test = b.IsLocal ? b.Name : $"{b.Remote}/{b.Name}";
if (test == name) return new ValidationResult("A branch with same name already exists!");
}
@ -66,27 +78,36 @@ namespace SourceGit.ViewModels {
return ValidationResult.Success;
}
public override Task<bool> Sure() {
public override Task<bool> Sure()
{
_repo.SetWatcherEnabled(false);
return Task.Run(() => {
if (CheckoutAfterCreated) {
return Task.Run(() =>
{
if (CheckoutAfterCreated)
{
bool needPopStash = false;
if (_repo.WorkingCopyChangesCount > 0) {
if (AutoStash) {
if (_repo.WorkingCopyChangesCount > 0)
{
if (AutoStash)
{
SetProgressDescription("Adding untracked changes...");
var succ = new Commands.Add(_repo.FullPath).Exec();
if (succ) {
if (succ)
{
SetProgressDescription("Stash local changes");
succ = new Commands.Stash(_repo.FullPath).Push("CREATE_BRANCH_AUTO_STASH");
}
if (!succ) {
if (!succ)
{
CallUIThread(() => _repo.SetWatcherEnabled(true));
return false;
}
needPopStash = true;
} else {
}
else
{
SetProgressDescription("Discard local changes...");
Commands.Discard.All(_repo.FullPath);
}
@ -95,11 +116,14 @@ namespace SourceGit.ViewModels {
SetProgressDescription($"Create new branch '{_name}'");
new Commands.Checkout(_repo.FullPath).Branch(_name, _baseOnRevision, SetProgressDescription);
if (needPopStash) {
if (needPopStash)
{
SetProgressDescription("Re-apply local changes...");
new Commands.Stash(_repo.FullPath).Pop("stash@{0}");
}
} else {
}
else
{
Commands.Branch.Create(_repo.FullPath, _name, _baseOnRevision);
}
@ -108,8 +132,8 @@ namespace SourceGit.ViewModels {
});
}
private Repository _repo = null;
private readonly Repository _repo = null;
private string _name = null;
private string _baseOnRevision = null;
private readonly string _baseOnRevision = null;
}
}
}