@@ -209,6 +209,32 @@ public void OpenRepository_WorkingDirectorySpecifiedInConfig()
209209 Assert . Equal ( workingDir2 . Path , repository . WorkingDirectory ) ;
210210 }
211211
212+ [ Fact ]
213+ public void OpenRepository_SparseV2 ( )
214+ {
215+ using var temp = new TempRoot ( ) ;
216+
217+ var workingDir = temp . CreateDirectory ( ) ;
218+ var gitDir = workingDir . CreateDirectory ( ".git" ) ;
219+
220+ gitDir . CreateFile ( "HEAD" ) ;
221+ gitDir . CreateFile ( "config" ) . WriteAllText ( @"
222+ [core]
223+ repositoryformatversion = 1
224+ [extensions]
225+ worktreeConfig = true" ) ;
226+
227+ Assert . True ( GitRepository . TryFindRepository ( gitDir . Path , out var location ) ) ;
228+ Assert . Equal ( gitDir . Path , location . CommonDirectory ) ;
229+ Assert . Equal ( gitDir . Path , location . GitDirectory ) ;
230+ Assert . Null ( location . WorkingDirectory ) ;
231+
232+ var repository = GitRepository . OpenRepository ( location , GitEnvironment . Empty ) ;
233+ Assert . Equal ( gitDir . Path , repository . CommonDirectory ) ;
234+ Assert . Equal ( gitDir . Path , repository . GitDirectory ) ;
235+ Assert . Null ( repository . WorkingDirectory ) ;
236+ }
237+
212238 [ Fact ]
213239 public void OpenRepository_VersionNotSupported ( )
214240 {
@@ -223,7 +249,32 @@ public void OpenRepository_VersionNotSupported()
223249 gitDir . CreateDirectory ( "refs" ) . CreateDirectory ( "heads" ) . CreateFile ( "master" ) . WriteAllText ( "0000000000000000000000000000000000000000" ) ;
224250 gitDir . CreateDirectory ( "objects" ) ;
225251
226- gitDir . CreateFile ( "config" ) . WriteAllText ( "[core]repositoryformatversion = 1" ) ;
252+ gitDir . CreateFile ( "config" ) . WriteAllText ( "[core]repositoryformatversion = 2" ) ;
253+
254+ var src = workingDir . CreateDirectory ( "src" ) ;
255+
256+ Assert . Throws < NotSupportedException > ( ( ) => GitRepository . OpenRepository ( src . Path , new GitEnvironment ( homeDir . Path ) ) ) ;
257+ }
258+
259+ [ Fact ]
260+ public void OpenRepository_V2ExtensionNotSupported ( )
261+ {
262+ using var temp = new TempRoot ( ) ;
263+
264+ var homeDir = temp . CreateDirectory ( ) ;
265+
266+ var workingDir = temp . CreateDirectory ( ) ;
267+ var gitDir = workingDir . CreateDirectory ( ".git" ) ;
268+
269+ gitDir . CreateFile ( "HEAD" ) . WriteAllText ( "ref: refs/heads/master" ) ;
270+ gitDir . CreateDirectory ( "refs" ) . CreateDirectory ( "heads" ) . CreateFile ( "master" ) . WriteAllText ( "0000000000000000000000000000000000000000" ) ;
271+ gitDir . CreateDirectory ( "objects" ) ;
272+
273+ gitDir . CreateFile ( "config" ) . WriteAllText ( @"
274+ [core]
275+ repositoryformatversion = 1
276+ [extensions]
277+ newExtension = true" ) ;
227278
228279 var src = workingDir . CreateDirectory ( "src" ) ;
229280
0 commit comments