Skip to content

Commit aa803c3

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) Signed-off-by: leo <[email protected]>
1 parent 7aa0083 commit aa803c3

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

src/ViewModels/WorkingCopy.cs

Lines changed: 26 additions & 13 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,13 @@ 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

1882-
// Use `_selectedUnstaged` instead of `SelectedUnstaged` to avoid UI refresh.
1883-
_selectedUnstaged = next != null ? [next] : [];
1884-
18851893
IsStaging = true;
1894+
_selectedUnstaged = next != null ? [next] : [];
18861895
_repo.SetWatcherEnabled(false);
18871896

18881897
var log = _repo.CreateLog("Stage");
@@ -1895,7 +1904,7 @@ private async void StageChanges(List<Models.Change> changes, Models.Change next)
18951904
var pathSpecFile = Path.GetTempFileName();
18961905
await using (var writer = new StreamWriter(pathSpecFile))
18971906
{
1898-
foreach (var c in nonConflictChanges)
1907+
foreach (var c in canStaged)
18991908
await writer.WriteLineAsync(c.Path);
19001909
}
19011910

@@ -1915,10 +1924,8 @@ private async void UnstageChanges(List<Models.Change> changes, Models.Change nex
19151924
if (count == 0)
19161925
return;
19171926

1918-
// Use `_selectedStaged` instead of `SelectedStaged` to avoid UI refresh.
1919-
_selectedStaged = next != null ? [next] : [];
1920-
19211927
IsUnstaging = true;
1928+
_selectedStaged = next != null ? [next] : [];
19221929
_repo.SetWatcherEnabled(false);
19231930

19241931
var log = _repo.CreateLog("Unstage");
@@ -1974,6 +1981,12 @@ private void DoCommit(bool autoStage, bool autoPush, CommitCheckPassed checkPass
19741981
return;
19751982
}
19761983

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

0 commit comments

Comments
 (0)