2024-02-05 23:08:37 -08:00
|
|
|
|
using System;
|
2021-06-06 23:14:53 -07:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.Commands {
|
|
|
|
|
public class LFS {
|
2024-02-05 23:08:37 -08:00
|
|
|
|
class PruneCmd : Command {
|
2022-02-09 22:27:46 -08:00
|
|
|
|
public PruneCmd(string repo, Action<string> onProgress) {
|
2024-02-05 23:08:37 -08:00
|
|
|
|
WorkingDirectory = repo;
|
|
|
|
|
Context = repo;
|
2022-02-09 22:27:46 -08:00
|
|
|
|
Args = "lfs prune";
|
|
|
|
|
TraitErrorAsOutput = true;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_outputHandler = onProgress;
|
2022-02-09 22:27:46 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
protected override void OnReadline(string line) {
|
|
|
|
|
_outputHandler?.Invoke(line);
|
2022-02-09 22:27:46 -08:00
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
private Action<string> _outputHandler;
|
2022-02-09 22:27:46 -08:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-06 23:14:53 -07:00
|
|
|
|
public LFS(string repo) {
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
2021-06-06 23:14:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsEnabled() {
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var path = Path.Combine(_repo, ".git", "hooks", "pre-push");
|
2021-06-06 23:14:53 -07:00
|
|
|
|
if (!File.Exists(path)) return false;
|
|
|
|
|
|
|
|
|
|
var content = File.ReadAllText(path);
|
|
|
|
|
return content.Contains("git lfs pre-push");
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
public void Prune(Action<string> outputHandler) {
|
|
|
|
|
new PruneCmd(_repo, outputHandler).Exec();
|
2021-06-06 23:14:53 -07:00
|
|
|
|
}
|
2022-02-09 22:27:46 -08:00
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private string _repo;
|
2021-06-06 23:14:53 -07:00
|
|
|
|
}
|
|
|
|
|
}
|