enhance: run checking out automatically when all the local changes are new files

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2026-03-17 13:50:18 +08:00
parent 418d4a3827
commit 5cdb8364a9
2 changed files with 16 additions and 6 deletions

View File

@@ -22,11 +22,6 @@ namespace SourceGit.ViewModels
DiscardLocalChanges = false;
}
public override bool CanStartDirectly()
{
return _repo.LocalChangesCount == 0;
}
public override async Task<bool> Sure()
{
using var lockWatcher = _repo.LockWatcher();

View File

@@ -1332,12 +1332,23 @@ namespace SourceGit.ViewModels
changes.Sort((l, r) => Models.NumericSort.Compare(l.Path, r.Path));
_workingCopy.SetData(changes, token);
var hasModified = false;
foreach (var c in changes)
{
if (c.Index == Models.ChangeState.Added || c.WorkTree == Models.ChangeState.Untracked)
continue;
hasModified = true;
break;
}
Dispatcher.UIThread.Invoke(() =>
{
if (token.IsCancellationRequested)
return;
LocalChangesCount = changes.Count;
_canCheckoutDirectly = !hasModified;
OnPropertyChanged(nameof(InProgressContext));
GetOwnerPage()?.ChangeDirtyState(Models.DirtyState.HasLocalChanges, changes.Count == 0);
});
@@ -1411,7 +1422,10 @@ namespace SourceGit.ViewModels
if (branch.IsLocal)
{
await ShowAndStartPopupAsync(new Checkout(this, branch));
if (_canCheckoutDirectly)
await ShowAndStartPopupAsync(new Checkout(this, branch));
else
ShowPopup(new Checkout(this, branch));
}
else
{
@@ -1965,6 +1979,7 @@ namespace SourceGit.ViewModels
private List<Models.Submodule> _submodules = [];
private object _visibleSubmodules = null;
private string _navigateToCommitDelayed = string.Empty;
private bool _canCheckoutDirectly = false;
private bool _isAutoFetching = false;
private Timer _autoFetchTimer = null;