* chore: add .worktrees/ to gitignore for worktree workflow * fix: resolve remote-tracking base ref in getLog for PR description generation getLog was calling git log <base>..<head> with a bare branch name that often doesn't exist locally (e.g. main when only origin/main is present), causing a fatal 'unknown revision' error and HTTP 500. Apply the same origin/<base> resolution already used in getRangeDiff and getRangeFiles: check refs/remotes/origin/<base> first and prefer that ref if it exists. Also fix getGitLog in gitApiHttp.ts to read the JSON error body on failure instead of falling back to response.statusText, so the actual git error message surfaces in the toast instead of 'Internal Server Error'. * fix(git): use local-first ref resolution in getLog and port to VS Code - Replace unconditional origin/<from> preference in getLog() with a local-first fallback: prefer the local ref, only use origin/<from> when the local ref cannot be resolved, and pass through unchanged when neither resolves so git surfaces a meaningful error. - Extract the logic into an exported resolveBaseRefForLog(from, checkRef) helper so it is unit-testable without a real git repo. - Add service.test.js with 6 cases covering local-wins, origin-fallback, neither-exists passthrough, and falsy/empty inputs. - Port the same local-first resolution to packages/vscode/src/gitService.ts getGitLog() to close the cross-runtime parity gap; also handles from-only ranges as from..HEAD, matching the web service contract. * fix(vscode): add missing to-only range branch in getGitLog When only 'to' is supplied (no 'from'), the web service appends it as a positional git-log argument. The VS Code port was missing this branch and silently returned unbounded history instead. Adds the else-if to restore full cross-runtime parity. * fix(vscode): surface git log errors --------- Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
40 lines
1.8 KiB
JavaScript
40 lines
1.8 KiB
JavaScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import { resolveBaseRefForLog } from './service.js';
|
|
|
|
describe('resolveBaseRefForLog', () => {
|
|
it('returns the local ref unchanged when it exists, even if origin also exists', async () => {
|
|
// Both local 'main' and 'refs/remotes/origin/main' are present.
|
|
// The local ref takes precedence — callers that ask for 'main' get 'main'.
|
|
const checkRef = async (ref) => ref === 'main' || ref === 'refs/remotes/origin/main';
|
|
expect(await resolveBaseRefForLog('main', checkRef)).toBe('main');
|
|
});
|
|
|
|
it('falls back to origin/<from> when local ref cannot be resolved but origin can', async () => {
|
|
// Local 'main' is absent (e.g. user never checked it out), but origin/main exists.
|
|
const checkRef = async (ref) => ref === 'refs/remotes/origin/main';
|
|
expect(await resolveBaseRefForLog('main', checkRef)).toBe('origin/main');
|
|
});
|
|
|
|
it('returns the original ref when neither local nor origin ref can be resolved', async () => {
|
|
// Neither ref exists; return as-is so git surfaces a meaningful error.
|
|
const checkRef = async () => false;
|
|
expect(await resolveBaseRefForLog('nonexistent-branch', checkRef)).toBe('nonexistent-branch');
|
|
});
|
|
|
|
it('returns undefined when from is undefined', async () => {
|
|
const checkRef = async () => true;
|
|
expect(await resolveBaseRefForLog(undefined, checkRef)).toBeUndefined();
|
|
});
|
|
|
|
it('returns undefined when from is an empty string', async () => {
|
|
const checkRef = async () => true;
|
|
expect(await resolveBaseRefForLog('', checkRef)).toBeUndefined();
|
|
});
|
|
|
|
it('returns undefined when from is a whitespace-only string', async () => {
|
|
const checkRef = async () => true;
|
|
expect(await resolveBaseRefForLog(' ', checkRef)).toBeUndefined();
|
|
});
|
|
});
|