shumadrid_obsidian-git-chan.../src/core/gitOperations/isAncestor.ts
2025-04-08 03:39:44 +02:00

30 lines
516 B
TypeScript

import type { SimpleGit } from 'simple-git';
/**
* Doesn't work because of the way SimpleGit instance is set up in Git plugin.
*/
export async function isAncestorOf({
newCommit,
oldCommit,
git
}: {
newCommit: string;
oldCommit: string;
git: SimpleGit;
}): Promise<boolean> {
if (oldCommit === newCommit) {
return true;
}
const result = await git.raw([
'merge-base',
'--is-ancestor',
oldCommit,
newCommit
]);
if (result === '1') {
return true;
}
return false;
}