Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/pull_module/libgit2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,33 @@ void removeLfsWipMarker(const std::string& repositoryPath) {
}
}

/**
* Attempts to remove stale lfs_error.txt file from a repository.
* If the file cannot be checked or deleted, logs a warning but does not fail the operation.
* This function clears error artifacts that would otherwise interfere with resume/clone detection.
*
* @param repositoryPath Path to the git repository root directory.
* @note Logs warnings if file operations fail; operation continues on error.
*/
static void clearStaleErrorFile(const std::string& repositoryPath) {
std::error_code ec;
const fs::path errorFilePath = fs::path(repositoryPath) / "lfs_error.txt";

bool fileExists = fs::exists(errorFilePath, ec);
if (ec) {
SPDLOG_WARN("Failed to check if lfs_error.txt exists at {}: {}. May interfere with resume/clone detection.",
errorFilePath.string(), ec.message());
return;
}

if (fileExists) {
if (!fs::remove(errorFilePath, ec)) {
SPDLOG_WARN("Failed to remove stale lfs_error.txt at {}: {}. May interfere with resume/clone detection.",
errorFilePath.string(), ec.message());
}
}
}

} // namespace libgit2

namespace {
Expand Down Expand Up @@ -1193,6 +1220,9 @@ Status resumeExistingRepository(git_repository* repo,
SPDLOG_WARN("Failed to create .lfswip marker before pull resume at {}", libgit2::getLfsWipMarkerPath(downloadPath).string());
}

// Clear any stale lfs_error.txt from previous failed attempts to avoid false error reports
libgit2::clearStaleErrorFile(downloadPath);

printResumeCandidates(candidates);

for (const auto& p : candidates.lfsMatches) {
Expand Down Expand Up @@ -1391,6 +1421,9 @@ Status handleFreshClone(const std::string& downloadPath,
const std::function<Status(const std::string&)>& removeReadonlyFn) {
SPDLOG_DEBUG("Downloading to path: {}", downloadPath);

// Clear any stale lfs_error.txt from previous failed attempts to avoid false error reports
libgit2::clearStaleErrorFile(downloadPath);

git_clone_options cloneOptions = GIT_CLONE_OPTIONS_INIT;
configureCloneOptions(cloneOptions, useProxy, proxyUrl);

Expand Down
Loading