Skip to content

Commit 5cdb836

Browse files
committed
enhance: run checking out automatically when all the local changes are new files
Signed-off-by: leo <longshuang@msn.cn>
1 parent 418d4a3 commit 5cdb836

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/ViewModels/Checkout.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ public Checkout(Repository repo, Models.Branch branch)
2222
DiscardLocalChanges = false;
2323
}
2424

25-
public override bool CanStartDirectly()
26-
{
27-
return _repo.LocalChangesCount == 0;
28-
}
29-
3025
public override async Task<bool> Sure()
3126
{
3227
using var lockWatcher = _repo.LockWatcher();

src/ViewModels/Repository.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,12 +1332,23 @@ public void RefreshWorkingCopyChanges()
13321332
changes.Sort((l, r) => Models.NumericSort.Compare(l.Path, r.Path));
13331333
_workingCopy.SetData(changes, token);
13341334

1335+
var hasModified = false;
1336+
foreach (var c in changes)
1337+
{
1338+
if (c.Index == Models.ChangeState.Added || c.WorkTree == Models.ChangeState.Untracked)
1339+
continue;
1340+
1341+
hasModified = true;
1342+
break;
1343+
}
1344+
13351345
Dispatcher.UIThread.Invoke(() =>
13361346
{
13371347
if (token.IsCancellationRequested)
13381348
return;
13391349

13401350
LocalChangesCount = changes.Count;
1351+
_canCheckoutDirectly = !hasModified;
13411352
OnPropertyChanged(nameof(InProgressContext));
13421353
GetOwnerPage()?.ChangeDirtyState(Models.DirtyState.HasLocalChanges, changes.Count == 0);
13431354
});
@@ -1411,7 +1422,10 @@ public async Task CheckoutBranchAsync(Models.Branch branch)
14111422

14121423
if (branch.IsLocal)
14131424
{
1414-
await ShowAndStartPopupAsync(new Checkout(this, branch));
1425+
if (_canCheckoutDirectly)
1426+
await ShowAndStartPopupAsync(new Checkout(this, branch));
1427+
else
1428+
ShowPopup(new Checkout(this, branch));
14151429
}
14161430
else
14171431
{
@@ -1965,6 +1979,7 @@ private async Task AutoFetchOnUIThread()
19651979
private List<Models.Submodule> _submodules = [];
19661980
private object _visibleSubmodules = null;
19671981
private string _navigateToCommitDelayed = string.Empty;
1982+
private bool _canCheckoutDirectly = false;
19681983

19691984
private bool _isAutoFetching = false;
19701985
private Timer _autoFetchTimer = null;

0 commit comments

Comments
 (0)