sourcegit/src/Commands/Submodule.cs

67 lines
1.7 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;
2024-07-26 03:49:07 -07:00
Args = $"submodule add {url} \"{relativePath}\"";
if (!Exec())
return false;
2021-04-29 05:05:55 -07:00
if (recursive)
{
2024-07-26 03:49:07 -07:00
Args = $"submodule update --init --recursive -- \"{relativePath}\"";
2021-04-29 05:05:55 -07:00
return Exec();
}
else
{
2024-07-26 03:49:07 -07:00
Args = $"submodule update --init -- \"{relativePath}\"";
2021-04-29 05:05:55 -07:00
return true;
}
}
2024-07-26 03:49:07 -07:00
public bool Update(string module, bool init, bool recursive, bool useRemote, Action<string> outputHandler)
{
2024-07-26 03:49:07 -07:00
Args = "submodule update";
if (init)
Args += " --init";
if (recursive)
Args += " --recursive";
if (useRemote)
Args += " --remote";
if (!string.IsNullOrEmpty(module))
Args += $" -- \"{module}\"";
_outputHandler = outputHandler;
2021-04-29 05:05:55 -07:00
return Exec();
}
public bool Delete(string relativePath)
{
2024-07-26 03:49:07 -07:00
Args = $"submodule deinit -f \"{relativePath}\"";
if (!Exec())
return false;
2021-04-29 05:05:55 -07:00
2024-07-26 03:49:07 -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
}
}