From 3a54471ea53bc547ccc4bf242e65b2c50f59a3f0 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 9 Aug 2024 14:08:25 +0800 Subject: [PATCH] refactor: rewrite branch auto-select after remote changed while pulling (#342) --- src/ViewModels/Pull.cs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/ViewModels/Pull.cs b/src/ViewModels/Pull.cs index d7638934..152cbb9e 100644 --- a/src/ViewModels/Pull.cs +++ b/src/ViewModels/Pull.cs @@ -182,30 +182,29 @@ namespace SourceGit.ViewModels RemoteBranches = branches; var autoSelectedBranch = false; - if (!string.IsNullOrEmpty(_current.Upstream)) + if (!string.IsNullOrEmpty(_current.Upstream) && + _current.Upstream.StartsWith($"refs/remotes/{remoteName}/", System.StringComparison.Ordinal)) { - if (_current.Upstream.StartsWith($"refs/remotes/{remoteName}/", System.StringComparison.Ordinal)) + foreach (var branch in branches) { - foreach (var branch in branches) + if (_current.Upstream == branch.FullName) { - if (_current.Upstream == branch.FullName) - { - SelectedBranch = branch; - autoSelectedBranch = true; - break; - } + SelectedBranch = branch; + autoSelectedBranch = true; + break; } } - else + } + + if (!autoSelectedBranch) + { + foreach (var branch in branches) { - foreach (var branch in branches) + if (_current.Name == branch.Name) { - if (_current.Name == branch.Name) - { - SelectedBranch = branch; - autoSelectedBranch = true; - break; - } + SelectedBranch = branch; + autoSelectedBranch = true; + break; } } }