mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
96d4150d26
* remove dotnet-tool.json because the project does not rely on any dotnet tools. * remove Directory.Build.props because the solution has only one project. * move src/SourceGit to src. It's not needed to put all sources into a subfolder of src since there's only one project.
61 lines
1.8 KiB
C#
61 lines
1.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace SourceGit.Commands
|
|
{
|
|
public partial class QueryStashChanges : Command
|
|
{
|
|
|
|
[GeneratedRegex(@"^(\s?[\w\?]{1,4})\s+(.+)$")]
|
|
private static partial Regex REG_FORMAT();
|
|
|
|
public QueryStashChanges(string repo, string sha)
|
|
{
|
|
WorkingDirectory = repo;
|
|
Context = repo;
|
|
Args = $"diff --name-status --pretty=format: {sha}^ {sha}";
|
|
}
|
|
|
|
public List<Models.Change> Result()
|
|
{
|
|
Exec();
|
|
return _changes;
|
|
}
|
|
|
|
protected override void OnReadline(string line)
|
|
{
|
|
var match = REG_FORMAT().Match(line);
|
|
if (!match.Success)
|
|
return;
|
|
|
|
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);
|
|
_changes.Add(change);
|
|
break;
|
|
case 'A':
|
|
change.Set(Models.ChangeState.Added);
|
|
_changes.Add(change);
|
|
break;
|
|
case 'D':
|
|
change.Set(Models.ChangeState.Deleted);
|
|
_changes.Add(change);
|
|
break;
|
|
case 'R':
|
|
change.Set(Models.ChangeState.Renamed);
|
|
_changes.Add(change);
|
|
break;
|
|
case 'C':
|
|
change.Set(Models.ChangeState.Copied);
|
|
_changes.Add(change);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private readonly List<Models.Change> _changes = new List<Models.Change>();
|
|
}
|
|
}
|