Skip to content

Commit 46a1432

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 46a1432

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 modified = 0;
1336+
foreach (var c in changes)
1337+
{
1338+
if (c.Index == Models.ChangeState.Added || c.WorkTree == Models.ChangeState.Untracked)
1339+
continue;
1340+
1341+
modified++;
1342+
}
1343+
13351344
Dispatcher.UIThread.Invoke(() =>
13361345
{
13371346
if (token.IsCancellationRequested)
13381347
return;
13391348

13401349
LocalChangesCount = changes.Count;
1350+
_localModifiedCount = modified;
1351+
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 (_localModifiedCount > 0)
1426+
ShowPopup(new Checkout(this, branch));
1427+
else
1428+
await ShowAndStartPopupAsync(new Checkout(this, branch));
14151429
}
14161430
else
14171431
{
@@ -1948,6 +1962,7 @@ private async Task AutoFetchOnUIThread()
19481962

19491963
private int _localBranchesCount = 0;
19501964
private int _localChangesCount = 0;
1965+
private int _localModifiedCount = 0;
19511966
private int _stashesCount = 0;
19521967

19531968
private bool _isSearchingCommits = false;

0 commit comments

Comments
 (0)