Skip to content

Commit c112549

Browse files
committed
refactor: query branch head after operation finished to avoid branch head mismatch
Signed-off-by: leo <[email protected]>
1 parent 9fb8af5 commit c112549

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

src/ViewModels/Fetch.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,16 @@ public override Task<bool> Sure()
8080

8181
log.Complete();
8282

83+
var upstream = _repo.CurrentBranch?.Upstream;
84+
var upstreamHead = string.Empty;
85+
if (!string.IsNullOrEmpty(upstream))
86+
upstreamHead = new Commands.QueryRevisionByRefName(_repo.FullPath, upstream.Substring(13)).Result();
87+
8388
CallUIThread(() =>
8489
{
85-
_repo.NavigateToBranchDelayed(_repo.CurrentBranch?.Upstream);
90+
if (!string.IsNullOrEmpty(upstreamHead))
91+
_repo.NavigateToCommitDelayed(upstreamHead);
92+
8693
_repo.MarkFetched();
8794
_repo.SetWatcherEnabled(true);
8895
});

src/ViewModels/FetchInto.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ public override Task<bool> Sure()
3333
{
3434
new Commands.Fetch(_repo.FullPath, Local, Upstream).Use(log).Exec();
3535
log.Complete();
36+
37+
var changedLocalBranchHead = new Commands.QueryRevisionByRefName(_repo.FullPath, Local.Name).Result();
3638
CallUIThread(() =>
3739
{
38-
_repo.NavigateToBranchDelayed(Upstream.FullName);
40+
_repo.NavigateToCommitDelayed(changedLocalBranchHead);
3941
_repo.SetWatcherEnabled(true);
4042
});
43+
4144
return true;
4245
});
4346
}

src/ViewModels/Merge.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ public override Task<bool> Sure()
6464
new Commands.Merge(_repo.FullPath, _sourceName, Mode.Arg).Use(log).Exec();
6565
log.Complete();
6666

67+
var head = new Commands.QueryRevisionByRefName(_repo.FullPath, "HEAD").Result();
6768
CallUIThread(() =>
6869
{
69-
_repo.NavigateToBranchDelayed(_repo.CurrentBranch?.FullName);
70+
_repo.NavigateToCommitDelayed(head);
7071
_repo.SetWatcherEnabled(true);
7172
});
7273
return true;

src/ViewModels/Pull.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,10 @@ public override Task<bool> Sure()
164164

165165
log.Complete();
166166

167+
var head = new Commands.QueryRevisionByRefName(_repo.FullPath, "HEAD").Result();
167168
CallUIThread(() =>
168169
{
169-
_repo.NavigateToBranchDelayed(_repo.CurrentBranch?.FullName);
170+
_repo.NavigateToCommitDelayed(head);
170171
_repo.SetWatcherEnabled(true);
171172
});
172173

src/ViewModels/Repository.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -922,15 +922,15 @@ public void NavigateToCommit(string sha)
922922
}
923923
}
924924

925-
public void NavigateToCurrentHead()
925+
public void NavigateToCommitDelayed(string sha)
926926
{
927-
if (_currentBranch != null)
928-
NavigateToCommit(_currentBranch.Head);
927+
_navigateToCommitDelayed = sha;
929928
}
930929

931-
public void NavigateToBranchDelayed(string branch)
930+
public void NavigateToCurrentHead()
932931
{
933-
_navigateToBranchDelayed = branch;
932+
if (_currentBranch != null)
933+
NavigateToCommit(_currentBranch.Head);
934934
}
935935

936936
public void ClearHistoriesFilter()
@@ -1189,15 +1189,11 @@ public void RefreshCommits()
11891189

11901190
BisectState = _histories.UpdateBisectInfo();
11911191

1192-
if (!string.IsNullOrEmpty(_navigateToBranchDelayed))
1193-
{
1194-
var branch = _branches.Find(x => x.FullName == _navigateToBranchDelayed);
1195-
if (branch != null)
1196-
NavigateToCommit(branch.Head);
1197-
}
1192+
if (!string.IsNullOrEmpty(_navigateToCommitDelayed))
1193+
NavigateToCommit(_navigateToCommitDelayed);
11981194
}
11991195

1200-
_navigateToBranchDelayed = string.Empty;
1196+
_navigateToCommitDelayed = string.Empty;
12011197
});
12021198
}
12031199

@@ -2937,6 +2933,6 @@ private void AutoFetchImpl(object sender)
29372933
private Models.BisectState _bisectState = Models.BisectState.None;
29382934
private bool _isBisectCommandRunning = false;
29392935

2940-
private string _navigateToBranchDelayed = string.Empty;
2936+
private string _navigateToCommitDelayed = string.Empty;
29412937
}
29422938
}

0 commit comments

Comments
 (0)