diff --git a/src/git-util.ts b/src/git-util.ts index 77b10e8..8587817 100644 --- a/src/git-util.ts +++ b/src/git-util.ts @@ -1,27 +1,32 @@ import { debug, info } from "@actions/core"; -import { readdir } from "fs/promises"; +import { readdir, access } from "fs/promises"; import * as path from "path"; import simpleGit from "simple-git"; const git = simpleGit(); -async function listGitDirectory() { - const dir = ".git"; - const files = await readdir(dir); - return files.map((file) => path.join(dir, file)); +/** + * Fetches all commits from the remote repository + */ +export async function fullFetch(): Promise { + access(path.join(".git", "shallow")) + .then(async () => { + await git.fetch(["--unshallow"]); + }) + .catch(async () => { + await git.fetch([]); + }); } export async function fetchRemoteBranches() { - const files = await listGitDirectory(); - info(files.join("\n")); - await git.fetch(["--unshallow"]); + await fullFetch(); const branches = await git.branch(["-r"]); return branches.all.map((branch) => branch.replace("origin/", "")); } export async function hasCommitsBetween( srcBranch: string, - targetBranch: string, + targetBranch: string ) { const commits = await git.log({ from: srcBranch, @@ -30,8 +35,8 @@ export async function hasCommitsBetween( }); debug( `Commits between ${srcBranch} and ${targetBranch}: ${JSON.stringify( - commits, - )}`, + commits + )}` ); return commits.total > 0; }