2023-08-24 04:05:38 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.Commands {
|
|
|
|
|
public class AssumeUnchanged {
|
|
|
|
|
class ViewCommand : Command {
|
|
|
|
|
private static readonly Regex REG = new Regex(@"^(\w)\s+(.+)$");
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<string> Result() {
|
|
|
|
|
Exec();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return _outs;
|
2023-08-24 04:05:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
protected override void OnReadline(string line) {
|
2023-08-24 04:05:38 -07:00
|
|
|
|
var match = REG.Match(line);
|
|
|
|
|
if (!match.Success) return;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
private List<string> _outs = new List<string>();
|
2023-08-24 04:05:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ModCommand : Command {
|
|
|
|
|
public ModCommand(string repo, string file, bool bAdd) {
|
|
|
|
|
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}\"";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AssumeUnchanged(string repo) {
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
2023-08-24 04:05:38 -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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
private string _repo;
|
2023-08-24 04:05:38 -07:00
|
|
|
|
}
|
|
|
|
|
}
|