Fixed Git manager lol

This commit is contained in:
Anemunt
2025-12-22 20:20:47 -05:00
parent 534d513be2
commit 7a2497ebfd

View File

@@ -25,6 +25,15 @@ bool containsPath(const std::vector<fs::path>& haystack, const fs::path& needle)
return false; return false;
} }
bool isGitRepo(const fs::path& root) {
std::error_code ec;
fs::path dotGit = root / ".git";
if (fs::exists(dotGit, ec)) {
return true;
}
return false;
}
fs::path guessIncludeDir(const fs::path& repoRoot, const std::string& includeRel) { fs::path guessIncludeDir(const fs::path& repoRoot, const std::string& includeRel) {
if (!includeRel.empty()) { if (!includeRel.empty()) {
fs::path candidate = normalizePath(repoRoot / includeRel); fs::path candidate = normalizePath(repoRoot / includeRel);
@@ -94,13 +103,25 @@ bool PackageManager::remove(const std::string& id) {
} }
if (pkg->external) { if (pkg->external) {
std::string log; std::string log;
std::string deinitCmd = "git submodule deinit -f \"" + pkg->localPath.string() + "\""; if (isGitRepo(projectRoot)) {
std::error_code ec;
fs::path relPath = fs::relative(pkg->localPath, projectRoot, ec);
std::string rel = (!ec ? relPath : pkg->localPath).generic_string();
std::string deinitCmd = "git -C \"" + projectRoot.string() + "\" submodule deinit -f \"" + rel + "\"";
runCommand(deinitCmd, log); // best-effort runCommand(deinitCmd, log); // best-effort
std::string rmCmd = "git rm -f \"" + pkg->localPath.string() + "\""; std::string rmCmd = "git -C \"" + projectRoot.string() + "\" rm -f \"" + rel + "\"";
if (!runCommand(rmCmd, log)) { if (!runCommand(rmCmd, log)) {
lastError = "Failed to remove submodule. Git log:\n" + log; lastError = "Failed to remove submodule. Git log:\n" + log;
return false; return false;
} }
} else {
std::error_code ec;
fs::remove_all(pkg->localPath, ec);
if (ec) {
lastError = "Failed to remove package folder: " + ec.message();
return false;
}
}
} }
auto it = std::remove(installedIds.begin(), installedIds.end(), id); auto it = std::remove(installedIds.begin(), installedIds.end(), id);
@@ -421,10 +442,22 @@ bool PackageManager::installGitPackage(const std::string& url,
fs::path dest = normalizePath(packagesFolder() / id); fs::path dest = normalizePath(packagesFolder() / id);
fs::create_directories(dest.parent_path()); fs::create_directories(dest.parent_path());
std::string cmd = "git submodule add --force \"" + url + "\" \"" + dest.string() + "\""; std::string cmd;
if (isGitRepo(projectRoot)) {
std::error_code ec;
fs::path relPath = fs::relative(dest, projectRoot, ec);
std::string rel = (!ec ? relPath : dest).generic_string();
cmd = "git -C \"" + projectRoot.string() + "\" submodule add --force \"" + url + "\" \"" + rel + "\"";
} else {
cmd = "git clone \"" + url + "\" \"" + dest.string() + "\"";
}
std::string log; std::string log;
if (!runCommand(cmd, log)) { if (!runCommand(cmd, log)) {
if (isGitRepo(projectRoot)) {
lastError = "git submodule add failed:\n" + log; lastError = "git submodule add failed:\n" + log;
} else {
lastError = "git clone failed:\n" + log;
}
return false; return false;
} }