Skip to content

Commit

Permalink
Fix get first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-centore committed May 11, 2024
1 parent de4d9c4 commit f83aeba
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/gitlib/git-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ const getIsMainBranch = async ({
return true;
};

const getFirstCommit = async ({ dir }: { dir: string }) => {
const execPromise = util.promisify(exec);
const { stdout, stderr } = await execPromise(
'git rev-list --max-parents=0 HEAD',
{
cwd: dir,
},
);
return stdout.trim();
};

const extractGitTree = async (): Promise<TreeData | null> => {
const dir = await getCwd();

Expand Down Expand Up @@ -228,8 +239,9 @@ const extractGitTree = async (): Promise<TreeData | null> => {
for (const ref of refs) {
// const isMainBranch = 'branch' in ref && ref.branch === mainBranchName;

// NOTE: git.firstCommit() seems to not always work
// eslint-disable-next-line no-await-in-loop
const firstCommit = await git.firstCommit();
const firstCommit = await getFirstCommit({ dir });
const branchCommits = await git.log({
to: 'branch' in ref ? ref.branch : ref.oid,
from: firstCommit,
Expand Down

0 comments on commit f83aeba

Please sign in to comment.