2023-08-24 04:05:38 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Commands
|
|
|
|
|
{
|
|
|
|
|
public partial class AssumeUnchanged
|
|
|
|
|
{
|
|
|
|
|
partial class ViewCommand : Command
|
|
|
|
|
{
|
2024-03-16 02:09:27 -07:00
|
|
|
|
[GeneratedRegex(@"^(\w)\s+(.+)$")]
|
|
|
|
|
private static partial Regex REG();
|
2023-08-24 04:05:38 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public ViewCommand(string repo)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
WorkingDirectory = repo;
|
2023-08-24 04:05:38 -07:00
|
|
|
|
Args = "ls-files -v";
|
2024-02-05 23:08:37 -08:00
|
|
|
|
RaiseError = false;
|
2023-08-24 04:05:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public List<string> Result()
|
|
|
|
|
{
|
2023-08-24 04:05:38 -07:00
|
|
|
|
Exec();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return _outs;
|
2023-08-24 04:05:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
protected override void OnReadline(string line)
|
|
|
|
|
{
|
2024-03-16 02:09:27 -07:00
|
|
|
|
var match = REG().Match(line);
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (!match.Success)
|
|
|
|
|
return;
|
2023-08-24 04:05:38 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (match.Groups[1].Value == "h")
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_outs.Add(match.Groups[2].Value);
|
2023-08-24 04:05:38 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly List<string> _outs = new List<string>();
|
2023-08-24 04:05:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
class ModCommand : Command
|
|
|
|
|
{
|
|
|
|
|
public ModCommand(string repo, string file, bool bAdd)
|
|
|
|
|
{
|
2023-08-24 04:05:38 -07:00
|
|
|
|
var mode = bAdd ? "--assume-unchanged" : "--no-assume-unchanged";
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
WorkingDirectory = repo;
|
|
|
|
|
Context = repo;
|
2023-08-24 04:05:38 -07:00
|
|
|
|
Args = $"update-index {mode} -- \"{file}\"";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public AssumeUnchanged(string repo)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
2023-08-24 04:05:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public List<string> View()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return new ViewCommand(_repo).Result();
|
2023-08-24 04:05:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void Add(string file)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
new ModCommand(_repo, file, true).Exec();
|
2023-08-24 04:05:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void Remove(string file)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
new ModCommand(_repo, file, false).Exec();
|
2023-08-24 04:05:38 -07:00
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly string _repo;
|
2023-08-24 04:05:38 -07:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|