v3.0.0
What's Changed
- feat: new API for ergonomic worktree creation. by @aslushnikov in #22
Migration notes
v3.0.0
GitWorktree.create() and GitWorktree.headCommitId() → GitWorktree.initialize()
Both removed methods could throw. The replacement GitWorktree.initialize() returns a
discriminated union that forces the caller to handle failure explicitly, and it also
resolves the HEAD commit in the same call.
export type GitWorktreeInitResult =
| { ok: true; worktree: GitWorktree; commitId: FlakinessReport.CommitId }
| { ok: false; error: string };Rewrite the try/catch pattern that wrapped GitWorktree.create() +
worktree.headCommitId() into an ok check.
Before
let worktree: GitWorktree;
let commitId: FK.CommitId;
try {
worktree = GitWorktree.create(rootDir);
commitId = worktree.headCommitId();
} catch {
console.warn('Failed to fetch commit info - is this a git repo?');
console.error('Report is NOT generated.');
return;
}After
const result = GitWorktree.initialize(rootDir);
if (!result.ok) {
console.warn(`Failed to fetch commit info - is this a git repo? (${result.error})`);
console.error('Report is NOT generated.');
return;
}
const { worktree, commitId } = result;Notes:
GitWorktree.initialize()never throws — do not wrap it intry/catch.- After the
!result.okearly return, TypeScript narrowsresult.worktreeand
result.commitIdto their non-undefinedtypes. result.erroris a human-readable string describing which git command failed; log
it instead of a generic message if you want better diagnostics.
Full Changelog: v2.7.0...v3.0.0