From 08567a7420b3171dff73fac4d26de9f9889cf992 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 18 Jun 2024 14:27:59 +0800 Subject: [PATCH] ux: only show `Set as tracking branch` option if selected remote branch is not upstream of selected local branch --- src/ViewModels/Push.cs | 33 +++++++++++++-------------------- src/Views/Push.axaml | 6 ++++-- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/ViewModels/Push.cs b/src/ViewModels/Push.cs index 0ca4f9de..863ef873 100644 --- a/src/ViewModels/Push.cs +++ b/src/ViewModels/Push.cs @@ -19,25 +19,7 @@ namespace SourceGit.ViewModels set { if (SetProperty(ref _selectedLocalBranch, value)) - { - // If selected local branch has upstream branch. Try to find it's remote. - if (!string.IsNullOrEmpty(value.Upstream)) - { - var branch = _repo.Branches.Find(x => x.FullName == value.Upstream); - if (branch != null) - { - var remote = _repo.Remotes.Find(x => x.Name == branch.Remote); - if (remote != null && remote != _selectedRemote) - { - SelectedRemote = remote; - return; - } - } - } - - // Re-generate remote branches and auto-select remote branches. AutoSelectBranchByRemote(); - } } } @@ -73,7 +55,11 @@ namespace SourceGit.ViewModels public Models.Branch SelectedRemoteBranch { get => _selectedRemoteBranch; - set => SetProperty(ref _selectedRemoteBranch, value); + set + { + if (SetProperty(ref _selectedRemoteBranch, value)) + IsSetTrackOptionVisible = value != null && _selectedLocalBranch.Upstream != value.FullName; + } } public bool PushAllTags @@ -82,6 +68,12 @@ namespace SourceGit.ViewModels set; } + public bool IsSetTrackOptionVisible + { + get => _isSetTrackOptionVisible; + private set => SetProperty(ref _isSetTrackOptionVisible, value); + } + public bool Tracking { get; @@ -160,7 +152,7 @@ namespace SourceGit.ViewModels remoteBranchName, PushAllTags, ForcePush, - Tracking, + _isSetTrackOptionVisible && Tracking, SetProgressDescription).Exec(); CallUIThread(() => _repo.SetWatcherEnabled(true)); return succ; @@ -218,5 +210,6 @@ namespace SourceGit.ViewModels private Models.Remote _selectedRemote = null; private List _remoteBranches = new List(); private Models.Branch _selectedRemoteBranch = null; + private bool _isSetTrackOptionVisible = false; } } diff --git a/src/Views/Push.axaml b/src/Views/Push.axaml index 00cdafbf..043910c2 100644 --- a/src/Views/Push.axaml +++ b/src/Views/Push.axaml @@ -13,7 +13,7 @@ Classes="bold" Text="{DynamicResource Text.Push.Title}"/> - + + IsChecked="{Binding Tracking, Mode=TwoWay}" + IsVisible="{Binding IsSetTrackOptionVisible}"/>