@@ -96,6 +96,22 @@ function createRepo(nestedName?: string) {
9696 return dir ;
9797}
9898
99+ function addTrackedUiConfig ( repoDir : string ) {
100+ const configDir = join ( repoDir , "ui" , "config" ) ;
101+ mkdirSync ( configDir , { recursive : true } ) ;
102+ writeFileSync ( join ( configDir , "control-ui-chunking.ts" ) , "export const chunking = true;\n" ) ;
103+ execFileSync ( "git" , [ "add" , "ui/config/control-ui-chunking.ts" ] , { cwd : repoDir } ) ;
104+ execFileSync ( "git" , [ "commit" , "-qm" , "add ui config" ] , { cwd : repoDir } ) ;
105+ }
106+
107+ function setSparseCheckout ( repoDir : string ) {
108+ execFileSync ( "git" , [ "sparse-checkout" , "init" , "--no-cone" ] , { cwd : repoDir } ) ;
109+ execFileSync ( "git" , [ "sparse-checkout" , "set" , "--no-cone" , "--stdin" ] , {
110+ cwd : repoDir ,
111+ input : "/*\n!/*/\n/base.txt\n" ,
112+ } ) ;
113+ }
114+
99115function bashSource ( repoDir : string , supervised = false ) {
100116 return [
101117 "set -euo pipefail" ,
@@ -2193,6 +2209,54 @@ describePosix("scripts/pr per-PR operation lock", () => {
21932209 ) . toBe ( "temp/pr-43" ) ;
21942210 } ) ;
21952211
2212+ it ( "materializes a new PR worktree inherited from a sparse checkout" , ( ) => {
2213+ const repoDir = createRepo ( ) ;
2214+ addTrackedUiConfig ( repoDir ) ;
2215+ execFileSync ( "git" , [ "remote" , "add" , "origin" , repoDir ] , { cwd : repoDir } ) ;
2216+ setSparseCheckout ( repoDir ) ;
2217+ const worktreeDir = join ( repoDir , ".worktrees" , "pr-44" ) ;
2218+
2219+ const result = runLockShell ( repoDir , [
2220+ "ensure_gh_api_auth() { return 0; }" ,
2221+ "enter_worktree 44" ,
2222+ ] ) ;
2223+
2224+ expect ( result . status , `${ result . stdout } \n${ result . stderr } ` ) . toBe ( 0 ) ;
2225+ expect ( existsSync ( join ( worktreeDir , "ui" , "config" , "control-ui-chunking.ts" ) ) ) . toBe ( true ) ;
2226+ expect (
2227+ execFileSync ( "git" , [ "config" , "--bool" , "core.sparseCheckout" ] , {
2228+ cwd : worktreeDir ,
2229+ encoding : "utf8" ,
2230+ } ) . trim ( ) ,
2231+ ) . toBe ( "false" ) ;
2232+ } ) ;
2233+
2234+ it ( "materializes an existing sparse PR worktree before reuse" , ( ) => {
2235+ const repoDir = createRepo ( ) ;
2236+ addTrackedUiConfig ( repoDir ) ;
2237+ execFileSync ( "git" , [ "remote" , "add" , "origin" , repoDir ] , { cwd : repoDir } ) ;
2238+ const worktreeDir = join ( repoDir , ".worktrees" , "pr-45" ) ;
2239+ execFileSync ( "git" , [ "worktree" , "add" , "-q" , "-b" , "temp/pr-45" , worktreeDir ] , {
2240+ cwd : repoDir ,
2241+ } ) ;
2242+ setSparseCheckout ( worktreeDir ) ;
2243+ expect ( existsSync ( join ( worktreeDir , "ui" , "config" , "control-ui-chunking.ts" ) ) ) . toBe ( false ) ;
2244+
2245+ const result = runLockShell ( repoDir , [
2246+ "ensure_gh_api_auth() { return 0; }" ,
2247+ "enter_worktree 45" ,
2248+ ] ) ;
2249+
2250+ expect ( result . status , `${ result . stdout } \n${ result . stderr } ` ) . toBe ( 0 ) ;
2251+ expect ( existsSync ( join ( worktreeDir , "ui" , "config" , "control-ui-chunking.ts" ) ) ) . toBe ( true ) ;
2252+ expect (
2253+ execFileSync ( "git" , [ "config" , "--bool" , "core.sparseCheckout" ] , {
2254+ cwd : worktreeDir ,
2255+ encoding : "utf8" ,
2256+ } ) . trim ( ) ,
2257+ ) . toBe ( "false" ) ;
2258+ } ) ;
2259+
21962260 it ( "refuses a symlink alias to another registered worktree" , ( ) => {
21972261 const repoDir = createRepo ( ) ;
21982262 const worktreesDir = join ( repoDir , ".worktrees" ) ;
0 commit comments