mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-23 13:14:59 +00:00
refactor: rewrite submodule to support IsDirty
state (#339)
This commit is contained in:
parent
eb441852b0
commit
1fe2be11a7
10 changed files with 110 additions and 19 deletions
|
@ -17,9 +17,10 @@ namespace SourceGit.Commands
|
|||
Args = "submodule status";
|
||||
}
|
||||
|
||||
public List<string> Result()
|
||||
public List<Models.Submodule> Result()
|
||||
{
|
||||
Exec();
|
||||
new UpdateSubmoduleStatus(WorkingDirectory, _submodules).Result();
|
||||
return _submodules;
|
||||
}
|
||||
|
||||
|
@ -28,17 +29,17 @@ namespace SourceGit.Commands
|
|||
var match = REG_FORMAT1().Match(line);
|
||||
if (match.Success)
|
||||
{
|
||||
_submodules.Add(match.Groups[1].Value);
|
||||
_submodules.Add(new Models.Submodule() { Path = match.Groups[1].Value });
|
||||
return;
|
||||
}
|
||||
|
||||
match = REG_FORMAT2().Match(line);
|
||||
if (match.Success)
|
||||
{
|
||||
_submodules.Add(match.Groups[1].Value);
|
||||
_submodules.Add(new Models.Submodule() { Path = match.Groups[1].Value });
|
||||
}
|
||||
}
|
||||
|
||||
private readonly List<string> _submodules = new List<string>();
|
||||
private readonly List<Models.Submodule> _submodules = new List<Models.Submodule>();
|
||||
}
|
||||
}
|
||||
|
|
43
src/Commands/UpdateSubmoduleStatus.cs
Normal file
43
src/Commands/UpdateSubmoduleStatus.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SourceGit.Commands
|
||||
{
|
||||
public partial class UpdateSubmoduleStatus : Command
|
||||
{
|
||||
[GeneratedRegex(@"^\s?[\w\?]{1,4}\s+(.+)$")]
|
||||
private static partial Regex REG_FORMAT();
|
||||
|
||||
public UpdateSubmoduleStatus(string repo, List<Models.Submodule> submodules)
|
||||
{
|
||||
var pathes = new StringBuilder();
|
||||
foreach (var submodule in submodules)
|
||||
pathes.Append($"\"{submodule.Path}\" ");
|
||||
|
||||
_submodules = submodules;
|
||||
|
||||
WorkingDirectory = repo;
|
||||
Context = repo;
|
||||
Args = $"status -uno --porcelain -- {pathes}";
|
||||
}
|
||||
|
||||
public void Result()
|
||||
{
|
||||
Exec();
|
||||
|
||||
foreach (var submodule in _submodules)
|
||||
submodule.IsDirty = _changed.Contains(submodule.Path);
|
||||
}
|
||||
|
||||
protected override void OnReadline(string line)
|
||||
{
|
||||
var match = REG_FORMAT().Match(line);
|
||||
if (match.Success)
|
||||
_changed.Add(match.Groups[1].Value);
|
||||
}
|
||||
|
||||
private List<Models.Submodule> _submodules = null;
|
||||
private HashSet<string> _changed = new HashSet<string>();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue