Services
Contains the concrete
LibGit2Sharpintegration and file upload orchestration.
GitCloneService
The GitCloneService implements IGitCloneService and performs the physical repository clone and subsequent data sync.
Deep Business Logic and Flow
-
Path Resolution & Sanitation: The target URL is parsed to extract a valid filesystem name. The service maps the repository into a structured hierarchy on a local high-performance volume:
{baseReposPath}/{tenantId}/{projectId}/{repoName}. This ensures absolute multi-tenant data isolation on disk. -
Directory Cleanup: Before cloning, any existing repository at the target path is forcibly deleted. This eliminates git-lock issues and guarantees that the pull is a pristine, complete representation of the external state.
-
Authentication & Submodules: If a
GitTokenis present in the request, it is mapped into a LibGit2SharpUsernamePasswordCredentialsprovider (using the defaultoauth2username). The service executes a robust clone operation that recursively fetches all submodules to ensure the code context is whole. -
S3 Synchronization: Once the code is securely on disk, the service triggers
IRepoFileStore.UploadRepositoryAsync. The locally cloned code is uploaded into the S3 object store. During this process, user-definedFileExclusionsare applied (e.g., ignoring binaries or compiled assets) to avoid polluting the object storage and context windows with unnecessary data. -
Error Containment: Git operations are notoriously prone to network and auth exceptions (
LibGit2SharpException). The service wraps the operation in strict try-catch blocks to prevent worker crashes, mapping specific failures into a controlledGitCloneResultwhereSuccess = falseand logging the error message.