From 039e38e6fa9c616d86f1e7505d8ac3fe7ffbb97d Mon Sep 17 00:00:00 2001 From: Mutzi Muszkal Date: Fri, 14 Feb 2025 14:50:35 -0500 Subject: [PATCH] . --- src/ViewModels/Push.cs | 71 ++++++++++++++++++++---------------------- src/Views/Push.axaml | 52 ++++++++++++++----------------- 2 files changed, 56 insertions(+), 67 deletions(-) diff --git a/src/ViewModels/Push.cs b/src/ViewModels/Push.cs index 1f18b38e6..036bc20f1 100644 --- a/src/ViewModels/Push.cs +++ b/src/ViewModels/Push.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Linq; using System.Threading.Tasks; namespace SourceGit.ViewModels @@ -44,20 +45,32 @@ public Models.Remote SelectedRemote } } - public List RemoteBranches + public Models.Branch SelectedRemoteBranch { - get => _remoteBranches; - private set => SetProperty(ref _remoteBranches, value); + get => _selectedRemoteBranch; + private set => SetProperty(ref _selectedRemoteBranch, value); } - + [Required(ErrorMessage = "Remote branch is required!!!")] - public Models.Branch SelectedRemoteBranch + public string SelectedRemoteBranchName { - get => _selectedRemoteBranch; + get => _selectedRemoteBranchName; set { - if (SetProperty(ref _selectedRemoteBranch, value)) - IsSetTrackOptionVisible = value != null && _selectedLocalBranch.Upstream != value.FullName; + if (SetProperty(ref _selectedRemoteBranchName, value)) + { + SelectedRemoteBranch = null; + + foreach (var branch in _repo.Branches.Where(branch => branch.Remote == _selectedRemote.Name)) + { + if (_selectedRemoteBranchName == branch.Name) + { + SelectedRemoteBranch = branch; + } + } + + IsSetTrackOptionVisible = SelectedRemoteBranch != null && _selectedLocalBranch.Upstream != SelectedRemoteBranch.FullName; + } } } @@ -130,7 +143,7 @@ public Push(Repository repo, Models.Branch localBranch) { if (!branch.IsLocal && _selectedLocalBranch.Upstream == branch.FullName) { - _selectedRemote = repo.Remotes.Find(x => x.Name == branch.Remote); + _selectedRemote = repo.Remotes.Find(remote => remote.Name == branch.Remote); break; } } @@ -141,7 +154,7 @@ public Push(Repository repo, Models.Branch localBranch) { var remote = null as Models.Remote; if (!string.IsNullOrEmpty(_repo.Settings.DefaultRemote)) - remote = repo.Remotes.Find(x => x.Name == _repo.Settings.DefaultRemote); + remote = repo.Remotes.Find(remote => remote.Name == _repo.Settings.DefaultRemote); _selectedRemote = remote ?? repo.Remotes[0]; } @@ -154,15 +167,15 @@ public Push(Repository repo, Models.Branch localBranch) public override bool CanStartDirectly() { - return !string.IsNullOrEmpty(_selectedRemoteBranch?.Head); + return !string.IsNullOrEmpty(SelectedRemoteBranch?.Head); } public override Task Sure() { _repo.SetWatcherEnabled(false); - var remoteBranchName = _selectedRemoteBranch.Name; - ProgressDescription = $"Push {_selectedLocalBranch.Name} -> {_selectedRemote.Name}/{remoteBranchName} ..."; + ProgressDescription = + $"Push {_selectedLocalBranch.Name} -> {_selectedRemote.Name}/{_selectedRemoteBranchName} ..."; return Task.Run(() => { @@ -170,7 +183,7 @@ public override Task Sure() _repo.FullPath, _selectedLocalBranch.Name, _selectedRemote.Name, - remoteBranchName, + _selectedRemoteBranchName, PushAllTags, _repo.Submodules.Count > 0 && CheckSubmodules, _isSetTrackOptionVisible && Tracking, @@ -183,54 +196,36 @@ public override Task Sure() private void AutoSelectBranchByRemote() { - // Gather branches. - var branches = new List(); - foreach (var branch in _repo.Branches) - { - if (branch.Remote == _selectedRemote.Name) - branches.Add(branch); - } - // If selected local branch has upstream. Try to find it in current remote branches. if (!string.IsNullOrEmpty(_selectedLocalBranch.Upstream)) { - foreach (var branch in branches) + foreach (var branch in _repo.Branches.Where(branch => branch.Remote == _selectedRemote.Name)) { if (_selectedLocalBranch.Upstream == branch.FullName) { - RemoteBranches = branches; - SelectedRemoteBranch = branch; + SelectedRemoteBranchName = branch.Name; return; } } } // Try to find a remote branch with the same name of selected local branch. - foreach (var branch in branches) + foreach (var branch in _repo.Branches.Where(branch => branch.Remote == _selectedRemote.Name)) { if (_selectedLocalBranch.Name == branch.Name) { - RemoteBranches = branches; - SelectedRemoteBranch = branch; + SelectedRemoteBranchName = branch.Name; return; } } - // Add a fake new branch. - var fake = new Models.Branch() - { - Name = _selectedLocalBranch.Name, - Remote = _selectedRemote.Name, - }; - branches.Add(fake); - RemoteBranches = branches; - SelectedRemoteBranch = fake; + SelectedRemoteBranchName = _selectedLocalBranch.Name; } private readonly Repository _repo = null; private Models.Branch _selectedLocalBranch = null; private Models.Remote _selectedRemote = null; - private List _remoteBranches = []; + private string _selectedRemoteBranchName = null; private Models.Branch _selectedRemoteBranch = null; private bool _isSetTrackOptionVisible = false; } diff --git a/src/Views/Push.axaml b/src/Views/Push.axaml index e28e2afd3..43c3e5a9a 100644 --- a/src/Views/Push.axaml +++ b/src/Views/Push.axaml @@ -63,35 +63,29 @@ HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,8,0" Text="{DynamicResource Text.Push.To}"/> - - - - - - - - - - - - - - - - - - - + + + + + + + + + +