feature: auto add checkout target branch to history filters if the filter list is not empty (#518)
Some checks are pending
Continuous Integration / Build (push) Waiting to run
Continuous Integration / Prepare version string (push) Waiting to run
Continuous Integration / Package (push) Blocked by required conditions

This commit is contained in:
leo 2024-09-26 20:37:48 +08:00
parent 4925e56dfb
commit 05c135a89d
No known key found for this signature in database
3 changed files with 44 additions and 1 deletions

View file

@ -62,7 +62,16 @@ namespace SourceGit.ViewModels
rs = new Commands.Stash(_repo.FullPath).Pop("stash@{0}"); rs = new Commands.Stash(_repo.FullPath).Pop("stash@{0}");
} }
CallUIThread(() => _repo.SetWatcherEnabled(true)); CallUIThread(() =>
{
var b = _repo.Branches.Find(x => x.IsLocal && x.Name == Branch);
if (b != null)
_repo.AutoAddBranchFilterPostCheckout(b);
_repo.MarkBranchesDirtyManually();
_repo.SetWatcherEnabled(true);
});
return rs; return rs;
}); });
} }

View file

@ -126,6 +126,15 @@ namespace SourceGit.ViewModels
CallUIThread(() => CallUIThread(() =>
{ {
if (CheckoutAfterCreated)
{
_repo.AutoAddBranchFilterPostCheckout(new Models.Branch()
{
FullName = $"refs/heads/{_name}",
Upstream = BasedOn is Models.Branch { IsLocal: false } remoteBranch ? remoteBranch.FullName : string.Empty,
});
}
_repo.MarkBranchesDirtyManually(); _repo.MarkBranchesDirtyManually();
_repo.SetWatcherEnabled(true); _repo.SetWatcherEnabled(true);
}); });

View file

@ -659,6 +659,31 @@ namespace SourceGit.ViewModels
NavigateToCommit(_currentBranch.Head); NavigateToCommit(_currentBranch.Head);
} }
public void AutoAddBranchFilterPostCheckout(Models.Branch local)
{
if (_settings.Filters.Count == 0 || _settings.Filters.Contains(local.FullName))
return;
var hasLeft = false;
foreach (var b in _branches)
{
if (!b.FullName.Equals(local.FullName, StringComparison.Ordinal) &&
!b.FullName.Equals(local.Upstream, StringComparison.Ordinal) &&
!_settings.Filters.Contains(b.FullName))
{
hasLeft = true;
break;
}
}
if (!hasLeft)
_settings.Filters.Clear();
else if (string.IsNullOrEmpty(local.Upstream) || _settings.Filters.Contains(local.Upstream))
_settings.Filters.Add(local.FullName);
else
_settings.Filters.AddRange([local.FullName, local.Upstream]);
}
public void UpdateFilters(List<string> filters, bool toggle) public void UpdateFilters(List<string> filters, bool toggle)
{ {
var changed = false; var changed = false;