@@ -519,6 +519,15 @@ function classifyGitFailure(stderr: string): GitCommandFailureReason | null {
519519 return null ;
520520}
521521
522+ // `--short` and `--abbrev-ref` print `heads/<name>` when a tag shares the branch's name, so
523+ // branch reads take the full ref and strip the prefix themselves.
524+ function branchNameFromHeadRef ( value : string ) : string | null {
525+ const ref = value . trim ( ) ;
526+ return ref . startsWith ( "refs/heads/" ) && ref . length > "refs/heads/" . length
527+ ? ref . slice ( "refs/heads/" . length )
528+ : null ;
529+ }
530+
522531function parseDefaultBranchFromRemoteHeadRef ( value : string , remoteName : string ) : string | null {
523532 const trimmed = value . trim ( ) ;
524533 const prefix = `refs/remotes/${ remoteName } /` ;
@@ -1414,7 +1423,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
14141423 executeGit (
14151424 "GitVcsDriver.resolveRepositoryPaths.currentBranch" ,
14161425 cwd ,
1417- [ "symbolic-ref" , "--quiet" , "--short" , " HEAD"] ,
1426+ [ "symbolic-ref" , "--quiet" , "HEAD" ] ,
14181427 {
14191428 timeoutMs : 5_000 ,
14201429 allowNonZeroExit : true ,
@@ -1445,11 +1454,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
14451454 Effect . map ( ( physicalCwd ) => path . relative ( worktreeRoot , physicalCwd ) === "" ) ,
14461455 Effect . orElseSucceed ( ( ) => undefined ) ,
14471456 ) ;
1448- const currentBranchOutput = currentBranchResult . stdout . trim ( ) ;
14491457 const currentBranch =
1450- currentBranchResult . exitCode === 0 && currentBranchOutput . length > 0
1451- ? currentBranchOutput
1452- : null ;
1458+ currentBranchResult . exitCode === 0 ? branchNameFromHeadRef ( currentBranchResult . stdout ) : null ;
14531459
14541460 return {
14551461 gitCommonDir,
@@ -1931,7 +1937,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
19311937 const branchResult = yield * executeGitWithStableDiagnostics (
19321938 "GitVcsDriver.statusDetailsRemote.branch" ,
19331939 cwd ,
1934- [ "rev-parse" , "--abbrev-ref " , "HEAD" ] ,
1940+ [ "rev-parse" , "--symbolic-full-name " , "HEAD" ] ,
19351941 { allowNonZeroExit : true } ,
19361942 ) . pipe (
19371943 Effect . catchTags ( {
@@ -1953,7 +1959,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
19531959 ...gitCommandContext ( {
19541960 operation : "GitVcsDriver.statusDetailsRemote.branch" ,
19551961 cwd,
1956- args : [ "rev-parse" , "--abbrev-ref " , "HEAD" ] ,
1962+ args : [ "rev-parse" , "--symbolic-full-name " , "HEAD" ] ,
19571963 } ) ,
19581964 detail : "Git branch lookup failed." ,
19591965 exitCode : branchResult . exitCode ,
@@ -1965,12 +1971,11 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
19651971 const branchValue = yield * runGitStdout (
19661972 "GitVcsDriver.statusDetailsRemote.unbornBranch" ,
19671973 cwd ,
1968- [ "symbolic-ref" , "--quiet" , "--short" , " HEAD"] ,
1974+ [ "symbolic-ref" , "--quiet" , "HEAD" ] ,
19691975 ) ;
1970- branch = branchValue . trim ( ) || null ;
1976+ branch = branchNameFromHeadRef ( branchValue ) ;
19711977 } else {
1972- const branchValue = branchResult . stdout . trim ( ) ;
1973- branch = branchValue . length > 0 && branchValue !== "HEAD" ? branchValue : null ;
1978+ branch = branchNameFromHeadRef ( branchResult . stdout ) ;
19741979 }
19751980 const currentUpstreamRef = yield * readCurrentUpstreamRef ( cwd ) ;
19761981 let upstreamRef =
@@ -2760,9 +2765,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
27602765 runGitStdout (
27612766 "GitVcsDriver.pullCurrentBranch.currentBranch" ,
27622767 cwd ,
2763- [ "symbolic-ref" , "--quiet" , "--short" , " HEAD"] ,
2768+ [ "symbolic-ref" , "--quiet" , "HEAD" ] ,
27642769 true ,
2765- ) . pipe ( Effect . map ( ( stdout ) => stdout . trim ( ) ) ) ,
2770+ ) . pipe ( Effect . map ( branchNameFromHeadRef ) ) ,
27662771 runGitStdout ( "GitVcsDriver.pullCurrentBranch.currentSha" , cwd , [ "rev-parse" , "HEAD" ] ) . pipe (
27672772 Effect . map ( ( stdout ) => stdout . trim ( ) ) ,
27682773 ) ,
0 commit comments