Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Commit

Permalink
fix: run git init and git version in project directory
Browse files Browse the repository at this point in the history
  • Loading branch information
phuctm97 committed Jul 3, 2022
1 parent 69f1847 commit 71955d9
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/utils/try-init-git.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import path from "path";
import fs from "fs/promises";

import { exec } from "./async-exec";

async function isInGitRepository(projectDirectory: string): Promise<boolean> {
Expand All @@ -18,7 +15,9 @@ async function isInMercurialRepository(
projectDirectory: string
): Promise<boolean> {
try {
await exec("hg --cwd . root", { cwd: projectDirectory });
await exec("hg --cwd . root", {
cwd: projectDirectory,
});
return true;
} catch {
return false;
Expand All @@ -27,14 +26,18 @@ async function isInMercurialRepository(

export async function tryGitInit(projectDirectory: string): Promise<boolean> {
try {
await exec("git --version", { cwd: projectDirectory });
await exec("git --version", {
cwd: projectDirectory,
});
if (
(await isInGitRepository(projectDirectory)) ||
(await isInMercurialRepository(projectDirectory))
) {
return false;
}
await exec("git init");
await exec("git init", {
cwd: projectDirectory,
});
return true;
} catch {
return false;
Expand Down

0 comments on commit 71955d9

Please sign in to comment.