@@ -43,10 +43,9 @@ const getBranchRemote = (branch: BranchListing) => {
4343 return branch . remotes [ 0 ] ?? null ;
4444} ;
4545
46- const getBranchRef = ( branch : BranchListing ) : string | null => {
47- if ( branch . hasLocal ) return `refs/heads/${ branch . name } ` ;
48- const remote = branch . remotes [ 0 ] ;
49- if ( remote === undefined ) return null ;
46+ const getBranchRef = ( branch : BranchListing ) : string => {
47+ const remote = getBranchRemote ( branch ) ;
48+ if ( remote === null ) return `refs/heads/${ branch . name } ` ;
5049 return `refs/remotes/${ remote } /${ branch . name } ` ;
5150} ;
5251
@@ -81,20 +80,17 @@ const BranchMenuPopup: FC<{
8180 const { Popup, Item } = parts ;
8281 const applyBranch = useMutation ( applyBranchMutationOptions ) ;
8382 const unapplyStack = useMutation ( unapplyStackMutationOptions ) ;
84- const ref = getBranchRef ( branch ) ;
8583 const stackId = branch . stack ?. id ;
8684
8785 return (
8886 < Popup className = { classes ( uiStyles . popup , uiStyles . menuPopup ) } >
8987 { ! branch . stack ?. inWorkspace ? (
9088 < Item
9189 className = { uiStyles . menuItem }
92- disabled = { ref === null }
9390 onClick = { ( ) => {
94- if ( ref === null ) return ;
9591 applyBranch . mutate ( {
9692 projectId,
97- existingBranch : ref ,
93+ existingBranch : getBranchRef ( branch ) ,
9894 } ) ;
9995 } }
10096 >
@@ -122,7 +118,6 @@ const BranchApplyToggle: FC<{
122118} > = ( { branch, projectId } ) => {
123119 const applyBranch = useMutation ( applyBranchMutationOptions ) ;
124120 const unapplyStack = useMutation ( unapplyStackMutationOptions ) ;
125- const ref = getBranchRef ( branch ) ;
126121 const stackId = branch . stack ?. id ;
127122 const isApplied = branch . stack ?. inWorkspace ?? false ;
128123
@@ -144,13 +139,11 @@ const BranchApplyToggle: FC<{
144139 < button
145140 type = "button"
146141 className = { classes ( sharedStyles . itemAction , styles . branchApplyToggle ) }
147- disabled = { ref === null }
148142 aria-label = { `Apply branch ${ branch . name } ` }
149143 onClick = { ( ) => {
150- if ( ref === null ) return ;
151144 applyBranch . mutate ( {
152145 projectId,
153- existingBranch : ref ,
146+ existingBranch : getBranchRef ( branch ) ,
154147 } ) ;
155148 } }
156149 >
@@ -452,22 +445,16 @@ const Preview: FC<{
452445 projectId : string ;
453446 selection : Selection ;
454447 remote : string | null ;
455- branchRef : string | null ;
456- } > = ( { projectId, selection, remote, branchRef } ) =>
448+ } > = ( { projectId, selection, remote } ) =>
457449 Match . value ( selection ) . pipe (
458- Match . tag ( "Branch" , ( { branchName } ) =>
459- branchRef !== null ? (
460- < ShowBranch
461- projectId = { projectId }
462- branchRef = { branchRef }
463- branchName = { branchName }
464- remote = { remote }
465- renderHunk = { ( change , hunk ) => < Hunk change = { change } hunk = { hunk } /> }
466- />
467- ) : (
468- < div > No branch diff available.</ div >
469- ) ,
470- ) ,
450+ Match . tag ( "Branch" , ( { branchName } ) => (
451+ < ShowBranch
452+ projectId = { projectId }
453+ branchName = { branchName }
454+ remote = { remote }
455+ renderHunk = { ( change , hunk ) => < Hunk change = { change } hunk = { hunk } /> }
456+ />
457+ ) ) ,
471458 Match . tag ( "Commit" , ( { branchName, commitId, mode } ) =>
472459 mode . _tag === "Details" && mode . path !== undefined ? (
473460 < ShowBranchCommitFile
@@ -520,7 +507,6 @@ const ProjectBranchesPage: FC = () => {
520507 < Preview
521508 projectId = { projectId }
522509 selection = { selection }
523- branchRef = { getBranchRef ( selectedBranch ) }
524510 remote = { getBranchRemote ( selectedBranch ) }
525511 />
526512 </ Suspense >
0 commit comments