@@ -566,6 +566,119 @@ it.effect.each(["bare", "unborn"] as const)(
566566 ) . pipe ( Effect . provide ( layerTest ) ) ,
567567) ;
568568
569+ it . effect . each ( [ "on a branch" , "detached" , "unborn" ] as const ) (
570+ "reads only the repository root for review requests that ignore the branch when %s" ,
571+ ( state ) =>
572+ Effect . scoped (
573+ Effect . gen ( function * ( ) {
574+ const delegate = yield * ChildProcessSpawner . ChildProcessSpawner ;
575+ const spawnedArgs : Array < ReadonlyArray < string > > = [ ] ;
576+ const spawner = ChildProcessSpawner . make ( ( command ) => {
577+ if ( ChildProcess . isStandardCommand ( command ) ) spawnedArgs . push ( command . args . map ( String ) ) ;
578+ return delegate . spawn ( command ) ;
579+ } ) ;
580+ const driver = yield * makeGitVcsDriverCore ( ) . pipe (
581+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
582+ ) ;
583+ const discoveries = ( ) => {
584+ const commands = spawnedArgs . filter (
585+ ( args ) =>
586+ args . includes ( "--show-toplevel" ) ||
587+ args . includes ( "--git-common-dir" ) ||
588+ ( args . includes ( "symbolic-ref" ) && args . includes ( "HEAD" ) ) ,
589+ ) ;
590+ spawnedArgs . length = 0 ;
591+ return commands . length ;
592+ } ;
593+ const cwd = yield * makeTmpDir ( ) ;
594+ if ( state === "unborn" ) {
595+ yield * git ( cwd , [ "init" , "-b" , "main" ] ) ;
596+ } else {
597+ yield * initRepoWithCommit ( cwd ) ;
598+ yield * writeTextFile ( cwd , "committed.txt" , "committed\n" ) ;
599+ yield * git ( cwd , [ "add" , "." ] ) ;
600+ yield * git ( cwd , [ "commit" , "-m" , "add file" ] ) ;
601+ if ( state === "detached" ) yield * git ( cwd , [ "checkout" , "--detach" ] ) ;
602+ }
603+ yield * writeTextFile ( cwd , "new.txt" , "new\n" ) ;
604+ spawnedArgs . length = 0 ;
605+
606+ const workingTree = yield * driver . getReviewDiffPreview ( {
607+ cwd,
608+ file : { path : "new.txt" , previousPath : null , sourceKind : "working-tree" } ,
609+ } ) ;
610+ assert . equal ( discoveries ( ) , 1 ) ;
611+ assert . deepStrictEqual (
612+ workingTree . sources
613+ . find ( ( source ) => source . kind === "working-tree" ) !
614+ . files ! . map ( ( file ) => file . path ) ,
615+ [ "new.txt" ] ,
616+ ) ;
617+
618+ if ( state !== "unborn" ) {
619+ const commitSha = yield * git ( cwd , [ "rev-parse" , "HEAD" ] ) ;
620+ spawnedArgs . length = 0 ;
621+ const commit = yield * driver . getReviewDiffPreview ( {
622+ cwd,
623+ commitSha,
624+ file : { path : "committed.txt" , previousPath : null , sourceKind : "commit" } ,
625+ } ) ;
626+ assert . equal ( discoveries ( ) , 1 ) ;
627+ assert . include ( commit . sources [ 0 ] ! . diff , "+committed" ) ;
628+ }
629+
630+ const general = yield * driver . getReviewDiffPreview ( { cwd } ) ;
631+ assert . equal ( discoveries ( ) , 3 ) ;
632+ assert . equal (
633+ general . sources . find ( ( source ) => source . kind === "branch-range" ) ! . headRef ,
634+ state === "detached" ? "HEAD" : yield * git ( cwd , [ "branch" , "--show-current" ] ) ,
635+ ) ;
636+ } ) ,
637+ ) . pipe ( Effect . provide ( layerTest ) ) ,
638+ ) ;
639+
640+ it . effect . each ( [
641+ { kind : "working-tree" , request : { sourceKind : "working-tree" } } ,
642+ { kind : "commit" , request : { sourceKind : "commit" , commitSha : "HEAD" } } ,
643+ ] as const ) ( "keeps $kind review requests safe without a worktree root" , ( { request } ) =>
644+ Effect . scoped (
645+ Effect . gen ( function * ( ) {
646+ const delegate = yield * ChildProcessSpawner . ChildProcessSpawner ;
647+ const bareRoot = yield * makeTmpDir ( "git-review-bare-" ) ;
648+ const spawner = ChildProcessSpawner . make ( ( command ) =>
649+ delegate . spawn (
650+ ChildProcess . isStandardCommand ( command ) && command . options . cwd === bareRoot
651+ ? ChildProcess . setEnv ( command , { GIT_DIR : bareRoot } )
652+ : command ,
653+ ) ,
654+ ) ;
655+ const driver = yield * makeGitVcsDriverCore ( ) . pipe (
656+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
657+ ) ;
658+ const path = yield * Path . Path ;
659+ const file = { path : "README.md" , previousPath : null , sourceKind : request . sourceKind } ;
660+ const input = ( cwd : string ) => ( {
661+ cwd,
662+ file,
663+ ...( "commitSha" in request ? { commitSha : request . commitSha } : { } ) ,
664+ } ) ;
665+ const source = yield * makeTmpDir ( ) ;
666+ yield * initRepoWithCommit ( source ) ;
667+ yield * git ( source , [ "clone" , "--bare" , source , bareRoot ] ) ;
668+ const nonRepository = yield * makeTmpDir ( ) ;
669+ for ( const cwd of [ bareRoot , nonRepository , path . join ( nonRepository , "missing" ) ] ) {
670+ assert . isEmpty ( ( yield * driver . getReviewDiffPreview ( input ( cwd ) ) ) . sources ) ;
671+ }
672+
673+ const brokenConfig = yield * makeTmpDir ( ) ;
674+ yield * initRepoWithCommit ( brokenConfig ) ;
675+ yield * writeTextFile ( brokenConfig , ".git/config" , "[broken" ) ;
676+ const error = yield * driver . getReviewDiffPreview ( input ( brokenConfig ) ) . pipe ( Effect . flip ) ;
677+ assert . equal ( error . operation , "GitVcsDriver.resolveRepositoryPaths.commonDir" ) ;
678+ } ) ,
679+ ) . pipe ( Effect . provide ( layerTest ) ) ,
680+ ) ;
681+
569682it . effect . skipIf ( HostProcess . Platform . defaultValue ( ) === "win32" ) (
570683 "preserves embedded newlines in repository paths after worktree creation" ,
571684 ( ) =>
@@ -2150,37 +2263,49 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
21502263 } ) ,
21512264 ) ;
21522265
2153- it . effect ( "loads repository-relative files from a nested project directory " , ( ) =>
2266+ it . effect ( "loads repository-relative files from nested directories and aliases " , ( ) =>
21542267 Effect . gen ( function * ( ) {
2155- const cwd = yield * makeTmpDir ( ) ;
2268+ const directory = yield * makeTmpDir ( ) ;
2269+ const path = yield * Path . Path ;
2270+ const fileSystem = yield * FileSystem . FileSystem ;
2271+ const platform = yield * HostProcess . Platform ;
2272+ const cwd = path . join ( directory , platform === "win32" ? "repository" : "repository\n " ) ;
2273+ yield * fileSystem . makeDirectory ( cwd ) ;
21562274 const { initialBranch } = yield * initRepoWithCommit ( cwd ) ;
21572275 yield * git ( cwd , [ "checkout" , "-b" , "feature/nested" ] ) ;
21582276 yield * writeTextFile ( cwd , "nested/tracked.txt" , "committed\n" ) ;
21592277 yield * git ( cwd , [ "add" , "." ] ) ;
21602278 yield * git ( cwd , [ "commit" , "-m" , "nested file" ] ) ;
21612279 yield * writeTextFile ( cwd , "nested/tracked.txt" , "changed\n" ) ;
21622280 yield * writeTextFile ( cwd , "untracked.txt" , "new\n" ) ;
2163- const path = yield * Path . Path ;
21642281 const driver = yield * GitVcsDriver . GitVcsDriver ;
21652282 const nestedCwd = path . join ( cwd , "nested" ) ;
2166- const preview = yield * driver . getReviewDiffPreview ( {
2167- cwd : nestedCwd ,
2168- baseRef : initialBranch ,
2169- } ) ;
2170- assert . equal (
2171- preview . sources . find ( ( source ) => source . kind === "working-tree" ) ! . files ! . length ,
2172- 2 ,
2173- ) ;
2174- for ( const source of preview . sources ) {
2175- for ( const file of source . files ?? [ ] ) {
2176- const scoped = yield * driver . getReviewDiffPreview ( {
2177- cwd : nestedCwd ,
2178- baseRef : initialBranch ,
2179- file : { path : file . path , previousPath : file . previousPath , sourceKind : source . kind } ,
2180- } ) ;
2181- const patch = scoped . sources . find ( ( item ) => item . kind === source . kind ) ! ;
2182- assert . deepStrictEqual ( patch . files , [ file ] ) ;
2183- assert . include ( patch . diff , `b/${ file . path } ` ) ;
2283+ const projectDirectories = [ nestedCwd ] ;
2284+ if ( symlinksSupported ) {
2285+ const alias = path . join ( directory , "alias" ) ;
2286+ yield * fileSystem . symlink ( nestedCwd , alias ) ;
2287+ projectDirectories . push ( alias ) ;
2288+ }
2289+ for ( const projectDirectory of projectDirectories ) {
2290+ const preview = yield * driver . getReviewDiffPreview ( {
2291+ cwd : projectDirectory ,
2292+ baseRef : initialBranch ,
2293+ } ) ;
2294+ assert . equal (
2295+ preview . sources . find ( ( source ) => source . kind === "working-tree" ) ! . files ! . length ,
2296+ 2 ,
2297+ ) ;
2298+ for ( const source of preview . sources ) {
2299+ for ( const file of source . files ?? [ ] ) {
2300+ const scoped = yield * driver . getReviewDiffPreview ( {
2301+ cwd : projectDirectory ,
2302+ baseRef : initialBranch ,
2303+ file : { path : file . path , previousPath : file . previousPath , sourceKind : source . kind } ,
2304+ } ) ;
2305+ const patch = scoped . sources . find ( ( item ) => item . kind === source . kind ) ! ;
2306+ assert . deepStrictEqual ( patch . files , [ file ] ) ;
2307+ assert . include ( patch . diff , `b/${ file . path } ` ) ;
2308+ }
21842309 }
21852310 }
21862311 } ) ,
0 commit comments