Skip to main content

clone

Function clone 

Source
pub fn clone(
    request: CloneRequest<'_>,
    services: CloneServices<'_>,
) -> Result<CloneOutcome>
Expand description

Clone the resolved source into a fresh repository at destination.

Performs the transport-shaped core the CLI’s clone_http_repository and the inline local clone path shared: initializes the repository, invokes configure to let the caller write the new repo’s config (returning the GitConfig to fetch against), fetches the configured refs (reusing crate::fetch::fetch with clone’s fixed options), creates the local checkout_branch at its fetched remote tip, invokes configure_branch to let the caller write the branch’s upstream config (returning the GitConfig to check out against), points refs/remotes/<origin>/HEAD at the remote default branch when appropriate, and checks out the worktree.

configure runs right after init (before the fetch) and must return the repository config; configure_branch runs right after the local branch is created (before the worktree checkout) and must return the config used for checkout. Splitting the config writes into these callbacks keeps the CLI’s config I/O helpers (which depend on CLI-specific config serialization and templates) out of the library while preserving their ordering in the flow.

Emits any library-side progress through progress and returns the structured CloneOutcome; never prints, mutates the process CWD, or returns GitError::Exit. A missing refs/remotes/<origin>/<checkout_branch> after the fetch is reported as GitError::NotFound for the caller to map (the CLI turns an explicit --branch miss into its own message).