@@ -244,6 +244,52 @@ public void CanCreateATreeContainingABlobFromAFileInTheWorkingDirectory()
244
244
}
245
245
}
246
246
247
+ [ Fact ]
248
+ public void CanCreateATreeContainingAGitLinkFromAnUntrackedSubmoduleInTheWorkingDirectory ( )
249
+ {
250
+ string path = CloneSubmoduleTestRepo ( ) ;
251
+ using ( var repo = new Repository ( path ) )
252
+ {
253
+ const string submodulePath = "sm_added_and_uncommited" ;
254
+
255
+ /* Unexpected behavior: test fails if this is uncommented... libgit2 caching?
256
+ var submoduleBefore = repo.Submodules[submodulePath];
257
+ Assert.NotNull(submoduleBefore);
258
+ Assert.Null(submoduleBefore.HeadCommitId);
259
+ /**/
260
+
261
+ var gitLink = repo . ObjectDatabase . CreateGitLink ( ( ObjectId ) "480095882d281ed676fe5b863569520e54a7d5c0" ) ;
262
+
263
+ TreeDefinition td = TreeDefinition . From ( repo . Head . Tip . Tree )
264
+ . Add ( submodulePath , gitLink ) ;
265
+
266
+ TreeEntryDefinition ted = td [ submodulePath ] ;
267
+ Assert . NotNull ( ted ) ;
268
+ Assert . Equal ( Mode . GitLink , ted . Mode ) ;
269
+ Assert . Equal ( gitLink . Id , ted . TargetId ) ;
270
+ Assert . Equal ( GitObjectType . Commit , ted . Type ) ;
271
+
272
+ Tree tree = repo . ObjectDatabase . CreateTree ( td ) ;
273
+
274
+ TreeEntry te = tree [ submodulePath ] ;
275
+ Assert . NotNull ( te . Target ) ;
276
+ Assert . IsType < GitLink > ( te . Target ) ;
277
+ Assert . Equal ( gitLink . Id , te . Target . Id ) ;
278
+
279
+ var commitWithSubmodule = repo . ObjectDatabase . CreateCommit ( "Submodule!" , DummySignature , DummySignature , tree ,
280
+ new [ ] { repo . Head . Tip } ) ;
281
+ repo . Reset ( ResetOptions . Soft , commitWithSubmodule ) ;
282
+
283
+ var submodule = repo . Submodules [ submodulePath ] ;
284
+ Assert . NotNull ( submodule ) ;
285
+ Assert . Equal ( submodulePath , submodule . Name ) ;
286
+ Assert . Equal ( submodulePath , submodule . Path ) ;
287
+
288
+ // This fails with HeadCommitId == null if lines above are uncommented
289
+ Assert . Equal ( gitLink . Id , submodule . HeadCommitId ) ;
290
+ }
291
+ }
292
+
247
293
[ Fact ]
248
294
public void CannotCreateATreeContainingABlobFromARelativePathAgainstABareRepository ( )
249
295
{
0 commit comments