mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
feature: auto add checkout target branch to history filters if the filter list is not empty (#518)
This commit is contained in:
parent
4925e56dfb
commit
05c135a89d
3 changed files with 44 additions and 1 deletions
|
@ -62,7 +62,16 @@ namespace SourceGit.ViewModels
|
|||
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;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -126,6 +126,15 @@ namespace SourceGit.ViewModels
|
|||
|
||||
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.SetWatcherEnabled(true);
|
||||
});
|
||||
|
|
|
@ -659,6 +659,31 @@ namespace SourceGit.ViewModels
|
|||
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)
|
||||
{
|
||||
var changed = false;
|
||||
|
|
Loading…
Reference in a new issue