@@ -10,6 +10,7 @@ import {
1010} from "effect"
1111import type { PlatformError } from "effect/PlatformError"
1212import { Atom , AtomRegistry } from "effect/unstable/reactivity"
13+ import type { ChildProcessSpawner } from "effect/unstable/process"
1314import {
1415 HookCommandFailedError ,
1516 Hooks ,
@@ -21,10 +22,11 @@ import { CurrentProjectId } from "./Settings.ts"
2122import { projectById } from "./Projects.ts"
2223import type { Worktree } from "./Worktree.ts"
2324import { CurrentWorkerState } from "./Workers.ts"
24- import { parseBranch } from "./shared/git.ts"
2525import {
2626 getCurrentRepository ,
27+ resolveTargetBranch ,
2728 targetBranchToJjBookmark ,
29+ targetBranchToJjRevision ,
2830 type VcsKind ,
2931} from "./shared/vcs.ts"
3032
@@ -52,7 +54,10 @@ export class GitFlow extends ServiceMap.Service<
5254 } ) => Effect . Effect <
5355 void ,
5456 IssueSourceError | PlatformError | GitFlowError ,
55- Prd | IssueSource | CurrentProjectId
57+ | Prd
58+ | IssueSource
59+ | CurrentProjectId
60+ | ChildProcessSpawner . ChildProcessSpawner
5661 >
5762 readonly autoMerge : ( options : {
5863 readonly targetBranch : string | undefined
@@ -320,10 +325,15 @@ But you **do not** need to push your changes or switch workspaces, and you shoul
320325 }
321326 const prd = yield * Prd
322327
323- const parsed = parseBranch ( targetBranch )
328+ const parsed = yield * resolveTargetBranch ( {
329+ repository : worktree . repository ,
330+ targetBranch,
331+ } )
324332
325333 if ( worktree . repository . kind === "git" ) {
326- yield * worktree . exec `git fetch ${ parsed . remote } `
334+ if ( Option . isSome ( parsed . remote ) ) {
335+ yield * worktree . exec `git fetch ${ parsed . remote . value } `
336+ }
327337 yield * worktree . exec `git restore --worktree .`
328338
329339 const rebaseResult =
@@ -335,25 +345,29 @@ But you **do not** need to push your changes or switch workspaces, and you shoul
335345 } )
336346 }
337347
338- const pushResult =
339- yield * worktree . exec `git push ${ parsed . remote } ${ `HEAD:${ parsed . branch } ` } `
340- if ( pushResult !== 0 ) {
341- yield * prd . flagUnmergable ( { issueId } )
342- return yield * new GitFlowError ( {
343- message : `Failed to push changes to ${ parsed . branchWithRemote } . Aborting task.` ,
344- } )
348+ if ( Option . isSome ( parsed . remote ) ) {
349+ const pushResult =
350+ yield * worktree . exec `git push ${ parsed . remote . value } ${ `HEAD:${ parsed . branch } ` } `
351+ if ( pushResult !== 0 ) {
352+ yield * prd . flagUnmergable ( { issueId } )
353+ return yield * new GitFlowError ( {
354+ message : `Failed to push changes to ${ parsed . branchWithRemote } . Aborting task.` ,
355+ } )
356+ }
345357 }
346358 return
347359 }
348360
349- yield * worktree . exec `jj git fetch --remote ${ parsed . remote } --branch ${ parsed . branch } `
350- yield * worktree . exec `jj bookmark track ${ parsed . branch } --remote ${ parsed . remote } `
361+ if ( Option . isSome ( parsed . remote ) ) {
362+ yield * worktree . exec `jj git fetch --remote ${ parsed . remote . value } --branch ${ parsed . branch } `
363+ yield * worktree . exec `jj bookmark track ${ parsed . branch } --remote ${ parsed . remote . value } `
364+ }
351365 const rebaseResult =
352- yield * worktree . exec `jj rebase --branch ${ "@" } --onto ${ targetBranchToJjBookmark ( targetBranch ) } `
366+ yield * worktree . exec `jj rebase --branch ${ "@" } --onto ${ targetBranchToJjBookmark ( parsed ) } `
353367 if ( rebaseResult !== 0 ) {
354368 yield * prd . flagUnmergable ( { issueId } )
355369 return yield * new GitFlowError ( {
356- message : `Failed to rebase onto ${ targetBranchToJjBookmark ( targetBranch ) } . Aborting task.` ,
370+ message : `Failed to rebase onto ${ targetBranchToJjBookmark ( parsed ) } . Aborting task.` ,
357371 } )
358372 }
359373 const setBookmarkResult =
@@ -365,13 +379,15 @@ But you **do not** need to push your changes or switch workspaces, and you shoul
365379 } )
366380 }
367381
368- const pushResult =
369- yield * worktree . exec `jj git push --remote ${ parsed . remote } --bookmark ${ parsed . branch } `
370- if ( pushResult !== 0 ) {
371- yield * prd . flagUnmergable ( { issueId } )
372- return yield * new GitFlowError ( {
373- message : `Failed to push jj bookmark ${ parsed . branch } @${ parsed . remote } . Aborting task.` ,
374- } )
382+ if ( Option . isSome ( parsed . remote ) ) {
383+ const pushResult =
384+ yield * worktree . exec `jj git push --remote ${ parsed . remote . value } --bookmark ${ parsed . branch } `
385+ if ( pushResult !== 0 ) {
386+ yield * prd . flagUnmergable ( { issueId } )
387+ return yield * new GitFlowError ( {
388+ message : `Failed to push jj bookmark ${ targetBranchToJjRevision ( parsed ) } . Aborting task.` ,
389+ } )
390+ }
375391 }
376392 } ) ,
377393 autoMerge : Effect . fnUntraced ( function * ( options ) {
0 commit comments