Skip to main content

clone_repository

Function clone_repository 

Source
pub async fn clone_repository(
    url: &str,
    branch: Option<&str>,
    tag: Option<&str>,
    auth: Option<&SourceAuth>,
) -> Result<TempDir, ServiceError>
Expand description

Clone a git repository to a temporary directory.

This function uses the system git binary to clone a repository. It performs shallow clones (depth=1) for optimal performance and supports branch/tag checkout.

§Arguments

  • url - Git repository URL (HTTPS, SSH, or GitHub tree URL)
  • branch - Optional branch name to checkout after clone
  • tag - Optional tag name to checkout after clone (mutually exclusive with branch)
  • auth - Deprecated: Ignored, system git handles authentication automatically

§Returns

Returns a TempDir containing the cloned repository. The directory is automatically cleaned up when the TempDir is dropped.

§Errors

Returns ServiceError if:

  • Git is not installed or not in PATH
  • Git version is too old (< 2.0)
  • Clone operation fails (network error, invalid URL, authentication failure)
  • Checkout operation fails
  • Operation times out (5 minute timeout for clone)

§Examples

use fastskill::storage::git::clone_repository;

let temp_dir = clone_repository(
    "https://github.com/example/repo.git",
    Some("main"),
    None,
    None,
).await?;
// Use temp_dir.path() to access cloned repository