@@ -88,3 +88,179 @@ describe('git-auth-helper tests', () => {
8888    expect ( branches . sort ( ) ) . toEqual ( [ 'foo' ] . sort ( ) ) 
8989  } ) 
9090} ) 
91+ 
92+ describe ( 'Test fetchDepth and fetchTags options' ,  ( )  =>  { 
93+   beforeEach ( async  ( )  =>  { 
94+     jest . spyOn ( fshelper ,  'fileExistsSync' ) . mockImplementation ( jest . fn ( ) ) 
95+     jest . spyOn ( fshelper ,  'directoryExistsSync' ) . mockImplementation ( jest . fn ( ) ) 
96+     mockExec . mockImplementation ( ( path ,  args ,  options )  =>  { 
97+       console . log ( args ,  options . listeners . stdout ) 
98+ 
99+       if  ( args . includes ( 'version' ) )  { 
100+         options . listeners . stdout ( Buffer . from ( '2.18' ) ) 
101+       } 
102+ 
103+       return  0 
104+     } ) 
105+   } ) 
106+ 
107+   afterEach ( ( )  =>  { 
108+     jest . restoreAllMocks ( ) 
109+   } ) 
110+ 
111+   it ( 'should call execGit with the correct arguments when fetchDepth is 0 and fetchTags is true' ,  async  ( )  =>  { 
112+     jest . spyOn ( exec ,  'exec' ) . mockImplementation ( mockExec ) 
113+     const  workingDirectory  =  'test' 
114+     const  lfs  =  false 
115+     const  doSparseCheckout  =  false 
116+     git  =  await  commandManager . createCommandManager ( 
117+       workingDirectory , 
118+       lfs , 
119+       doSparseCheckout 
120+     ) 
121+ 
122+     const  refSpec  =  [ 'refspec1' ,  'refspec2' ] 
123+     const  options  =  { 
124+       filter : 'filterValue' , 
125+       fetchDepth : 0 , 
126+       fetchTags : true 
127+     } 
128+ 
129+     await  git . fetch ( refSpec ,  options ) 
130+ 
131+     expect ( mockExec ) . toHaveBeenCalledWith ( 
132+       expect . any ( String ) , 
133+       [ 
134+         '-c' , 
135+         'protocol.version=2' , 
136+         'fetch' , 
137+         '--prune' , 
138+         '--progress' , 
139+         '--no-recurse-submodules' , 
140+         '--filter=filterValue' , 
141+         'origin' , 
142+         'refspec1' , 
143+         'refspec2' 
144+       ] , 
145+       expect . any ( Object ) 
146+     ) 
147+   } ) 
148+ 
149+   it ( 'should call execGit with the correct arguments when fetchDepth is 0 and fetchTags is false' ,  async  ( )  =>  { 
150+     jest . spyOn ( exec ,  'exec' ) . mockImplementation ( mockExec ) 
151+ 
152+     const  workingDirectory  =  'test' 
153+     const  lfs  =  false 
154+     const  doSparseCheckout  =  false 
155+     git  =  await  commandManager . createCommandManager ( 
156+       workingDirectory , 
157+       lfs , 
158+       doSparseCheckout 
159+     ) 
160+     const  refSpec  =  [ 'refspec1' ,  'refspec2' ] 
161+     const  options  =  { 
162+       filter : 'filterValue' , 
163+       fetchDepth : 0 , 
164+       fetchTags : false 
165+     } 
166+ 
167+     await  git . fetch ( refSpec ,  options ) 
168+ 
169+     expect ( mockExec ) . toHaveBeenCalledWith ( 
170+       expect . any ( String ) , 
171+       [ 
172+         '-c' , 
173+         'protocol.version=2' , 
174+         'fetch' , 
175+         '--no-tags' , 
176+         '--prune' , 
177+         '--progress' , 
178+         '--no-recurse-submodules' , 
179+         '--filter=filterValue' , 
180+         'origin' , 
181+         'refspec1' , 
182+         'refspec2' 
183+       ] , 
184+       expect . any ( Object ) 
185+     ) 
186+   } ) 
187+ 
188+   it ( 'should call execGit with the correct arguments when fetchDepth is 1 and fetchTags is false' ,  async  ( )  =>  { 
189+     jest . spyOn ( exec ,  'exec' ) . mockImplementation ( mockExec ) 
190+ 
191+     const  workingDirectory  =  'test' 
192+     const  lfs  =  false 
193+     const  doSparseCheckout  =  false 
194+     git  =  await  commandManager . createCommandManager ( 
195+       workingDirectory , 
196+       lfs , 
197+       doSparseCheckout 
198+     ) 
199+     const  refSpec  =  [ 'refspec1' ,  'refspec2' ] 
200+     const  options  =  { 
201+       filter : 'filterValue' , 
202+       fetchDepth : 1 , 
203+       fetchTags : false 
204+     } 
205+ 
206+     await  git . fetch ( refSpec ,  options ) 
207+ 
208+     expect ( mockExec ) . toHaveBeenCalledWith ( 
209+       expect . any ( String ) , 
210+       [ 
211+         '-c' , 
212+         'protocol.version=2' , 
213+         'fetch' , 
214+         '--no-tags' , 
215+         '--prune' , 
216+         '--progress' , 
217+         '--no-recurse-submodules' , 
218+         '--filter=filterValue' , 
219+         '--depth=1' , 
220+         'origin' , 
221+         'refspec1' , 
222+         'refspec2' 
223+       ] , 
224+       expect . any ( Object ) 
225+     ) 
226+   } ) 
227+ 
228+   it ( 'should call execGit with the correct arguments when fetchDepth is 1 and fetchTags is true' ,  async  ( )  =>  { 
229+     jest . spyOn ( exec ,  'exec' ) . mockImplementation ( mockExec ) 
230+ 
231+     const  workingDirectory  =  'test' 
232+     const  lfs  =  false 
233+     const  doSparseCheckout  =  false 
234+     git  =  await  commandManager . createCommandManager ( 
235+       workingDirectory , 
236+       lfs , 
237+       doSparseCheckout 
238+     ) 
239+     const  refSpec  =  [ 'refspec1' ,  'refspec2' ] 
240+     const  options  =  { 
241+       filter : 'filterValue' , 
242+       fetchDepth : 1 , 
243+       fetchTags : true 
244+     } 
245+ 
246+     await  git . fetch ( refSpec ,  options ) 
247+ 
248+     expect ( mockExec ) . toHaveBeenCalledWith ( 
249+       expect . any ( String ) , 
250+       [ 
251+         '-c' , 
252+         'protocol.version=2' , 
253+         'fetch' , 
254+         '--prune' , 
255+         '--progress' , 
256+         '--no-recurse-submodules' , 
257+         '--filter=filterValue' , 
258+         '--depth=1' , 
259+         'origin' , 
260+         'refspec1' , 
261+         'refspec2' 
262+       ] , 
263+       expect . any ( Object ) 
264+     ) 
265+   } ) 
266+ } ) 
0 commit comments