@@ -255,6 +255,79 @@ it.layer(TestLayer)("WorkspacePathsLive", (it) => {
255255 } ) ,
256256 ) ;
257257
258+ it . effect ( "lets Git reject malformed gitfiles instead of probing an unrelated target" , ( ) =>
259+ Effect . gen ( function * ( ) {
260+ const workspacePaths = yield * WorkspacePaths . WorkspacePaths ;
261+ const vcsProcess = yield * VcsProcess . VcsProcess ;
262+ const root = yield * makeBareRoot ( ) ;
263+ for ( const pointer of [ "metadata\ngitdir: .bare\n" , "gitdir:.bare\n" , " gitdir: .bare\n" ] ) {
264+ yield * writeTextFile ( root , ".git" , pointer ) ;
265+ const native = yield * vcsProcess . run ( {
266+ operation : "WorkspacePaths.test.malformedGitfile" ,
267+ command : "git" ,
268+ cwd : root ,
269+ args : [ "rev-parse" , "--is-bare-repository" ] ,
270+ allowNonZeroExit : true ,
271+ } ) ;
272+ expect ( native . exitCode ) . not . toBe ( 0 ) ;
273+ expect ( yield * workspacePaths . ensureNotBareRepositoryLayout ( root ) ) . toBe ( root ) ;
274+ }
275+ } ) ,
276+ ) ;
277+
278+ it . effect . skipIf ( HostProcessPlatform . defaultValue ( ) === "win32" ) (
279+ "preserves trailing spaces in POSIX gitdir names" ,
280+ ( ) =>
281+ Effect . gen ( function * ( ) {
282+ const workspacePaths = yield * WorkspacePaths . WorkspacePaths ;
283+ const path = yield * Path . Path ;
284+ const root = yield * makeTempDir ( ) ;
285+ yield * runGit ( root , [ "init" , "--separate-git-dir" , path . join ( root , "store " ) ] ) ;
286+ yield * runGit ( root , [ "init" , "--bare" , path . join ( root , "store" ) ] ) ;
287+ expect ( ( yield * runGit ( root , [ "rev-parse" , "--is-inside-work-tree" ] ) ) . stdout . trim ( ) ) . toBe (
288+ "true" ,
289+ ) ;
290+
291+ expect ( yield * workspacePaths . ensureNotBareRepositoryLayout ( root ) ) . toBe ( root ) ;
292+ } ) ,
293+ ) ;
294+
295+ it . effect (
296+ "classifies the root independently of inherited Git worktree and gitdir overrides" ,
297+ ( ) =>
298+ Effect . gen ( function * ( ) {
299+ const vcsProcess = yield * VcsProcess . VcsProcess ;
300+ const path = yield * Path . Path ;
301+ const root = yield * makeBareRoot ( ) ;
302+ const otherRoot = yield * makeTempDir ( ) ;
303+ yield * runGit ( otherRoot , [ "init" ] ) ;
304+ for ( const inheritedEnv of [
305+ { GIT_WORK_TREE : root } ,
306+ { GIT_DIR : path . join ( otherRoot , ".git" ) } ,
307+ ] ) {
308+ const native = yield * vcsProcess . run ( {
309+ operation : "WorkspacePaths.test.inheritedGitEnvironment" ,
310+ command : "git" ,
311+ cwd : root ,
312+ args : [ "rev-parse" , "--is-bare-repository" ] ,
313+ env : inheritedEnv ,
314+ } ) ;
315+ expect ( native . stdout . trim ( ) ) . toBe ( "false" ) ;
316+ const workspacePaths = yield * WorkspacePaths . make . pipe (
317+ Effect . provideService ( VcsProcess . VcsProcess , {
318+ run : ( input ) =>
319+ vcsProcess . run ( { ...input , env : { ...inheritedEnv , ...input . env } } ) ,
320+ } ) ,
321+ ) ;
322+
323+ const error = yield * workspacePaths
324+ . ensureNotBareRepositoryLayout ( root )
325+ . pipe ( Effect . flip ) ;
326+ expect ( error ) . toBeInstanceOf ( WorkspacePaths . WorkspaceRootBareRepositoryLayoutError ) ;
327+ }
328+ } ) ,
329+ ) ;
330+
258331 it . effect . skipIf ( HostProcessPlatform . defaultValue ( ) === "win32" ) (
259332 "preserves literal backslashes in POSIX gitdir names" ,
260333 ( ) =>
0 commit comments