2024-02-05 23:08:37 -08:00
|
|
|
|
using System;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
|
|
|
|
namespace SourceGit.Commands {
|
|
|
|
|
public class Submodule : Command {
|
2024-02-05 23:08:37 -08:00
|
|
|
|
public Submodule(string repo) {
|
|
|
|
|
WorkingDirectory = repo;
|
|
|
|
|
Context = repo;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 23:08:37 -08: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) {
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Args = $"submodule update --init --recursive -- {relativePath}";
|
2021-04-29 05:05:55 -07:00
|
|
|
|
return Exec();
|
|
|
|
|
} else {
|
2024-02-05 23:08:37 -08:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
public bool Delete(string relativePath) {
|
|
|
|
|
Args = $"submodule deinit -f {relativePath}";
|
2021-04-29 05:05:55 -07:00
|
|
|
|
if (!Exec()) return false;
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Args = $"rm -rf {relativePath}";
|
2021-04-29 05:05:55 -07:00
|
|
|
|
return Exec();
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
protected override void OnReadline(string line) {
|
|
|
|
|
_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
|
|
|
|
}
|
|
|
|
|
}
|