Skip to content

Commit 17cf402

Browse files
authored
enhance: navigate to upstream head after fetch, pull, and merge (#1180)
1 parent 245de9b commit 17cf402

File tree

9 files changed

+60
-12
lines changed

9 files changed

+60
-12
lines changed

src/Commands/QueryBranches.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public QueryBranches(string repo)
4040
foreach (var b in branches)
4141
{
4242
if (b.IsLocal && !string.IsNullOrEmpty(b.Upstream))
43-
b.IsUpsteamGone = !remoteBranches.Contains(b.Upstream);
43+
b.IsUpstreamGone = !remoteBranches.Contains(b.Upstream);
4444
}
4545

4646
return branches;
@@ -86,7 +86,7 @@ private Models.Branch ParseLine(string line)
8686
branch.Head = parts[1];
8787
branch.IsCurrent = parts[2] == "*";
8888
branch.Upstream = parts[3];
89-
branch.IsUpsteamGone = false;
89+
branch.IsUpstreamGone = false;
9090

9191
if (branch.IsLocal && !string.IsNullOrEmpty(parts[4]) && !parts[4].Equals("=", StringComparison.Ordinal))
9292
branch.TrackStatus = new QueryTrackStatus(WorkingDirectory, branch.Name, branch.Upstream).Result();

src/Models/Branch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class Branch
3434
public string Upstream { get; set; }
3535
public BranchTrackStatus TrackStatus { get; set; }
3636
public string Remote { get; set; }
37-
public bool IsUpsteamGone { get; set; }
37+
public bool IsUpstreamGone { get; set; }
3838

3939
public string FriendlyName => IsLocal ? Name : $"{Remote}/{Name}";
4040
}

src/ViewModels/BranchTreeNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public bool IsCurrent
4444

4545
public bool ShowUpstreamGoneTip
4646
{
47-
get => Backend is Models.Branch { IsUpsteamGone: true };
47+
get => Backend is Models.Branch { IsUpstreamGone: true };
4848
}
4949

5050
public string Tooltip

src/ViewModels/FastForwardWithoutCheckout.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ public override Task<bool> Sure()
3232
return Task.Run(() =>
3333
{
3434
new Commands.UpdateRef(_repo.FullPath, Local.FullName, To.FullName, SetProgressDescription).Exec();
35-
CallUIThread(() => _repo.SetWatcherEnabled(true));
35+
CallUIThread(() =>
36+
{
37+
_repo.NavigateToCommit(To.Head);
38+
_repo.SetWatcherEnabled(true);
39+
});
3640
return true;
3741
});
3842
}

src/ViewModels/Fetch.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ public bool Force
3434
set => _repo.Settings.EnableForceOnFetch = value;
3535
}
3636

37-
public Fetch(Repository repo, Models.Remote preferedRemote = null)
37+
public Fetch(Repository repo, Models.Remote preferredRemote = null)
3838
{
3939
_repo = repo;
40-
_fetchAllRemotes = preferedRemote == null;
40+
_fetchAllRemotes = preferredRemote == null;
4141

42-
if (preferedRemote != null)
42+
if (preferredRemote != null)
4343
{
44-
SelectedRemote = preferedRemote;
44+
SelectedRemote = preferredRemote;
4545
}
4646
else if (!string.IsNullOrEmpty(_repo.Settings.DefaultRemote))
4747
{
@@ -83,6 +83,7 @@ public override Task<bool> Sure()
8383

8484
CallUIThread(() =>
8585
{
86+
_repo.SetNeedNavigateToUpstreamHead();
8687
_repo.MarkFetched();
8788
_repo.SetWatcherEnabled(true);
8889
});

src/ViewModels/FetchInto.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ public override Task<bool> Sure()
3232
return Task.Run(() =>
3333
{
3434
new Commands.Fetch(_repo.FullPath, Local, Upstream, SetProgressDescription).Exec();
35-
CallUIThread(() => _repo.SetWatcherEnabled(true));
35+
CallUIThread(() =>
36+
{
37+
_repo.SetNeedNavigateToUpstreamHead();
38+
_repo.SetWatcherEnabled(true);
39+
});
3640
return true;
3741
});
3842
}

src/ViewModels/Merge.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,22 @@ public override Task<bool> Sure()
6262
return Task.Run(() =>
6363
{
6464
new Commands.Merge(_repo.FullPath, _sourceName, Mode.Arg, SetProgressDescription).Exec();
65-
CallUIThread(() => _repo.SetWatcherEnabled(true));
65+
CallUIThread(() =>
66+
{
67+
switch (Source)
68+
{
69+
case Models.Branch branch:
70+
_repo.NavigateToCommit(branch.Head);
71+
break;
72+
case Models.Commit commit:
73+
_repo.NavigateToCommit(commit.SHA);
74+
break;
75+
case Models.Tag tag:
76+
_repo.NavigateToCommit(tag.SHA);
77+
break;
78+
}
79+
_repo.SetWatcherEnabled(true);
80+
});
6681
return true;
6782
});
6883
}

src/ViewModels/Pull.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,11 @@ public override Task<bool> Sure()
192192
rs = new Commands.Stash(_repo.FullPath).Pop("stash@{0}");
193193
}
194194

195-
CallUIThread(() => _repo.SetWatcherEnabled(true));
195+
CallUIThread(() =>
196+
{
197+
_repo.SetNeedNavigateToUpstreamHead();
198+
_repo.SetWatcherEnabled(true);
199+
});
196200
return rs;
197201
});
198202
}

src/ViewModels/Repository.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,11 @@ public void SetWatcherEnabled(bool enabled)
717717
_watcher?.SetEnabled(enabled);
718718
}
719719

720+
public void SetNeedNavigateToUpstreamHead()
721+
{
722+
_needNavigateToUpstreamHead = true;
723+
}
724+
720725
public void MarkBranchesDirtyManually()
721726
{
722727
if (_watcher == null)
@@ -773,6 +778,15 @@ public void NavigateToCurrentHead()
773778
NavigateToCommit(_currentBranch.Head);
774779
}
775780

781+
public void NavigateToCurrentUpstreamHead()
782+
{
783+
if (_currentBranch == null || string.IsNullOrEmpty(_currentBranch.Upstream))
784+
return;
785+
var branch = _branches.Find(x => x.FullName == _currentBranch.Upstream);
786+
if (branch != null)
787+
NavigateToCommit(branch.Head);
788+
}
789+
776790
public void ClearHistoriesFilter()
777791
{
778792
_settings.HistoriesFilters.Clear();
@@ -991,6 +1005,11 @@ public void RefreshCommits()
9911005
_histories.IsLoading = false;
9921006
_histories.Commits = commits;
9931007
_histories.Graph = graph;
1008+
if (_needNavigateToUpstreamHead)
1009+
{
1010+
NavigateToCurrentUpstreamHead();
1011+
_needNavigateToUpstreamHead = false;
1012+
}
9941013
}
9951014
});
9961015
}
@@ -2588,5 +2607,6 @@ private void AutoFetchImpl(object sender)
25882607
private bool _isAutoFetching = false;
25892608
private Timer _autoFetchTimer = null;
25902609
private DateTime _lastFetchTime = DateTime.MinValue;
2610+
private bool _needNavigateToUpstreamHead = false;
25912611
}
25922612
}

0 commit comments

Comments
 (0)