mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-05 11:05:00 +00:00
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>
This commit is contained in:
parent
056b90a5ae
commit
826619e7c9
3 changed files with 19 additions and 100 deletions
|
@ -1,76 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace SourceGit.Commands
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Query stash changes. Requires git >= 2.32.0
|
|
||||||
/// </summary>
|
|
||||||
public partial class QueryStashChanges : Command
|
|
||||||
{
|
|
||||||
[GeneratedRegex(@"^([MADC])\s+(.+)$")]
|
|
||||||
private static partial Regex REG_FORMAT();
|
|
||||||
[GeneratedRegex(@"^R[0-9]{0,4}\s+(.+)$")]
|
|
||||||
private static partial Regex REG_RENAME_FORMAT();
|
|
||||||
|
|
||||||
public QueryStashChanges(string repo, string stash)
|
|
||||||
{
|
|
||||||
WorkingDirectory = repo;
|
|
||||||
Context = repo;
|
|
||||||
Args = $"stash show -u --name-status \"{stash}\"";
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Models.Change> Result()
|
|
||||||
{
|
|
||||||
var rs = ReadToEnd();
|
|
||||||
if (!rs.IsSuccess)
|
|
||||||
return [];
|
|
||||||
|
|
||||||
var lines = rs.StdOut.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
var outs = new List<Models.Change>();
|
|
||||||
foreach (var line in lines)
|
|
||||||
{
|
|
||||||
var match = REG_FORMAT().Match(line);
|
|
||||||
if (!match.Success)
|
|
||||||
{
|
|
||||||
match = REG_RENAME_FORMAT().Match(line);
|
|
||||||
if (match.Success)
|
|
||||||
{
|
|
||||||
var renamed = new Models.Change() { Path = match.Groups[1].Value };
|
|
||||||
renamed.Set(Models.ChangeState.Renamed);
|
|
||||||
outs.Add(renamed);
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var change = new Models.Change() { Path = match.Groups[2].Value };
|
|
||||||
var status = match.Groups[1].Value;
|
|
||||||
|
|
||||||
switch (status[0])
|
|
||||||
{
|
|
||||||
case 'M':
|
|
||||||
change.Set(Models.ChangeState.Modified);
|
|
||||||
outs.Add(change);
|
|
||||||
break;
|
|
||||||
case 'A':
|
|
||||||
change.Set(Models.ChangeState.Added);
|
|
||||||
outs.Add(change);
|
|
||||||
break;
|
|
||||||
case 'D':
|
|
||||||
change.Set(Models.ChangeState.Deleted);
|
|
||||||
outs.Add(change);
|
|
||||||
break;
|
|
||||||
case 'C':
|
|
||||||
change.Set(Models.ChangeState.Copied);
|
|
||||||
outs.Add(change);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
outs.Sort((l, r) => string.Compare(l.Path, r.Path, StringComparison.Ordinal));
|
|
||||||
return outs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -21,10 +21,5 @@
|
||||||
/// The minimal version of Git that supports the `stash push` command with the `--staged` option.
|
/// The minimal version of Git that supports the `stash push` command with the `--staged` option.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly System.Version STASH_PUSH_ONLY_STAGED = new System.Version(2, 35, 0);
|
public static readonly System.Version STASH_PUSH_ONLY_STAGED = new System.Version(2, 35, 0);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The minimal version of Git that supports the `stash show` command with the `-u` option.
|
|
||||||
/// </summary>
|
|
||||||
public static readonly System.Version STASH_SHOW_WITH_UNTRACKED = new System.Version(2, 32, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,34 +53,32 @@ namespace SourceGit.ViewModels
|
||||||
if (value == null)
|
if (value == null)
|
||||||
{
|
{
|
||||||
Changes = null;
|
Changes = null;
|
||||||
|
_untracked.Clear();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
var changes = null as List<Models.Change>;
|
var changes = new Commands.CompareRevisions(_repo.FullPath, $"{value.SHA}^", value.SHA).Result();
|
||||||
|
var untracked = new List<Models.Change>();
|
||||||
if (Native.OS.GitVersion >= Models.GitVersions.STASH_SHOW_WITH_UNTRACKED)
|
|
||||||
|
if (value.Parents.Count == 3)
|
||||||
{
|
{
|
||||||
changes = new Commands.QueryStashChanges(_repo.FullPath, value.Name).Result();
|
untracked = new Commands.CompareRevisions(_repo.FullPath, Models.Commit.EmptyTreeSHA1, value.Parents[2]).Result();
|
||||||
}
|
var needSort = changes.Count > 0 && untracked.Count > 0;
|
||||||
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;
|
|
||||||
|
|
||||||
foreach (var c in untracked)
|
foreach (var c in untracked)
|
||||||
changes.Add(c);
|
changes.Add(c);
|
||||||
|
|
||||||
if (needSort)
|
if (needSort)
|
||||||
changes.Sort((l, r) => string.Compare(l.Path, r.Path, StringComparison.Ordinal));
|
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)
|
if (value == null)
|
||||||
DiffContext = 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);
|
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(Models.Commit.EmptyTreeSHA1, _selectedStash.Parents[2], value), _diffContext);
|
||||||
else
|
else
|
||||||
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(_selectedStash.Parents[0], _selectedStash.SHA, value), _diffContext);
|
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(_selectedStash.Parents[0], _selectedStash.SHA, value), _diffContext);
|
||||||
|
@ -129,6 +127,7 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
_stashes?.Clear();
|
_stashes?.Clear();
|
||||||
_changes?.Clear();
|
_changes?.Clear();
|
||||||
|
_untracked.Clear();
|
||||||
|
|
||||||
_repo = null;
|
_repo = null;
|
||||||
_selectedStash = null;
|
_selectedStash = null;
|
||||||
|
@ -309,6 +308,7 @@ namespace SourceGit.ViewModels
|
||||||
private string _searchFilter = string.Empty;
|
private string _searchFilter = string.Empty;
|
||||||
private Models.Stash _selectedStash = null;
|
private Models.Stash _selectedStash = null;
|
||||||
private List<Models.Change> _changes = null;
|
private List<Models.Change> _changes = null;
|
||||||
|
private List<Models.Change> _untracked = [];
|
||||||
private Models.Change _selectedChange = null;
|
private Models.Change _selectedChange = null;
|
||||||
private DiffContext _diffContext = null;
|
private DiffContext _diffContext = null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue