From 0be24585e89f45b000391adb744eeb0bb6082879 Mon Sep 17 00:00:00 2001 From: test Date: Tue, 31 Mar 2026 21:21:08 +0900 Subject: [PATCH] feat: add depth option to clone/fetch for shallow clones Expose the existing protocol-level deepen support to the JavaScript API. The depth parameter is passed through to fetch_pack_with_http which encodes it as "deepen {depth}" in the git smart HTTP protocol. When depth is 0 (default), full clone behavior is preserved. When depth > 0, the server returns only the specified number of commits. Co-Authored-By: Claude Opus 4.6 (1M context) --- npm/lib.d.ts | 2 ++ npm/lib.js | 2 ++ src/lib/js_api_exports.mbt | 12 ++++++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/npm/lib.d.ts b/npm/lib.d.ts index b16af7d6..3fa62b29 100644 --- a/npm/lib.d.ts +++ b/npm/lib.d.ts @@ -179,6 +179,7 @@ export type BitResetMode = "soft" | "mixed" | "hard"; export interface BitFetchOptions { refspec?: string; preferV2?: boolean; + depth?: number; preferredSender?: string; preferredRepo?: string; authToken?: string; @@ -186,6 +187,7 @@ export interface BitFetchOptions { export interface BitCloneOptions { preferV2?: boolean; + depth?: number; preferredSender?: string; preferredRepo?: string; authToken?: string; diff --git a/npm/lib.js b/npm/lib.js index 2c78f031..563dc243 100644 --- a/npm/lib.js +++ b/npm/lib.js @@ -1124,6 +1124,7 @@ export const fetch = async ( toTransportId(transport), options.refspec ?? "", options.preferV2 !== false, + options.depth ?? 0, ), ); }; @@ -1151,6 +1152,7 @@ export const clone = async ( resolvedRemoteUrl, toTransportId(transport), options.preferV2 !== false, + options.depth ?? 0, ), ); }; diff --git a/src/lib/js_api_exports.mbt b/src/lib/js_api_exports.mbt index a72c6951..ccc08e0f 100644 --- a/src/lib/js_api_exports.mbt +++ b/src/lib/js_api_exports.mbt @@ -2376,6 +2376,7 @@ pub async fn js_clone_remote( remote_url : String, transport_id : Int, prefer_v2 : Bool, + depth : Int, ) -> Result[JsCloneResult, String] { let fs = js_make_host_fs(host_id) js_wrap_error_async(async fn() -> JsCloneResult raise @bit.GitError { @@ -2412,7 +2413,7 @@ pub async fn js_clone_remote( remote_url, wants, prefer_v2, - 0, + depth, @protocol.FilterSpec::NoFilter, async fn( url : String, @@ -2469,9 +2470,10 @@ pub fn js_clone_remote_promise( remote_url : String, transport_id : Int, prefer_v2 : Bool, + depth : Int, ) -> @js_async.Promise[Result[JsCloneResult, String]] { js_export_promise(async fn() { - js_clone_remote(host_id, root, remote_url, transport_id, prefer_v2) + js_clone_remote(host_id, root, remote_url, transport_id, prefer_v2, depth) }) } @@ -2483,6 +2485,7 @@ pub async fn js_fetch_remote( transport_id : Int, refspec : String, prefer_v2 : Bool, + depth : Int, ) -> Result[JsFetchResult, String] { let fs = js_make_host_fs(host_id) js_wrap_error_async(async fn() -> JsFetchResult raise @bit.GitError { @@ -2511,7 +2514,7 @@ pub async fn js_fetch_remote( remote_url, [commit_id], prefer_v2, - 0, + depth, @protocol.FilterSpec::NoFilter, async fn( url : String, @@ -2560,9 +2563,10 @@ pub fn js_fetch_remote_promise( transport_id : Int, refspec : String, prefer_v2 : Bool, + depth : Int, ) -> @js_async.Promise[Result[JsFetchResult, String]] { js_export_promise(async fn() { - js_fetch_remote(host_id, root, remote_url, transport_id, refspec, prefer_v2) + js_fetch_remote(host_id, root, remote_url, transport_id, refspec, prefer_v2, depth) }) }