fix: new added file in stash changes may not come from untracked file but from staged files (#1358)
Some checks are pending
Continuous Integration / Build (push) Waiting to run
Continuous Integration / Prepare version string (push) Waiting to run
Continuous Integration / Package (push) Blocked by required conditions

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-05-26 22:07:14 +08:00
parent 056b90a5ae
commit 826619e7c9
No known key found for this signature in database
3 changed files with 19 additions and 100 deletions

View file

@ -53,34 +53,32 @@ namespace SourceGit.ViewModels
if (value == null)
{
Changes = null;
_untracked.Clear();
}
else
{
Task.Run(() =>
{
var changes = null as List<Models.Change>;
if (Native.OS.GitVersion >= Models.GitVersions.STASH_SHOW_WITH_UNTRACKED)
var changes = new Commands.CompareRevisions(_repo.FullPath, $"{value.SHA}^", value.SHA).Result();
var untracked = new List<Models.Change>();
if (value.Parents.Count == 3)
{
changes = new Commands.QueryStashChanges(_repo.FullPath, value.Name).Result();
}
else
{
changes = new Commands.CompareRevisions(_repo.FullPath, $"{value.SHA}^", value.SHA).Result();
if (value.Parents.Count == 3)
{
var untracked = new Commands.CompareRevisions(_repo.FullPath, Models.Commit.EmptyTreeSHA1, value.Parents[2]).Result();
var needSort = changes.Count > 0;
untracked = new Commands.CompareRevisions(_repo.FullPath, Models.Commit.EmptyTreeSHA1, value.Parents[2]).Result();
var needSort = changes.Count > 0 && untracked.Count > 0;
foreach (var c in untracked)
changes.Add(c);
foreach (var c in untracked)
changes.Add(c);
if (needSort)
changes.Sort((l, r) => string.Compare(l.Path, r.Path, StringComparison.Ordinal));
}
if (needSort)
changes.Sort((l, r) => string.Compare(l.Path, r.Path, StringComparison.Ordinal));
}
Dispatcher.UIThread.Invoke(() => Changes = changes);
Dispatcher.UIThread.Invoke(() =>
{
_untracked = untracked;
Changes = changes;
});
});
}
}
@ -106,7 +104,7 @@ namespace SourceGit.ViewModels
{
if (value == null)
DiffContext = null;
else if (value.Index == Models.ChangeState.Added && _selectedStash.Parents.Count == 3)
else if (_untracked.Contains(value))
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(Models.Commit.EmptyTreeSHA1, _selectedStash.Parents[2], value), _diffContext);
else
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(_selectedStash.Parents[0], _selectedStash.SHA, value), _diffContext);
@ -129,6 +127,7 @@ namespace SourceGit.ViewModels
{
_stashes?.Clear();
_changes?.Clear();
_untracked.Clear();
_repo = null;
_selectedStash = null;
@ -309,6 +308,7 @@ namespace SourceGit.ViewModels
private string _searchFilter = string.Empty;
private Models.Stash _selectedStash = null;
private List<Models.Change> _changes = null;
private List<Models.Change> _untracked = [];
private Models.Change _selectedChange = null;
private DiffContext _diffContext = null;
}