Skip to content

Commit

Permalink
fix: don't crash during init if git is not installed (#956)
Browse files Browse the repository at this point in the history
  • Loading branch information
threepointone authored May 10, 2022
1 parent 09196ec commit 1caa5f7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .changeset/afraid-cows-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"wrangler": patch
---

fix: don't crash during `init` if `git` is not installed

When a command isn't available on a system, calling `execa()` on it throws an error, and not just a non zero exitCode. This patch fixes the flow so we don't crash the whole process when that happens on testing the presence of `git` when calling `wrangler init`.

Fixes https://github.com/cloudflare/wrangler2/issues/950
12 changes: 11 additions & 1 deletion packages/wrangler/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,17 @@ export async function main(argv: string[]): Promise<void> {
const isInsideGitProject = Boolean(
await findUp(".git", { cwd: creationDirectory, type: "directory" })
);
const isGitInstalled = (await execa("git", ["--version"])).exitCode === 0;
let isGitInstalled;
try {
isGitInstalled = (await execa("git", ["--version"])).exitCode === 0;
} catch (err) {
if ((err as { code: string | undefined }).code !== "ENOENT") {
// only throw if the error is not because git is not installed
throw err;
} else {
isGitInstalled = false;
}
}
if (!isInsideGitProject && isGitInstalled) {
const shouldInitGit =
yesFlag ||
Expand Down

0 comments on commit 1caa5f7

Please sign in to comment.