Skip to content

Commit

Permalink
fix: wrangler init should not crash if Git is not available on Windows
Browse files Browse the repository at this point in the history
We check for the presence of Git by trying to run `git --version`.
On non-Windows we get an Error with `code` set to "ENOENT".
One Windows we get a different error:

```
{
  "shortMessage":"Command failed with exit code 1: git --version",
  "command":"git --version",
  "escapedCommand":"git --version",
  "exitCode":1,
  "stdout":"",
  "stderr":"'git' is not recognized as an internal or external command,\r\noperable program or batch file.",
  "failed":true,
  "timedOut":false,
  "isCanceled":false,
  "killed":false
}
```

Since we don't really care what the error is, now we just assume that Git
is not available if an error is thrown.

Fixes cloudflare#1022
  • Loading branch information
petebacondarwin committed May 16, 2022
1 parent cd2c42f commit bb2d1d8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
29 changes: 29 additions & 0 deletions .changeset/metal-bees-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
"wrangler": patch
---

fix: `wrangler init` should not crash if Git is not available on Windows

We check for the presence of Git by trying to run `git --version`.
On non-Windows we get an Error with `code` set to "ENOENT".
One Windows we get a different error:

```
{
"shortMessage":"Command failed with exit code 1: git --version",
"command":"git --version",
"escapedCommand":"git --version",
"exitCode":1,
"stdout":"",
"stderr":"'git' is not recognized as an internal or external command,\r\noperable program or batch file.",
"failed":true,
"timedOut":false,
"isCanceled":false,
"killed":false
}
```

Since we don't really care what the error is, now we just assume that Git
is not available if an error is thrown.

Fixes #1022
7 changes: 1 addition & 6 deletions packages/wrangler/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,7 @@ export async function main(argv: string[]): Promise<void> {
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;
}
isGitInstalled = false;
}
if (!isInsideGitProject && isGitInstalled) {
const shouldInitGit =
Expand Down

0 comments on commit bb2d1d8

Please sign in to comment.