mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 12:45:00 +00:00
feature: use git stash show -u --name-status <stash_name>
command to query changes in selected stash if git >= 2.32.0
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
65dbfd336d
commit
38d87fa1a1
4 changed files with 98 additions and 13 deletions
68
src/Commands/QueryStashChanges.cs
Normal file
68
src/Commands/QueryStashChanges.cs
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
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(@"^([MADRC])\s+(.+)$")]
|
||||||
|
private static partial Regex REG_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)
|
||||||
|
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 'R':
|
||||||
|
change.Set(Models.ChangeState.Renamed);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,13 +13,18 @@
|
||||||
public static readonly System.Version ADD_WITH_PATHSPECFILE = new System.Version(2, 25, 0);
|
public static readonly System.Version ADD_WITH_PATHSPECFILE = new System.Version(2, 25, 0);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The minimal version of Git that supports the `stash` command with the `--pathspec-from-file` option.
|
/// The minimal version of Git that supports the `stash push` command with the `--pathspec-from-file` option.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly System.Version STASH_WITH_PATHSPECFILE = new System.Version(2, 26, 0);
|
public static readonly System.Version STASH_PUSH_WITH_PATHSPECFILE = new System.Version(2, 26, 0);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The minimal version of Git that supports the `stash` 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_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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
if (OnlyStaged)
|
if (OnlyStaged)
|
||||||
{
|
{
|
||||||
if (Native.OS.GitVersion >= Models.GitVersions.STASH_ONLY_STAGED)
|
if (Native.OS.GitVersion >= Models.GitVersions.STASH_PUSH_ONLY_STAGED)
|
||||||
{
|
{
|
||||||
succ = new Commands.Stash(_repo.FullPath).PushOnlyStaged(Message, KeepIndex);
|
succ = new Commands.Stash(_repo.FullPath).PushOnlyStaged(Message, KeepIndex);
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ namespace SourceGit.ViewModels
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
var succ = false;
|
var succ = false;
|
||||||
if (Native.OS.GitVersion >= Models.GitVersions.STASH_WITH_PATHSPECFILE)
|
if (Native.OS.GitVersion >= Models.GitVersions.STASH_PUSH_WITH_PATHSPECFILE)
|
||||||
{
|
{
|
||||||
var paths = new List<string>();
|
var paths = new List<string>();
|
||||||
foreach (var c in changes)
|
foreach (var c in changes)
|
||||||
|
|
|
@ -58,14 +58,26 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
var changes = new Commands.CompareRevisions(_repo.FullPath, $"{value.SHA}^", value.SHA).Result();
|
var changes = null as List<Models.Change>;
|
||||||
if (value.Parents.Count == 3)
|
|
||||||
{
|
|
||||||
var untracked = new Commands.CompareRevisions(_repo.FullPath, "4b825dc642cb6eb9a060e54bf8d69288fbee4904", value.Parents[2]).Result();
|
|
||||||
foreach (var c in untracked)
|
|
||||||
changes.Add(c);
|
|
||||||
|
|
||||||
changes.Sort((l, r) => string.Compare(l.Path, r.Path, StringComparison.Ordinal));
|
if (Native.OS.GitVersion >= Models.GitVersions.STASH_SHOW_WITH_UNTRACKED)
|
||||||
|
{
|
||||||
|
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, "4b825dc642cb6eb9a060e54bf8d69288fbee4904", value.Parents[2]).Result();
|
||||||
|
var needSort = changes.Count > 0;
|
||||||
|
|
||||||
|
foreach (var c in untracked)
|
||||||
|
changes.Add(c);
|
||||||
|
|
||||||
|
if (needSort)
|
||||||
|
changes.Sort((l, r) => string.Compare(l.Path, r.Path, StringComparison.Ordinal));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Dispatcher.UIThread.Invoke(() => Changes = changes);
|
Dispatcher.UIThread.Invoke(() => Changes = changes);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue