diff --git a/src/ViewModels/Fetch.cs b/src/ViewModels/Fetch.cs index cc38aa70..35e34bb3 100644 --- a/src/ViewModels/Fetch.cs +++ b/src/ViewModels/Fetch.cs @@ -83,7 +83,7 @@ namespace SourceGit.ViewModels CallUIThread(() => { - _repo.SetNeedNavigateToUpstreamHead(); + _repo.NavigateToBranchDelayed(_repo.CurrentBranch?.Upstream); _repo.MarkFetched(); _repo.SetWatcherEnabled(true); }); diff --git a/src/ViewModels/FetchInto.cs b/src/ViewModels/FetchInto.cs index 8143ac9c..878b0416 100644 --- a/src/ViewModels/FetchInto.cs +++ b/src/ViewModels/FetchInto.cs @@ -34,7 +34,7 @@ namespace SourceGit.ViewModels new Commands.Fetch(_repo.FullPath, Local, Upstream, SetProgressDescription).Exec(); CallUIThread(() => { - _repo.SetNeedNavigateToUpstreamHead(); + _repo.NavigateToBranchDelayed(Upstream.FullName); _repo.SetWatcherEnabled(true); }); return true; diff --git a/src/ViewModels/Merge.cs b/src/ViewModels/Merge.cs index 7130bb30..8b2ad537 100644 --- a/src/ViewModels/Merge.cs +++ b/src/ViewModels/Merge.cs @@ -64,18 +64,7 @@ namespace SourceGit.ViewModels new Commands.Merge(_repo.FullPath, _sourceName, Mode.Arg, SetProgressDescription).Exec(); CallUIThread(() => { - switch (Source) - { - case Models.Branch branch: - _repo.NavigateToCommit(branch.Head); - break; - case Models.Commit commit: - _repo.NavigateToCommit(commit.SHA); - break; - case Models.Tag tag: - _repo.NavigateToCommit(tag.SHA); - break; - } + _repo.NavigateToBranchDelayed(_repo.CurrentBranch?.FullName); _repo.SetWatcherEnabled(true); }); return true; diff --git a/src/ViewModels/Pull.cs b/src/ViewModels/Pull.cs index f40b0916..465a393a 100644 --- a/src/ViewModels/Pull.cs +++ b/src/ViewModels/Pull.cs @@ -194,7 +194,7 @@ namespace SourceGit.ViewModels CallUIThread(() => { - _repo.SetNeedNavigateToUpstreamHead(); + _repo.NavigateToBranchDelayed(_repo.CurrentBranch?.FullName); _repo.SetWatcherEnabled(true); }); return rs; diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 617105d9..9b720c7b 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -717,11 +717,6 @@ namespace SourceGit.ViewModels _watcher?.SetEnabled(enabled); } - public void SetNeedNavigateToUpstreamHead() - { - _needNavigateToUpstreamHead = true; - } - public void MarkBranchesDirtyManually() { if (_watcher == null) @@ -778,13 +773,9 @@ namespace SourceGit.ViewModels NavigateToCommit(_currentBranch.Head); } - public void NavigateToCurrentUpstreamHead() + public void NavigateToBranchDelayed(string branch) { - if (_currentBranch == null || string.IsNullOrEmpty(_currentBranch.Upstream)) - return; - var branch = _branches.Find(x => x.FullName == _currentBranch.Upstream); - if (branch != null) - NavigateToCommit(branch.Head); + _navigateToBranchDelayed = branch; } public void ClearHistoriesFilter() @@ -1005,12 +996,16 @@ namespace SourceGit.ViewModels _histories.IsLoading = false; _histories.Commits = commits; _histories.Graph = graph; - if (_needNavigateToUpstreamHead) + + if (!string.IsNullOrEmpty(_navigateToBranchDelayed)) { - NavigateToCurrentUpstreamHead(); - _needNavigateToUpstreamHead = false; + var branch = _branches.Find(x => x.FullName == _navigateToBranchDelayed); + if (branch != null) + NavigateToCommit(branch.Head); } } + + _navigateToBranchDelayed = string.Empty; }); } @@ -2607,6 +2602,7 @@ namespace SourceGit.ViewModels private bool _isAutoFetching = false; private Timer _autoFetchTimer = null; private DateTime _lastFetchTime = DateTime.MinValue; - private bool _needNavigateToUpstreamHead = false; + + private string _navigateToBranchDelayed = string.Empty; } }