@@ -514,6 +514,15 @@ function classifyGitFailure(stderr: string): GitCommandFailureReason | null {
514514 return null ;
515515}
516516
517+ // `--short` and `--abbrev-ref` print `heads/<name>` when a tag shares the branch's name, so
518+ // branch reads take the full ref and strip the prefix themselves.
519+ function branchNameFromHeadRef ( value : string ) : string | null {
520+ const ref = value . trim ( ) ;
521+ return ref . startsWith ( "refs/heads/" ) && ref . length > "refs/heads/" . length
522+ ? ref . slice ( "refs/heads/" . length )
523+ : null ;
524+ }
525+
517526function parseDefaultBranchFromRemoteHeadRef ( value : string , remoteName : string ) : string | null {
518527 const trimmed = value . trim ( ) ;
519528 const prefix = `refs/remotes/${ remoteName } /` ;
@@ -1412,7 +1421,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
14121421 executeGit (
14131422 "GitVcsDriver.resolveRepositoryPaths.currentBranch" ,
14141423 cwd ,
1415- [ "symbolic-ref" , "--quiet" , "--short" , " HEAD"] ,
1424+ [ "symbolic-ref" , "--quiet" , "HEAD" ] ,
14161425 {
14171426 timeoutMs : 5_000 ,
14181427 allowNonZeroExit : true ,
@@ -1443,11 +1452,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
14431452 Effect . map ( ( physicalCwd ) => path . relative ( worktreeRoot , physicalCwd ) === "" ) ,
14441453 Effect . orElseSucceed ( ( ) => undefined ) ,
14451454 ) ;
1446- const currentBranchOutput = currentBranchResult . stdout . trim ( ) ;
14471455 const currentBranch =
1448- currentBranchResult . exitCode === 0 && currentBranchOutput . length > 0
1449- ? currentBranchOutput
1450- : null ;
1456+ currentBranchResult . exitCode === 0 ? branchNameFromHeadRef ( currentBranchResult . stdout ) : null ;
14511457
14521458 return {
14531459 gitCommonDir,
@@ -1938,7 +1944,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
19381944 const branchResult = yield * executeGitWithStableDiagnostics (
19391945 "GitVcsDriver.statusDetailsRemote.branch" ,
19401946 cwd ,
1941- [ "rev-parse" , "--abbrev-ref " , "HEAD" ] ,
1947+ [ "rev-parse" , "--symbolic-full-name " , "HEAD" ] ,
19421948 { allowNonZeroExit : true } ,
19431949 ) . pipe (
19441950 Effect . catchTags ( {
@@ -1960,7 +1966,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
19601966 ...gitCommandContext ( {
19611967 operation : "GitVcsDriver.statusDetailsRemote.branch" ,
19621968 cwd,
1963- args : [ "rev-parse" , "--abbrev-ref " , "HEAD" ] ,
1969+ args : [ "rev-parse" , "--symbolic-full-name " , "HEAD" ] ,
19641970 } ) ,
19651971 detail : "Git branch lookup failed." ,
19661972 exitCode : branchResult . exitCode ,
@@ -1972,12 +1978,11 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
19721978 const branchValue = yield * runGitStdout (
19731979 "GitVcsDriver.statusDetailsRemote.unbornBranch" ,
19741980 cwd ,
1975- [ "symbolic-ref" , "--quiet" , "--short" , " HEAD"] ,
1981+ [ "symbolic-ref" , "--quiet" , "HEAD" ] ,
19761982 ) ;
1977- branch = branchValue . trim ( ) || null ;
1983+ branch = branchNameFromHeadRef ( branchValue ) ;
19781984 } else {
1979- const branchValue = branchResult . stdout . trim ( ) ;
1980- branch = branchValue . length > 0 && branchValue !== "HEAD" ? branchValue : null ;
1985+ branch = branchNameFromHeadRef ( branchResult . stdout ) ;
19811986 }
19821987 const currentUpstreamRef = yield * readCurrentUpstreamRef ( cwd ) ;
19831988 let upstreamRef =
@@ -2781,9 +2786,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
27812786 runGitStdout (
27822787 "GitVcsDriver.pullCurrentBranch.currentBranch" ,
27832788 cwd ,
2784- [ "symbolic-ref" , "--quiet" , "--short" , " HEAD"] ,
2789+ [ "symbolic-ref" , "--quiet" , "HEAD" ] ,
27852790 true ,
2786- ) . pipe ( Effect . map ( ( stdout ) => stdout . trim ( ) ) ) ,
2791+ ) . pipe ( Effect . map ( branchNameFromHeadRef ) ) ,
27872792 runGitStdout ( "GitVcsDriver.pullCurrentBranch.currentSha" , cwd , [ "rev-parse" , "HEAD" ] ) . pipe (
27882793 Effect . map ( ( stdout ) => stdout . trim ( ) ) ,
27892794 ) ,
0 commit comments