Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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