code_review: PR #1180

- replace `SetNeedNavigateToUpstreamHead` with `NavigateToBranchDelayed`
- navigate to current HEAD instead of original source HEAD after merge

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-04-14 11:35:50 +08:00
parent 17cf402c78
commit 0cb2ca78fe
No known key found for this signature in database
5 changed files with 15 additions and 30 deletions

View file

@ -83,7 +83,7 @@ namespace SourceGit.ViewModels
CallUIThread(() => CallUIThread(() =>
{ {
_repo.SetNeedNavigateToUpstreamHead(); _repo.NavigateToBranchDelayed(_repo.CurrentBranch?.Upstream);
_repo.MarkFetched(); _repo.MarkFetched();
_repo.SetWatcherEnabled(true); _repo.SetWatcherEnabled(true);
}); });

View file

@ -34,7 +34,7 @@ namespace SourceGit.ViewModels
new Commands.Fetch(_repo.FullPath, Local, Upstream, SetProgressDescription).Exec(); new Commands.Fetch(_repo.FullPath, Local, Upstream, SetProgressDescription).Exec();
CallUIThread(() => CallUIThread(() =>
{ {
_repo.SetNeedNavigateToUpstreamHead(); _repo.NavigateToBranchDelayed(Upstream.FullName);
_repo.SetWatcherEnabled(true); _repo.SetWatcherEnabled(true);
}); });
return true; return true;

View file

@ -64,18 +64,7 @@ namespace SourceGit.ViewModels
new Commands.Merge(_repo.FullPath, _sourceName, Mode.Arg, SetProgressDescription).Exec(); new Commands.Merge(_repo.FullPath, _sourceName, Mode.Arg, SetProgressDescription).Exec();
CallUIThread(() => CallUIThread(() =>
{ {
switch (Source) _repo.NavigateToBranchDelayed(_repo.CurrentBranch?.FullName);
{
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); _repo.SetWatcherEnabled(true);
}); });
return true; return true;

View file

@ -194,7 +194,7 @@ namespace SourceGit.ViewModels
CallUIThread(() => CallUIThread(() =>
{ {
_repo.SetNeedNavigateToUpstreamHead(); _repo.NavigateToBranchDelayed(_repo.CurrentBranch?.FullName);
_repo.SetWatcherEnabled(true); _repo.SetWatcherEnabled(true);
}); });
return rs; return rs;

View file

@ -717,11 +717,6 @@ namespace SourceGit.ViewModels
_watcher?.SetEnabled(enabled); _watcher?.SetEnabled(enabled);
} }
public void SetNeedNavigateToUpstreamHead()
{
_needNavigateToUpstreamHead = true;
}
public void MarkBranchesDirtyManually() public void MarkBranchesDirtyManually()
{ {
if (_watcher == null) if (_watcher == null)
@ -778,13 +773,9 @@ namespace SourceGit.ViewModels
NavigateToCommit(_currentBranch.Head); NavigateToCommit(_currentBranch.Head);
} }
public void NavigateToCurrentUpstreamHead() public void NavigateToBranchDelayed(string branch)
{ {
if (_currentBranch == null || string.IsNullOrEmpty(_currentBranch.Upstream)) _navigateToBranchDelayed = branch;
return;
var branch = _branches.Find(x => x.FullName == _currentBranch.Upstream);
if (branch != null)
NavigateToCommit(branch.Head);
} }
public void ClearHistoriesFilter() public void ClearHistoriesFilter()
@ -1005,12 +996,16 @@ namespace SourceGit.ViewModels
_histories.IsLoading = false; _histories.IsLoading = false;
_histories.Commits = commits; _histories.Commits = commits;
_histories.Graph = graph; _histories.Graph = graph;
if (_needNavigateToUpstreamHead)
if (!string.IsNullOrEmpty(_navigateToBranchDelayed))
{ {
NavigateToCurrentUpstreamHead(); var branch = _branches.Find(x => x.FullName == _navigateToBranchDelayed);
_needNavigateToUpstreamHead = false; if (branch != null)
NavigateToCommit(branch.Head);
} }
} }
_navigateToBranchDelayed = string.Empty;
}); });
} }
@ -2607,6 +2602,7 @@ namespace SourceGit.ViewModels
private bool _isAutoFetching = false; private bool _isAutoFetching = false;
private Timer _autoFetchTimer = null; private Timer _autoFetchTimer = null;
private DateTime _lastFetchTime = DateTime.MinValue; private DateTime _lastFetchTime = DateTime.MinValue;
private bool _needNavigateToUpstreamHead = false;
private string _navigateToBranchDelayed = string.Empty;
} }
} }