@@ -73,7 +73,9 @@ def init(self, overwrite: bool = False):
73
73
err = C .git_submodule_init (self ._subm , int (overwrite ))
74
74
check_error (err )
75
75
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
+ ):
77
79
"""
78
80
Update a submodule. This will clone a missing submodule and checkout
79
81
the subrepository to the commit specified in the index of the
@@ -90,12 +92,17 @@ def update(self, init: bool = False, callbacks: RemoteCallbacks = None):
90
92
91
93
callbacks
92
94
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).
93
99
"""
94
100
95
101
opts = ffi .new ('git_submodule_update_options *' )
96
102
C .git_submodule_update_options_init (
97
103
opts , C .GIT_SUBMODULE_UPDATE_OPTIONS_VERSION
98
104
)
105
+ opts .fetch_opts .depth = depth
99
106
100
107
with git_fetch_options (callbacks , opts = opts .fetch_opts ) as payload :
101
108
err = C .git_submodule_update (self ._subm , int (init ), opts )
@@ -188,6 +195,7 @@ def add(
188
195
path : str ,
189
196
link : bool = True ,
190
197
callbacks : Optional [RemoteCallbacks ] = None ,
198
+ depth : int = 0 ,
191
199
) -> Submodule :
192
200
"""
193
201
Add a submodule to the index.
@@ -208,6 +216,10 @@ def add(
208
216
209
217
callbacks
210
218
Optional RemoteCallbacks to clone the submodule.
219
+
220
+ depth
221
+ Number of commits to fetch.
222
+ The default is 0 (full commit history).
211
223
"""
212
224
csub = ffi .new ('git_submodule **' )
213
225
curl = ffi .new ('char[]' , to_bytes (url ))
@@ -226,6 +238,7 @@ def add(
226
238
C .git_submodule_update_options_init (
227
239
opts , C .GIT_SUBMODULE_UPDATE_OPTIONS_VERSION
228
240
)
241
+ opts .fetch_opts .depth = depth
229
242
230
243
with git_fetch_options (callbacks , opts = opts .fetch_opts ) as payload :
231
244
crepo = ffi .new ('git_repository **' )
@@ -268,6 +281,7 @@ def update(
268
281
submodules : Optional [Iterable [str ]] = None ,
269
282
init : bool = False ,
270
283
callbacks : Optional [RemoteCallbacks ] = None ,
284
+ depth : int = 0 ,
271
285
):
272
286
"""
273
287
Update submodules. This will clone a missing submodule and checkout
@@ -289,14 +303,18 @@ def update(
289
303
290
304
callbacks
291
305
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).
292
310
"""
293
311
if submodules is None :
294
312
submodules = self ._repository .listall_submodules ()
295
313
296
314
instances = [self [s ] for s in submodules ]
297
315
298
316
for submodule in instances :
299
- submodule .update (init , callbacks )
317
+ submodule .update (init , callbacks , depth )
300
318
301
319
def status (
302
320
self , name : str , ignore : SubmoduleIgnore = SubmoduleIgnore .UNSPECIFIED
0 commit comments