@@ -111,6 +111,27 @@ public void CanAddAnExistingTreeEntryDefinition(string sourcePath, string target
111
111
}
112
112
}
113
113
114
+ [ Fact ]
115
+ public void CanAddAnExistingGitLinkTreeEntryDefinition ( )
116
+ {
117
+ const string sourcePath = "sm_unchanged" ;
118
+ const string targetPath = "sm_from_td" ;
119
+
120
+ using ( var repo = new Repository ( SubmoduleTestRepoWorkingDirPath ) )
121
+ {
122
+ TreeDefinition td = TreeDefinition . From ( repo . Head . Tip . Tree ) ;
123
+ Assert . Null ( td [ targetPath ] ) ;
124
+
125
+ TreeEntryDefinition ted = td [ sourcePath ] ;
126
+ td . Add ( targetPath , ted ) ;
127
+
128
+ TreeEntryDefinition fetched = td [ targetPath ] ;
129
+ Assert . NotNull ( fetched ) ;
130
+
131
+ Assert . Equal ( ted , fetched ) ;
132
+ }
133
+ }
134
+
114
135
[ Theory ]
115
136
[ InlineData ( "a8233120f6ad708f843d861ce2b7228ec4e3dec6" , "README_TOO" ) ]
116
137
[ InlineData ( "a8233120f6ad708f843d861ce2b7228ec4e3dec6" , "1/README" ) ]
@@ -217,6 +238,109 @@ public void CanReplaceAnExistingBlobWithATree(string targetPath)
217
238
}
218
239
}
219
240
241
+ [ Fact ]
242
+ public void CanReplaceAnExistingTreeWithAGitLink ( )
243
+ {
244
+ var commitId = ( ObjectId ) "480095882d281ed676fe5b863569520e54a7d5c0" ;
245
+ const string targetPath = "just_a_dir" ;
246
+
247
+ using ( var repo = new Repository ( SubmoduleTestRepoWorkingDirPath ) )
248
+ {
249
+ TreeDefinition td = TreeDefinition . From ( repo . Head . Tip . Tree ) ;
250
+ Assert . Equal ( GitObjectType . Tree , td [ targetPath ] . Type ) ;
251
+
252
+ Assert . NotNull ( td [ "just_a_dir/contents" ] ) ;
253
+
254
+ td . AddGitLink ( targetPath , commitId ) ;
255
+
256
+ TreeEntryDefinition fetched = td [ targetPath ] ;
257
+ Assert . NotNull ( fetched ) ;
258
+
259
+ Assert . Equal ( commitId , fetched . TargetId ) ;
260
+ Assert . Equal ( GitObjectType . Commit , fetched . Type ) ;
261
+ Assert . Equal ( Mode . GitLink , fetched . Mode ) ;
262
+
263
+ Assert . Null ( td [ "just_a_dir/contents" ] ) ;
264
+ }
265
+ }
266
+
267
+ [ Fact ]
268
+ public void CanReplaceAnExistingGitLinkWithATree ( )
269
+ {
270
+ const string treeSha = "607d96653d4d0a4f733107f7890c2e67b55b620d" ;
271
+ const string targetPath = "sm_unchanged" ;
272
+
273
+ using ( var repo = new Repository ( SubmoduleTestRepoWorkingDirPath ) )
274
+ {
275
+ TreeDefinition td = TreeDefinition . From ( repo . Head . Tip . Tree ) ;
276
+ Assert . NotNull ( td [ targetPath ] ) ;
277
+ Assert . Equal ( GitObjectType . Commit , td [ targetPath ] . Type ) ;
278
+ Assert . Equal ( Mode . GitLink , td [ targetPath ] . Mode ) ;
279
+
280
+ var objectId = new ObjectId ( treeSha ) ;
281
+ var tree = repo . Lookup < Tree > ( objectId ) ;
282
+
283
+ td . Add ( targetPath , tree ) ;
284
+
285
+ TreeEntryDefinition fetched = td [ targetPath ] ;
286
+ Assert . NotNull ( fetched ) ;
287
+
288
+ Assert . Equal ( objectId , fetched . TargetId ) ;
289
+ Assert . Equal ( GitObjectType . Tree , fetched . Type ) ;
290
+ Assert . Equal ( Mode . Directory , fetched . Mode ) ;
291
+ }
292
+ }
293
+
294
+ [ Fact ]
295
+ public void CanReplaceAnExistingBlobWithAGitLink ( )
296
+ {
297
+ var commitId = ( ObjectId ) "480095882d281ed676fe5b863569520e54a7d5c0" ;
298
+ const string targetPath = "just_a_file" ;
299
+
300
+ using ( var repo = new Repository ( SubmoduleTestRepoWorkingDirPath ) )
301
+ {
302
+ TreeDefinition td = TreeDefinition . From ( repo . Head . Tip . Tree ) ;
303
+ Assert . NotNull ( td [ targetPath ] ) ;
304
+ Assert . Equal ( GitObjectType . Blob , td [ targetPath ] . Type ) ;
305
+
306
+ td . AddGitLink ( targetPath , commitId ) ;
307
+
308
+ TreeEntryDefinition fetched = td [ targetPath ] ;
309
+ Assert . NotNull ( fetched ) ;
310
+
311
+ Assert . Equal ( GitObjectType . Commit , td [ targetPath ] . Type ) ;
312
+ Assert . Equal ( commitId , fetched . TargetId ) ;
313
+ Assert . Equal ( Mode . GitLink , fetched . Mode ) ;
314
+ }
315
+ }
316
+
317
+ [ Fact ]
318
+ public void CanReplaceAnExistingGitLinkWithABlob ( )
319
+ {
320
+ const string blobSha = "42cfb95cd01bf9225b659b5ee3edcc78e8eeb478" ;
321
+ const string targetPath = "sm_unchanged" ;
322
+
323
+ using ( var repo = new Repository ( SubmoduleTestRepoWorkingDirPath ) )
324
+ {
325
+ TreeDefinition td = TreeDefinition . From ( repo . Head . Tip . Tree ) ;
326
+ Assert . NotNull ( td [ targetPath ] ) ;
327
+ Assert . Equal ( GitObjectType . Commit , td [ targetPath ] . Type ) ;
328
+ Assert . Equal ( Mode . GitLink , td [ targetPath ] . Mode ) ;
329
+
330
+ var objectId = new ObjectId ( blobSha ) ;
331
+ var blob = repo . Lookup < Blob > ( objectId ) ;
332
+
333
+ td . Add ( targetPath , blob , Mode . NonExecutableFile ) ;
334
+
335
+ TreeEntryDefinition fetched = td [ targetPath ] ;
336
+ Assert . NotNull ( fetched ) ;
337
+
338
+ Assert . Equal ( objectId , fetched . TargetId ) ;
339
+ Assert . Equal ( GitObjectType . Blob , fetched . Type ) ;
340
+ Assert . Equal ( Mode . NonExecutableFile , fetched . Mode ) ;
341
+ }
342
+ }
343
+
220
344
[ Fact ]
221
345
public void CanNotReplaceAnExistingTreeWithATreeBeingAssembled ( )
222
346
{
0 commit comments