sourcegit/src/Commands/Submodule.cs

56 lines
1.3 KiB
C#
Raw Normal View History

using System;
2021-04-29 05:05:55 -07:00
namespace SourceGit.Commands
{
public class Submodule : Command
{
public Submodule(string repo)
{
WorkingDirectory = repo;
Context = repo;
2021-04-29 05:05:55 -07:00
}
public bool Add(string url, string relativePath, bool recursive, Action<string> outputHandler)
{
_outputHandler = outputHandler;
Args = $"submodule add {url} {relativePath}";
if (!Exec())
return false;
2021-04-29 05:05:55 -07:00
if (recursive)
{
Args = $"submodule update --init --recursive -- {relativePath}";
2021-04-29 05:05:55 -07:00
return Exec();
}
else
{
Args = $"submodule update --init -- {relativePath}";
2021-04-29 05:05:55 -07:00
return true;
}
}
public bool Update()
{
2021-04-29 05:05:55 -07:00
Args = $"submodule update --rebase --remote";
return Exec();
}
public bool Delete(string relativePath)
{
Args = $"submodule deinit -f {relativePath}";
if (!Exec())
return false;
2021-04-29 05:05:55 -07:00
Args = $"rm -rf {relativePath}";
2021-04-29 05:05:55 -07:00
return Exec();
}
protected override void OnReadline(string line)
{
_outputHandler?.Invoke(line);
2021-04-29 05:05:55 -07:00
}
private Action<string> _outputHandler;
2021-04-29 05:05:55 -07:00
}
}