2024-02-05 23:08:37 -08:00
|
|
|
|
using System;
|
2021-06-06 23:14:53 -07:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Commands
|
|
|
|
|
{
|
|
|
|
|
public class LFS
|
|
|
|
|
{
|
|
|
|
|
class PruneCmd : Command
|
|
|
|
|
{
|
|
|
|
|
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-03-17 18:37:06 -07:00
|
|
|
|
protected override void OnReadline(string line)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_outputHandler?.Invoke(line);
|
2022-02-09 22:27:46 -08:00
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly Action<string> _outputHandler;
|
2022-02-09 22:27:46 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public LFS(string repo)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
2021-06-06 23:14:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -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-03-17 18:37:06 -07:00
|
|
|
|
public void Prune(Action<string> outputHandler)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
new PruneCmd(_repo, outputHandler).Exec();
|
2021-06-06 23:14:53 -07:00
|
|
|
|
}
|
2022-02-09 22:27:46 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly string _repo;
|
2021-06-06 23:14:53 -07:00
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|