diff --git a/src/Commands/QueryBranches.cs b/src/Commands/QueryBranches.cs index 8dbc4055..39b77189 100644 --- a/src/Commands/QueryBranches.cs +++ b/src/Commands/QueryBranches.cs @@ -40,7 +40,7 @@ namespace SourceGit.Commands foreach (var b in branches) { if (b.IsLocal && !string.IsNullOrEmpty(b.Upstream)) - b.IsUpsteamGone = !remoteBranches.Contains(b.Upstream); + b.IsUpstreamGone = !remoteBranches.Contains(b.Upstream); } return branches; @@ -86,7 +86,7 @@ namespace SourceGit.Commands branch.Head = parts[1]; branch.IsCurrent = parts[2] == "*"; branch.Upstream = parts[3]; - branch.IsUpsteamGone = false; + branch.IsUpstreamGone = false; if (branch.IsLocal && !string.IsNullOrEmpty(parts[4]) && !parts[4].Equals("=", StringComparison.Ordinal)) branch.TrackStatus = new QueryTrackStatus(WorkingDirectory, branch.Name, branch.Upstream).Result(); diff --git a/src/Models/Branch.cs b/src/Models/Branch.cs index 2d0ae5b2..d0ac1990 100644 --- a/src/Models/Branch.cs +++ b/src/Models/Branch.cs @@ -34,7 +34,7 @@ namespace SourceGit.Models public string Upstream { get; set; } public BranchTrackStatus TrackStatus { get; set; } public string Remote { get; set; } - public bool IsUpsteamGone { get; set; } + public bool IsUpstreamGone { get; set; } public string FriendlyName => IsLocal ? Name : $"{Remote}/{Name}"; } diff --git a/src/ViewModels/BranchTreeNode.cs b/src/ViewModels/BranchTreeNode.cs index 6c1d2e04..0148844a 100644 --- a/src/ViewModels/BranchTreeNode.cs +++ b/src/ViewModels/BranchTreeNode.cs @@ -44,7 +44,7 @@ namespace SourceGit.ViewModels public bool ShowUpstreamGoneTip { - get => Backend is Models.Branch { IsUpsteamGone: true }; + get => Backend is Models.Branch { IsUpstreamGone: true }; } public string Tooltip diff --git a/src/ViewModels/FastForwardWithoutCheckout.cs b/src/ViewModels/FastForwardWithoutCheckout.cs index df4b4d73..974730a7 100644 --- a/src/ViewModels/FastForwardWithoutCheckout.cs +++ b/src/ViewModels/FastForwardWithoutCheckout.cs @@ -32,7 +32,11 @@ namespace SourceGit.ViewModels return Task.Run(() => { new Commands.UpdateRef(_repo.FullPath, Local.FullName, To.FullName, SetProgressDescription).Exec(); - CallUIThread(() => _repo.SetWatcherEnabled(true)); + CallUIThread(() => + { + _repo.NavigateToCommit(To.Head); + _repo.SetWatcherEnabled(true); + }); return true; }); } diff --git a/src/ViewModels/Fetch.cs b/src/ViewModels/Fetch.cs index 1094012e..cc38aa70 100644 --- a/src/ViewModels/Fetch.cs +++ b/src/ViewModels/Fetch.cs @@ -34,14 +34,14 @@ namespace SourceGit.ViewModels set => _repo.Settings.EnableForceOnFetch = value; } - public Fetch(Repository repo, Models.Remote preferedRemote = null) + public Fetch(Repository repo, Models.Remote preferredRemote = null) { _repo = repo; - _fetchAllRemotes = preferedRemote == null; + _fetchAllRemotes = preferredRemote == null; - if (preferedRemote != null) + if (preferredRemote != null) { - SelectedRemote = preferedRemote; + SelectedRemote = preferredRemote; } else if (!string.IsNullOrEmpty(_repo.Settings.DefaultRemote)) { @@ -83,6 +83,7 @@ namespace SourceGit.ViewModels CallUIThread(() => { + _repo.SetNeedNavigateToUpstreamHead(); _repo.MarkFetched(); _repo.SetWatcherEnabled(true); }); diff --git a/src/ViewModels/FetchInto.cs b/src/ViewModels/FetchInto.cs index a52b1cd6..8143ac9c 100644 --- a/src/ViewModels/FetchInto.cs +++ b/src/ViewModels/FetchInto.cs @@ -32,7 +32,11 @@ namespace SourceGit.ViewModels return Task.Run(() => { new Commands.Fetch(_repo.FullPath, Local, Upstream, SetProgressDescription).Exec(); - CallUIThread(() => _repo.SetWatcherEnabled(true)); + CallUIThread(() => + { + _repo.SetNeedNavigateToUpstreamHead(); + _repo.SetWatcherEnabled(true); + }); return true; }); } diff --git a/src/ViewModels/Merge.cs b/src/ViewModels/Merge.cs index faadaf57..7130bb30 100644 --- a/src/ViewModels/Merge.cs +++ b/src/ViewModels/Merge.cs @@ -62,7 +62,22 @@ namespace SourceGit.ViewModels return Task.Run(() => { new Commands.Merge(_repo.FullPath, _sourceName, Mode.Arg, SetProgressDescription).Exec(); - CallUIThread(() => _repo.SetWatcherEnabled(true)); + 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.SetWatcherEnabled(true); + }); return true; }); } diff --git a/src/ViewModels/Pull.cs b/src/ViewModels/Pull.cs index 62d68834..f40b0916 100644 --- a/src/ViewModels/Pull.cs +++ b/src/ViewModels/Pull.cs @@ -192,7 +192,11 @@ namespace SourceGit.ViewModels rs = new Commands.Stash(_repo.FullPath).Pop("stash@{0}"); } - CallUIThread(() => _repo.SetWatcherEnabled(true)); + CallUIThread(() => + { + _repo.SetNeedNavigateToUpstreamHead(); + _repo.SetWatcherEnabled(true); + }); return rs; }); } diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 6b1e439e..617105d9 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -717,6 +717,11 @@ namespace SourceGit.ViewModels _watcher?.SetEnabled(enabled); } + public void SetNeedNavigateToUpstreamHead() + { + _needNavigateToUpstreamHead = true; + } + public void MarkBranchesDirtyManually() { if (_watcher == null) @@ -773,6 +778,15 @@ namespace SourceGit.ViewModels NavigateToCommit(_currentBranch.Head); } + public void NavigateToCurrentUpstreamHead() + { + if (_currentBranch == null || string.IsNullOrEmpty(_currentBranch.Upstream)) + return; + var branch = _branches.Find(x => x.FullName == _currentBranch.Upstream); + if (branch != null) + NavigateToCommit(branch.Head); + } + public void ClearHistoriesFilter() { _settings.HistoriesFilters.Clear(); @@ -991,6 +1005,11 @@ namespace SourceGit.ViewModels _histories.IsLoading = false; _histories.Commits = commits; _histories.Graph = graph; + if (_needNavigateToUpstreamHead) + { + NavigateToCurrentUpstreamHead(); + _needNavigateToUpstreamHead = false; + } } }); } @@ -2588,5 +2607,6 @@ namespace SourceGit.ViewModels private bool _isAutoFetching = false; private Timer _autoFetchTimer = null; private DateTime _lastFetchTime = DateTime.MinValue; + private bool _needNavigateToUpstreamHead = false; } }