2024-02-05 23:08:37 -08:00
|
|
|
|
using System;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Commands
|
|
|
|
|
{
|
|
|
|
|
public class Submodule : Command
|
|
|
|
|
{
|
|
|
|
|
public Submodule(string repo)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
WorkingDirectory = repo;
|
|
|
|
|
Context = repo;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool Add(string url, string relativePath, bool recursive, Action<string> outputHandler)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_outputHandler = outputHandler;
|
|
|
|
|
Args = $"submodule add {url} {relativePath}";
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (!Exec())
|
|
|
|
|
return false;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (recursive)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Args = $"submodule update --init --recursive -- {relativePath}";
|
2021-04-29 05:05:55 -07:00
|
|
|
|
return Exec();
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Args = $"submodule update --init -- {relativePath}";
|
2021-04-29 05:05:55 -07:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-03 20:36:00 -07:00
|
|
|
|
public bool Update(Action<string> outputHandler)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2021-04-29 05:05:55 -07:00
|
|
|
|
Args = $"submodule update --rebase --remote";
|
2024-06-03 20:36:00 -07:00
|
|
|
|
_outputHandler = outputHandler;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
return Exec();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool Delete(string relativePath)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Args = $"submodule deinit -f {relativePath}";
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (!Exec())
|
|
|
|
|
return false;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Args = $"rm -rf {relativePath}";
|
2021-04-29 05:05:55 -07:00
|
|
|
|
return Exec();
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
private Action<string> _outputHandler;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|