Skip to content

Commit 4f52cb9

Browse files
committed
code_review: PR #1555
- Remove unnecessary reference to `System.Linq` - Stop to auto-stage and commit when there is unsolved conflict(s)
1 parent 7aa0083 commit 4f52cb9

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/ViewModels/WorkingCopy.cs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4-
using System.Linq;
54
using System.Threading.Tasks;
65

76
using Avalonia.Controls;
@@ -1796,6 +1795,21 @@ public ContextMenu CreateContextForOpenAI()
17961795
return visible;
17971796
}
17981797

1798+
private List<Models.Change> GetCanStagedChanges(List<Models.Change> changes)
1799+
{
1800+
if (!HasUnsolvedConflicts)
1801+
return changes;
1802+
1803+
var outs = new List<Models.Change>();
1804+
foreach (var c in changes)
1805+
{
1806+
if (!c.IsConflicted)
1807+
outs.Add(c);
1808+
}
1809+
1810+
return outs;
1811+
}
1812+
17991813
private List<Models.Change> GetStagedChanges()
18001814
{
18011815
if (_useAmend)
@@ -1871,18 +1885,14 @@ private void UpdateInProgressState()
18711885

18721886
private async void StageChanges(List<Models.Change> changes, Models.Change next)
18731887
{
1874-
var nonConflictChanges = HasUnsolvedConflicts
1875-
? changes.Where(c => !c.IsConflicted).ToList()
1876-
: changes;
1877-
1878-
var count = nonConflictChanges.Count;
1888+
var canStaged = GetCanStagedChanges(changes);
1889+
var count = canStaged.Count;
18791890
if (count == 0)
18801891
return;
18811892

18821893
// Use `_selectedUnstaged` instead of `SelectedUnstaged` to avoid UI refresh.
1883-
_selectedUnstaged = next != null ? [next] : [];
1884-
18851894
IsStaging = true;
1895+
_selectedUnstaged = next != null ? [next] : [];
18861896
_repo.SetWatcherEnabled(false);
18871897

18881898
var log = _repo.CreateLog("Stage");
@@ -1895,7 +1905,7 @@ private async void StageChanges(List<Models.Change> changes, Models.Change next)
18951905
var pathSpecFile = Path.GetTempFileName();
18961906
await using (var writer = new StreamWriter(pathSpecFile))
18971907
{
1898-
foreach (var c in nonConflictChanges)
1908+
foreach (var c in canStaged)
18991909
await writer.WriteLineAsync(c.Path);
19001910
}
19011911

@@ -1974,6 +1984,12 @@ private void DoCommit(bool autoStage, bool autoPush, CommitCheckPassed checkPass
19741984
return;
19751985
}
19761986

1987+
if (autoStage && HasUnsolvedConflicts)
1988+
{
1989+
App.RaiseException(_repo.FullPath, "Repository has unsolved conflict(s). Auto-stage and commit is disabled!");
1990+
return;
1991+
}
1992+
19771993
if (_repo.CurrentBranch is { IsDetachedHead: true } && checkPassed < CommitCheckPassed.DetachedHead)
19781994
{
19791995
var msg = App.Text("WorkingCopy.ConfirmCommitWithDetachedHead");

0 commit comments

Comments
 (0)