@@ -73,7 +73,9 @@ def init(self, overwrite: bool = False):
7373 err = C .git_submodule_init (self ._subm , int (overwrite ))
7474 check_error (err )
7575
76- def update (self , init : bool = False , callbacks : RemoteCallbacks = None ):
76+ def update (
77+ self , init : bool = False , callbacks : RemoteCallbacks = None , depth : int = 0
78+ ):
7779 """
7880 Update a submodule. This will clone a missing submodule and checkout
7981 the subrepository to the commit specified in the index of the
@@ -90,12 +92,17 @@ def update(self, init: bool = False, callbacks: RemoteCallbacks = None):
9092
9193 callbacks
9294 Optional RemoteCallbacks to clone or fetch the submodule.
95+
96+ depth
97+ Number of commits to fetch.
98+ The default is 0 (full commit history).
9399 """
94100
95101 opts = ffi .new ('git_submodule_update_options *' )
96102 C .git_submodule_update_options_init (
97103 opts , C .GIT_SUBMODULE_UPDATE_OPTIONS_VERSION
98104 )
105+ opts .fetch_opts .depth = depth
99106
100107 with git_fetch_options (callbacks , opts = opts .fetch_opts ) as payload :
101108 err = C .git_submodule_update (self ._subm , int (init ), opts )
@@ -188,6 +195,7 @@ def add(
188195 path : str ,
189196 link : bool = True ,
190197 callbacks : Optional [RemoteCallbacks ] = None ,
198+ depth : int = 0 ,
191199 ) -> Submodule :
192200 """
193201 Add a submodule to the index.
@@ -208,6 +216,10 @@ def add(
208216
209217 callbacks
210218 Optional RemoteCallbacks to clone the submodule.
219+
220+ depth
221+ Number of commits to fetch.
222+ The default is 0 (full commit history).
211223 """
212224 csub = ffi .new ('git_submodule **' )
213225 curl = ffi .new ('char[]' , to_bytes (url ))
@@ -226,6 +238,7 @@ def add(
226238 C .git_submodule_update_options_init (
227239 opts , C .GIT_SUBMODULE_UPDATE_OPTIONS_VERSION
228240 )
241+ opts .fetch_opts .depth = depth
229242
230243 with git_fetch_options (callbacks , opts = opts .fetch_opts ) as payload :
231244 crepo = ffi .new ('git_repository **' )
@@ -268,6 +281,7 @@ def update(
268281 submodules : Optional [Iterable [str ]] = None ,
269282 init : bool = False ,
270283 callbacks : Optional [RemoteCallbacks ] = None ,
284+ depth : int = 0 ,
271285 ):
272286 """
273287 Update submodules. This will clone a missing submodule and checkout
@@ -289,14 +303,18 @@ def update(
289303
290304 callbacks
291305 Optional RemoteCallbacks to clone or fetch the submodule.
306+
307+ depth
308+ Number of commits to fetch.
309+ The default is 0 (full commit history).
292310 """
293311 if submodules is None :
294312 submodules = self ._repository .listall_submodules ()
295313
296314 instances = [self [s ] for s in submodules ]
297315
298316 for submodule in instances :
299- submodule .update (init , callbacks )
317+ submodule .update (init , callbacks , depth )
300318
301319 def status (
302320 self , name : str , ignore : SubmoduleIgnore = SubmoduleIgnore .UNSPECIFIED
0 commit comments