Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
bonyuta0204 committed Nov 30, 2023
1 parent f132577 commit 464a65c
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/git-util.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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,
Expand All @@ -30,8 +35,8 @@ export async function hasCommitsBetween(
});
debug(
`Commits between ${srcBranch} and ${targetBranch}: ${JSON.stringify(
commits,
)}`,
commits
)}`
);
return commits.total > 0;
}

0 comments on commit 464a65c

Please sign in to comment.