sourcegit/src/Commands/Submodule.cs

44 lines
1.2 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}";
2021-04-29 05:05:55 -07:00
if (!Exec()) return false;
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() {
Args = $"submodule update --rebase --remote";
return Exec();
}
public bool Delete(string relativePath) {
Args = $"submodule deinit -f {relativePath}";
2021-04-29 05:05:55 -07:00
if (!Exec()) return false;
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
}
}