@@ -109,18 +109,20 @@ const repositories: Record<string, VcsRepositoryIdentity> = {
109109} ;
110110
111111const makeHarness = Effect . fn ( "makeWorktreeToolkitHarness" ) ( function * (
112- options : { readonly headBranch ?: string | null } = { } ,
112+ options : { readonly headBranch ?: string | null ; readonly headExitCode ?: number } = { } ,
113113) {
114114 const commands = yield * Ref . make < ReadonlyArray < OrchestrationCommand > > ( [ ] ) ;
115115 const headBranch = options . headBranch === undefined ? "feature" : options . headBranch ;
116+ // `git symbolic-ref --quiet` exits 1 for a detached HEAD and 128 for other failures.
117+ const headExitCode = options . headExitCode ?? ( headBranch === null ? 1 : 0 ) ;
116118 const dispatch : OrchestrationEngineShape [ "dispatch" ] = ( command ) =>
117119 Ref . update ( commands , ( recorded ) => [ ...recorded , command ] ) . pipe ( Effect . as ( { sequence : 1 } ) ) ;
118120 const driver = {
119121 execute : ( ) =>
120122 Effect . succeed ( {
121- exitCode : headBranch === null ? 128 : 0 ,
122- stdout : headBranch === null ? "" : `${ headBranch } \n` ,
123- stderr : headBranch === null ? "fatal: ref HEAD is not a symbolic ref \n" : "" ,
123+ exitCode : headExitCode ,
124+ stdout : headExitCode === 0 ? `${ headBranch } \n` : "" ,
125+ stderr : headExitCode === 128 ? "fatal: not a git repository \n" : "" ,
124126 stdoutTruncated : false ,
125127 stderrTruncated : false ,
126128 } ) ,
@@ -226,6 +228,15 @@ describe("worktree toolkit handlers", () => {
226228 } ) ,
227229 ) ;
228230
231+ it . effect ( "fails without touching the thread when HEAD cannot be read" , ( ) =>
232+ Effect . gen ( function * ( ) {
233+ const harness = yield * makeHarness ( { headExitCode : 128 } ) ;
234+ const error = yield * harness . call ( { path : LINKED_WORKTREE } ) . pipe ( Effect . flip ) ;
235+ expect ( error ) . toMatchObject ( { _tag : "WorktreeHandoffFailedError" } ) ;
236+ expect ( yield * Ref . get ( harness . commands ) ) . toEqual ( [ ] ) ;
237+ } ) ,
238+ ) ;
239+
229240 it . effect . each ( [
230241 { path : "relative/worktree" , detail : "Pass the worktree's absolute path." } ,
231242 { path : "/workspace/missing" , detail : "does not exist or is not inside a git worktree" } ,
0 commit comments