Skip to content

Commit 3b47f0b

Browse files
Fix resolveCurrentUpstream to handle slashed remote names
Use 'git config branch.<branch>.remote' to resolve the remote name instead of splitting the upstream ref on the first '/'. This correctly handles remotes with slashes in their names (e.g., 'my-org/upstream') where the old heuristic would parse 'my-org/upstream/feature' as remoteName='my-org' and upstreamBranch='upstream/feature'. Co-authored-by: Julius Marminge <[email protected]>
1 parent 99483cf commit 3b47f0b

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

apps/server/src/git/Layers/GitCore.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,24 @@ const makeGitCore = Effect.gen(function* () {
334334
return null;
335335
}
336336

337-
const separatorIndex = upstreamRef.indexOf("/");
338-
if (separatorIndex <= 0) {
337+
const currentBranch = yield* runGitStdout(
338+
"GitCore.resolveCurrentUpstream.branch",
339+
cwd,
340+
["rev-parse", "--abbrev-ref", "HEAD"],
341+
true,
342+
).pipe(Effect.map((stdout) => stdout.trim()));
343+
344+
const remoteName = yield* readConfigValue(cwd, `branch.${currentBranch}.remote`);
345+
if (!remoteName) {
346+
return null;
347+
}
348+
349+
const prefix = `${remoteName}/`;
350+
if (!upstreamRef.startsWith(prefix)) {
339351
return null;
340352
}
341-
const remoteName = upstreamRef.slice(0, separatorIndex);
342-
const upstreamBranch = upstreamRef.slice(separatorIndex + 1);
343-
if (remoteName.length === 0 || upstreamBranch.length === 0) {
353+
const upstreamBranch = upstreamRef.slice(prefix.length);
354+
if (upstreamBranch.length === 0) {
344355
return null;
345356
}
346357

0 commit comments

Comments
 (0)