Skip to content

Commit 826619e

Browse files
committed
fix: new added file in stash changes may not come from untracked file but from staged files (#1358)
Signed-off-by: leo <longshuang@msn.cn>
1 parent 056b90a commit 826619e

File tree

3 files changed

+21
-102
lines changed

3 files changed

+21
-102
lines changed

src/Commands/QueryStashChanges.cs

Lines changed: 0 additions & 76 deletions
This file was deleted.

src/Models/GitVersions.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,5 @@ public static class GitVersions
2121
/// The minimal version of Git that supports the `stash push` command with the `--staged` option.
2222
/// </summary>
2323
public static readonly System.Version STASH_PUSH_ONLY_STAGED = new System.Version(2, 35, 0);
24-
25-
/// <summary>
26-
/// The minimal version of Git that supports the `stash show` command with the `-u` option.
27-
/// </summary>
28-
public static readonly System.Version STASH_SHOW_WITH_UNTRACKED = new System.Version(2, 32, 0);
2924
}
3025
}

src/ViewModels/StashesPage.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,34 +53,32 @@ public Models.Stash SelectedStash
5353
if (value == null)
5454
{
5555
Changes = null;
56+
_untracked.Clear();
5657
}
5758
else
5859
{
5960
Task.Run(() =>
6061
{
61-
var changes = null as List<Models.Change>;
62-
63-
if (Native.OS.GitVersion >= Models.GitVersions.STASH_SHOW_WITH_UNTRACKED)
64-
{
65-
changes = new Commands.QueryStashChanges(_repo.FullPath, value.Name).Result();
66-
}
67-
else
62+
var changes = new Commands.CompareRevisions(_repo.FullPath, $"{value.SHA}^", value.SHA).Result();
63+
var untracked = new List<Models.Change>();
64+
65+
if (value.Parents.Count == 3)
6866
{
69-
changes = new Commands.CompareRevisions(_repo.FullPath, $"{value.SHA}^", value.SHA).Result();
70-
if (value.Parents.Count == 3)
71-
{
72-
var untracked = new Commands.CompareRevisions(_repo.FullPath, Models.Commit.EmptyTreeSHA1, value.Parents[2]).Result();
73-
var needSort = changes.Count > 0;
74-
75-
foreach (var c in untracked)
76-
changes.Add(c);
77-
78-
if (needSort)
79-
changes.Sort((l, r) => string.Compare(l.Path, r.Path, StringComparison.Ordinal));
80-
}
67+
untracked = new Commands.CompareRevisions(_repo.FullPath, Models.Commit.EmptyTreeSHA1, value.Parents[2]).Result();
68+
var needSort = changes.Count > 0 && untracked.Count > 0;
69+
70+
foreach (var c in untracked)
71+
changes.Add(c);
72+
73+
if (needSort)
74+
changes.Sort((l, r) => string.Compare(l.Path, r.Path, StringComparison.Ordinal));
8175
}
8276

83-
Dispatcher.UIThread.Invoke(() => Changes = changes);
77+
Dispatcher.UIThread.Invoke(() =>
78+
{
79+
_untracked = untracked;
80+
Changes = changes;
81+
});
8482
});
8583
}
8684
}
@@ -106,7 +104,7 @@ public Models.Change SelectedChange
106104
{
107105
if (value == null)
108106
DiffContext = null;
109-
else if (value.Index == Models.ChangeState.Added && _selectedStash.Parents.Count == 3)
107+
else if (_untracked.Contains(value))
110108
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(Models.Commit.EmptyTreeSHA1, _selectedStash.Parents[2], value), _diffContext);
111109
else
112110
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(_selectedStash.Parents[0], _selectedStash.SHA, value), _diffContext);
@@ -129,6 +127,7 @@ public void Dispose()
129127
{
130128
_stashes?.Clear();
131129
_changes?.Clear();
130+
_untracked.Clear();
132131

133132
_repo = null;
134133
_selectedStash = null;
@@ -309,6 +308,7 @@ private void RefreshVisible()
309308
private string _searchFilter = string.Empty;
310309
private Models.Stash _selectedStash = null;
311310
private List<Models.Change> _changes = null;
311+
private List<Models.Change> _untracked = [];
312312
private Models.Change _selectedChange = null;
313313
private DiffContext _diffContext = null;
314314
}

0 commit comments

Comments
 (0)