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

@ -2,24 +2,33 @@
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
namespace SourceGit.ViewModels {
public class Push : Popup {
public bool HasSpecifiedLocalBranch {
namespace SourceGit.ViewModels
{
public class Push : Popup
{
public bool HasSpecifiedLocalBranch
{
get;
private set;
}
[Required(ErrorMessage = "Local branch is required!!!")]
public Models.Branch SelectedLocalBranch {
public Models.Branch SelectedLocalBranch
{
get => _selectedLocalBranch;
set {
if (SetProperty(ref _selectedLocalBranch, value)) {
set
{
if (SetProperty(ref _selectedLocalBranch, value))
{
// If selected local branch has upstream branch. Try to find it's remote.
if (!string.IsNullOrEmpty(value.Upstream)) {
if (!string.IsNullOrEmpty(value.Upstream))
{
var branch = _repo.Branches.Find(x => x.FullName == value.Upstream);
if (branch != null) {
if (branch != null)
{
var remote = _repo.Remotes.Find(x => x.Name == branch.Remote);
if (remote != null && remote != _selectedRemote) {
if (remote != null && remote != _selectedRemote)
{
SelectedRemote = remote;
return;
}
@ -32,68 +41,84 @@ namespace SourceGit.ViewModels {
}
}
public List<Models.Branch> LocalBranches {
public List<Models.Branch> LocalBranches
{
get;
private set;
}
public List<Models.Remote> Remotes {
public List<Models.Remote> Remotes
{
get => _repo.Remotes;
}
[Required(ErrorMessage = "Remote is required!!!")]
public Models.Remote SelectedRemote {
public Models.Remote SelectedRemote
{
get => _selectedRemote;
set {
set
{
if (SetProperty(ref _selectedRemote, value)) AutoSelectBranchByRemote();
}
}
public List<Models.Branch> RemoteBranches {
public List<Models.Branch> RemoteBranches
{
get => _remoteBranches;
private set => SetProperty(ref _remoteBranches, value);
}
[Required(ErrorMessage = "Remote branch is required!!!")]
public Models.Branch SelectedRemoteBranch {
public Models.Branch SelectedRemoteBranch
{
get => _selectedRemoteBranch;
set => SetProperty(ref _selectedRemoteBranch, value);
}
public bool PushAllTags {
public bool PushAllTags
{
get;
set;
}
public bool ForcePush {
public bool ForcePush
{
get;
set;
}
public Push(Repository repo, Models.Branch localBranch) {
public Push(Repository repo, Models.Branch localBranch)
{
_repo = repo;
// Gather all local branches and find current branch.
LocalBranches = new List<Models.Branch>();
var current = null as Models.Branch;
foreach (var branch in _repo.Branches) {
foreach (var branch in _repo.Branches)
{
if (branch.IsLocal) LocalBranches.Add(branch);
if (branch.IsCurrent) current = branch;
}
// Set default selected local branch.
if (localBranch != null) {
if (localBranch != null)
{
_selectedLocalBranch = localBranch;
HasSpecifiedLocalBranch = true;
} else {
}
else
{
_selectedLocalBranch = current;
HasSpecifiedLocalBranch = false;
}
// Find preferred remote if selected local branch has upstream.
if (!string.IsNullOrEmpty(_selectedLocalBranch.Upstream)) {
foreach (var branch in repo.Branches) {
if (!branch.IsLocal && _selectedLocalBranch.Upstream == branch.FullName) {
if (!string.IsNullOrEmpty(_selectedLocalBranch.Upstream))
{
foreach (var branch in repo.Branches)
{
if (!branch.IsLocal && _selectedLocalBranch.Upstream == branch.FullName)
{
_selectedRemote = repo.Remotes.Find(x => x.Name == branch.Remote);
break;
}
@ -109,13 +134,15 @@ namespace SourceGit.ViewModels {
View = new Views.Push() { DataContext = this };
}
public override Task<bool> Sure() {
public override Task<bool> Sure()
{
_repo.SetWatcherEnabled(false);
var remoteBranchName = _selectedRemoteBranch.Name.Replace(" (new)", "");
ProgressDescription = $"Push {_selectedLocalBranch.Name} -> {_selectedRemote.Name}/{remoteBranchName} ...";
return Task.Run(() => {
return Task.Run(() =>
{
var succ = new Commands.Push(
_repo.FullPath,
_selectedLocalBranch.Name,
@ -130,17 +157,22 @@ namespace SourceGit.ViewModels {
});
}
private void AutoSelectBranchByRemote() {
private void AutoSelectBranchByRemote()
{
// Gather branches.
var branches = new List<Models.Branch>();
foreach (var branch in _repo.Branches) {
foreach (var branch in _repo.Branches)
{
if (branch.Remote == _selectedRemote.Name) branches.Add(branch);
}
// If selected local branch has upstream branch. Try to find it in current remote branches.
if (!string.IsNullOrEmpty(_selectedLocalBranch.Upstream)) {
foreach (var branch in branches) {
if (_selectedLocalBranch.Upstream == branch.FullName) {
if (!string.IsNullOrEmpty(_selectedLocalBranch.Upstream))
{
foreach (var branch in branches)
{
if (_selectedLocalBranch.Upstream == branch.FullName)
{
RemoteBranches = branches;
SelectedRemoteBranch = branch;
return;
@ -149,8 +181,10 @@ namespace SourceGit.ViewModels {
}
// Find best remote branch by name.
foreach (var branch in branches) {
if (_selectedLocalBranch.Name == branch.Name) {
foreach (var branch in branches)
{
if (_selectedLocalBranch.Name == branch.Name)
{
RemoteBranches = branches;
SelectedRemoteBranch = branch;
return;
@ -158,7 +192,8 @@ namespace SourceGit.ViewModels {
}
// Add a fake new branch.
var fake = new Models.Branch() {
var fake = new Models.Branch()
{
Name = $"{_selectedLocalBranch.Name} (new)",
Remote = _selectedRemote.Name,
};
@ -167,10 +202,10 @@ namespace SourceGit.ViewModels {
SelectedRemoteBranch = fake;
}
private Repository _repo = null;
private readonly Repository _repo = null;
private Models.Branch _selectedLocalBranch = null;
private Models.Remote _selectedRemote = null;
private List<Models.Branch> _remoteBranches = new List<Models.Branch>();
private Models.Branch _selectedRemoteBranch = null;
}
}
}