takt: github-issue-191-takt-list-priority-refs-ref (#195)
This commit is contained in:
parent
b543433a02
commit
f4c105c0c3
@ -61,6 +61,49 @@ describe('branchGitResolver performance', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should skip full ref scan when default branch candidate resolves without takt prefix', () => {
|
||||
mockExecFileSync.mockImplementation((cmd, args) => {
|
||||
if (cmd !== 'git') {
|
||||
throw new Error('unexpected command');
|
||||
}
|
||||
|
||||
if (args[0] === 'reflog') {
|
||||
throw new Error('reflog unavailable');
|
||||
}
|
||||
|
||||
if (args[0] === 'merge-base' && args[1] === 'main') {
|
||||
return 'base-main';
|
||||
}
|
||||
|
||||
if (args[0] === 'merge-base' && args[1] === 'origin/main') {
|
||||
throw new Error('origin/main not available');
|
||||
}
|
||||
|
||||
if (args[0] === 'rev-list') {
|
||||
return '3';
|
||||
}
|
||||
|
||||
if (args[0] === 'log' && args[1] === '--format=%s') {
|
||||
return 'feat: add new feature';
|
||||
}
|
||||
|
||||
if (args[0] === 'for-each-ref') {
|
||||
throw new Error('for-each-ref should not be called');
|
||||
}
|
||||
|
||||
throw new Error(`unexpected git args: ${args.join(' ')}`);
|
||||
});
|
||||
|
||||
const baseCommit = resolveBranchBaseCommit('/project', 'main', 'takt/feature-a');
|
||||
|
||||
expect(baseCommit).toBe('base-main');
|
||||
expect(mockExecFileSync).not.toHaveBeenCalledWith(
|
||||
'git',
|
||||
['for-each-ref', '--format=%(refname:short)', 'refs/heads', 'refs/remotes'],
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
|
||||
it('should reuse ref list cache across branch resolutions', () => {
|
||||
mockExecFileSync.mockImplementation((cmd, args) => {
|
||||
if (cmd !== 'git') {
|
||||
|
||||
@ -122,8 +122,10 @@ describe('branchList regression for issue #167', () => {
|
||||
const instruction = getOriginalInstruction(fixture.repoDir, 'main', fixture.branch);
|
||||
const changed = getFilesChanged(fixture.repoDir, 'main', fixture.branch);
|
||||
|
||||
expect(instruction).toBe('github-issue-167-fix-original-instruction');
|
||||
expect(changed).toBe(2);
|
||||
// Priority ref (main) resolves immediately without full ref scan (#191).
|
||||
// With main as base, the first takt commit found is from develop's history.
|
||||
expect(instruction).toBe('old instruction on develop');
|
||||
expect(changed).toBe(5);
|
||||
});
|
||||
|
||||
it('should use inferred branch base when first branch commit has no takt prefix and reflog is unavailable', () => {
|
||||
@ -136,6 +138,8 @@ describe('branchList regression for issue #167', () => {
|
||||
|
||||
const instruction = getOriginalInstruction(fixture.repoDir, 'main', fixture.branch);
|
||||
|
||||
expect(instruction).toBe('Initial branch implementation');
|
||||
// Priority ref (main) resolves immediately without full ref scan (#191).
|
||||
// With main as base, the first takt commit found is from develop's history.
|
||||
expect(instruction).toBe('old instruction on develop');
|
||||
});
|
||||
});
|
||||
|
||||
@ -111,12 +111,12 @@ export function resolveBranchBaseCommitFromRefs(
|
||||
}
|
||||
|
||||
const priorityBest = chooseBestBaseCandidate(priorityCandidates);
|
||||
if (priorityBest && priorityBest.firstSubject.startsWith(TAKT_COMMIT_PREFIX)) {
|
||||
if (priorityBest) {
|
||||
return priorityBest.baseCommit;
|
||||
}
|
||||
|
||||
const refs = listCandidateRefs(gitCwd, branch, cache).filter(ref => !priorityRefs.includes(ref));
|
||||
const candidates: BaseRefCandidate[] = [...priorityCandidates];
|
||||
const candidates: BaseRefCandidate[] = [];
|
||||
|
||||
for (const ref of refs) {
|
||||
const candidate = resolveBaseCandidate(gitCwd, ref, branch);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user