fix(walkthrough): use remote default branch

This commit is contained in:
RyderAsking
2026-08-04 16:48:24 +00:00
parent 746e0d4abd
commit b4ced01cc7
8 changed files with 121 additions and 10 deletions
@@ -0,0 +1,30 @@
import { describe, expect, test } from 'bun:test';
import { deriveBaseBranch, hasResolvableBaseBranch } from './baseBranch';
describe('deriveBaseBranch', () => {
test('prefers the remote default branch hint over conventional fallbacks', () => {
expect(deriveBaseBranch({
remoteNames: new Set(['origin']),
localBranches: ['next'],
rootBranchHint: 'origin/react',
})).toBe('react');
});
});
describe('hasResolvableBaseBranch', () => {
test('rejects the main fallback when it does not exist', () => {
expect(hasResolvableBaseBranch({
baseBranch: 'main',
localBranches: ['next', 'react'],
remoteBranches: ['origin/next', 'origin/react'],
})).toBe(false);
});
test('accepts a base branch available through a remote-tracking ref', () => {
expect(hasResolvableBaseBranch({
baseBranch: 'main',
localBranches: ['next'],
remoteBranches: ['origin/main', 'origin/next'],
})).toBe(true);
});
});
@@ -62,3 +62,18 @@ export const deriveBaseBranch = (options: {
if (localBranches.includes('develop')) return 'develop';
return 'main';
};
/**
* Whether a base branch can be resolved locally or through one of the active
* remote-tracking refs. Callers must not offer comparisons against the `main`
* fallback when that ref does not actually exist in the repository.
*/
export const hasResolvableBaseBranch = (options: {
baseBranch: string;
localBranches: readonly string[];
remoteBranches: readonly string[];
}): boolean => {
const { baseBranch, localBranches, remoteBranches } = options;
return localBranches.includes(baseBranch)
|| remoteBranches.some((branch) => branch.endsWith(`/${baseBranch}`));
};