From 7c65d0e30b93ed24a494852612c5eedb1eaa5211 Mon Sep 17 00:00:00 2001 From: Basix Date: Fri, 27 Sep 2024 04:58:51 +0900 Subject: [PATCH] fix(plugin-init): check git repository using git cli --- .yarn/versions/52500532.yml | 23 +++++++++++++++++++ packages/plugin-init/sources/commands/init.ts | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 .yarn/versions/52500532.yml diff --git a/.yarn/versions/52500532.yml b/.yarn/versions/52500532.yml new file mode 100644 index 000000000000..df8410021c37 --- /dev/null +++ b/.yarn/versions/52500532.yml @@ -0,0 +1,23 @@ +releases: + "@yarnpkg/cli": patch + "@yarnpkg/plugin-init": patch + +declined: + - "@yarnpkg/plugin-compat" + - "@yarnpkg/plugin-constraints" + - "@yarnpkg/plugin-dlx" + - "@yarnpkg/plugin-essentials" + - "@yarnpkg/plugin-interactive-tools" + - "@yarnpkg/plugin-nm" + - "@yarnpkg/plugin-npm-cli" + - "@yarnpkg/plugin-pack" + - "@yarnpkg/plugin-patch" + - "@yarnpkg/plugin-pnp" + - "@yarnpkg/plugin-pnpm" + - "@yarnpkg/plugin-stage" + - "@yarnpkg/plugin-typescript" + - "@yarnpkg/plugin-version" + - "@yarnpkg/plugin-workspace-tools" + - "@yarnpkg/builder" + - "@yarnpkg/core" + - "@yarnpkg/doctor" diff --git a/packages/plugin-init/sources/commands/init.ts b/packages/plugin-init/sources/commands/init.ts index a8fe7e7b8308..5172b378db58 100644 --- a/packages/plugin-init/sources/commands/init.ts +++ b/packages/plugin-init/sources/commands/init.ts @@ -248,7 +248,8 @@ export default class InitCommand extends BaseCommand { quiet: true, }); - if (!xfs.existsSync(ppath.join(this.context.cwd, `.git`))) { + const isGitRepo = (await execUtils.execvp(`git`, [`rev-parse`, `--is-inside-work-tree`], {cwd: this.context.cwd})).code === 0; + if (!isGitRepo) { await execUtils.execvp(`git`, [`init`], { cwd: this.context.cwd, });