Skip to content

Commit 1273155

Browse files
committed
feature: auto-change filter branches after checkout (#855)
1 parent 2a55ba6 commit 1273155

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/ViewModels/Checkout.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,14 @@ public override Task<bool> Sure()
6565
{
6666
var b = _repo.Branches.Find(x => x.IsLocal && x.Name == Branch);
6767
if (b != null && _repo.HistoriesFilterMode == Models.FilterMode.Included)
68+
{
69+
_repo.Settings.HistoriesFilters.Clear();
6870
_repo.Settings.UpdateHistoriesFilter(b.FullName, Models.FilterType.LocalBranch, Models.FilterMode.Included);
6971

72+
if (!string.IsNullOrEmpty(b.Upstream))
73+
_repo.Settings.UpdateHistoriesFilter(b.Upstream, Models.FilterType.LocalBranch, Models.FilterMode.Included);
74+
}
75+
7076
_repo.MarkBranchesDirtyManually();
7177
_repo.SetWatcherEnabled(true);
7278
});

src/ViewModels/CreateBranch.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public override Task<bool> Sure()
8383
_repo.SetWatcherEnabled(false);
8484
return Task.Run(() =>
8585
{
86+
var succ = false;
8687
if (CheckoutAfterCreated)
8788
{
8889
var changes = new Commands.CountLocalChangesWithoutUntracked(_repo.FullPath).Result();
@@ -92,7 +93,7 @@ public override Task<bool> Sure()
9293
if (PreAction == Models.DealWithLocalChanges.StashAndReaply)
9394
{
9495
SetProgressDescription("Stash local changes");
95-
var succ = new Commands.Stash(_repo.FullPath).Push("CREATE_BRANCH_AUTO_STASH");
96+
succ = new Commands.Stash(_repo.FullPath).Push("CREATE_BRANCH_AUTO_STASH");
9697
if (!succ)
9798
{
9899
CallUIThread(() => _repo.SetWatcherEnabled(true));
@@ -109,7 +110,7 @@ public override Task<bool> Sure()
109110
}
110111

111112
SetProgressDescription($"Create new branch '{_name}'");
112-
new Commands.Checkout(_repo.FullPath).Branch(_name, _baseOnRevision, SetProgressDescription);
113+
succ = new Commands.Checkout(_repo.FullPath).Branch(_name, _baseOnRevision, SetProgressDescription);
113114

114115
if (needPopStash)
115116
{
@@ -120,17 +121,24 @@ public override Task<bool> Sure()
120121
else
121122
{
122123
SetProgressDescription($"Create new branch '{_name}'");
123-
Commands.Branch.Create(_repo.FullPath, _name, _baseOnRevision);
124+
succ = Commands.Branch.Create(_repo.FullPath, _name, _baseOnRevision);
124125
}
125126

126127
CallUIThread(() =>
127128
{
128-
if (CheckoutAfterCreated && _repo.HistoriesFilterMode == Models.FilterMode.Included)
129+
if (succ && CheckoutAfterCreated && _repo.HistoriesFilterMode == Models.FilterMode.Included)
130+
{
131+
_repo.Settings.HistoriesFilters.Clear();
129132
_repo.Settings.UpdateHistoriesFilter($"refs/heads/{_name}", Models.FilterType.LocalBranch, Models.FilterMode.Included);
130133

134+
if (BasedOn is Models.Branch b && !b.IsLocal)
135+
_repo.Settings.UpdateHistoriesFilter(b.FullName, Models.FilterType.LocalBranch, Models.FilterMode.Included);
136+
}
137+
131138
_repo.MarkBranchesDirtyManually();
132139
_repo.SetWatcherEnabled(true);
133140
});
141+
134142
return true;
135143
});
136144
}

0 commit comments

Comments
 (0)