gatsby: gatsby new fails if there's no git identity set
Description
gatsby new fails if there’s no git identity set.
I don’t set my email in ~/.gitconfig on purpose, as then I am asked to set it on the 1st commit for every new local clone (with git config --global user.useConfigOnly true). I need to use different email addresses for different projects and I always forget to set it correctly unless I don’t set my email globally.
I would love it if there were a way to skip the git commit part of setting up a new project.
Steps to reproduce
Unset your git identity (open ~/.gitconfig, remove email line in section [user], in the same section add line useConfigOnly = true, and then run e.g. gatsby new hello-world https://github.com/gatsbyjs/gatsby-starter-hello-world.
Expected result
Set up a gatsby project.
Actual result
% gatsby new gatsby-starter https://github.com/gatsbyjs/gatsby-starter-hello-world
info Creating new site from git: https://github.com/gatsbyjs/gatsby-starter-hello-world.git
Cloning into 'gatsby-starter'...
remote: Enumerating objects: 43, done.
remote: Counting objects: 100% (43/43), done.
remote: Compressing objects: 100% (27/27), done.
remote: Total 1159 (delta 29), reused 29 (delta 16), pack-reused 1116
Receiving objects: 100% (1159/1159), 3.69 MiB | 1.82 MiB/s, done.
success Created starter directory layout
info Installing packages...
yarn install v1.17.3
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
info fsevents@2.0.7: The platform "linux" is incompatible with this module.
info "fsevents@2.0.7" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.9: The platform "linux" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] 🔗 Linking dependencies...
warning "gatsby > eslint-config-react-app@4.0.1" has incorrect peer dependency "eslint-plugin-flowtype@2.x".
warning "gatsby > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
[4/4] 🔨 Building fresh packages...
info Initialising git in gatsby-starter
info Create initial git commit in gatsby-starter
9.93s user 2.95s system 103% cpu 12.462s total
INSERT zeorin ~ code gatsby new hello-world https://github.com/gatsbyjs/gatsby-starter-hello-world
info Creating new site from git: https://github.com/gatsbyjs/gatsby-starter-hello-world.git
Cloning into 'hello-world'...
remote: Enumerating objects: 43, done.
remote: Counting objects: 100% (43/43), done.
remote: Compressing objects: 100% (27/27), done.
remote: Total 1159 (delta 29), reused 29 (delta 16), pack-reused 1116
Receiving objects: 100% (1159/1159), 3.69 MiB | 1.64 MiB/s, done.
success Created starter directory layout
info Installing packages...
yarn install v1.17.3
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
info fsevents@2.0.7: The platform "linux" is incompatible with this module.
info "fsevents@2.0.7" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.9: The platform "linux" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] 🔗 Linking dependencies...
warning "gatsby > eslint-config-react-app@4.0.1" has incorrect peer dependency "eslint-plugin-flowtype@2.x".
warning "gatsby > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
[4/4] 🔨 Building fresh packages...
info Initialising git in hello-world
info Create initial git commit in hello-world
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
ERROR
Command failed: git commit -m "Initial commit from gatsby: (https://github.com/gatsbyjs/gatsby-starter-hello-world.git)"
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: no email was given and auto-detection is disabled
Error: Command failed: git commit -m "Initial commit from gatsby: (https://github.com/gatsbyjs/gatsby-starter-hello-wo rld.git)"
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: no email was given and auto-detection is disabled
- init-starter.js:151
[lib]/[gatsby-cli]/lib/init-starter.js:151:5
- Generator.next
- task_queues.js:93 processTicksAndRejections
internal/process/task_queues.js:93:5
Environment
System:
OS: Linux 5.0 Ubuntu 19.04 (Disco Dingo)
CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Shell: 5.5.1 - /bin/zsh
Binaries:
Node: 12.10.0 - /usr/bin/node
Yarn: 1.17.3 - /usr/bin/yarn
npm: 6.10.3 - /usr/bin/npm
Languages:
Python: 2.7.16 - /usr/bin/python
Browsers:
Chrome: 77.0.3865.90
Firefox: 69.0
npmGlobalPackages:
gatsby-cli: 2.7.49
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (12 by maintainers)
Yeah, you are right about this - we should definitely have generic error handling there, to at least not crash.
I still think having special case for missing git identity could be valuable - maybe we would want to skip initializing git repo at all if email is not set (so we bail on all git actions and don’t have to rollback some of them). I think it’s easier for users (specifically users new to git) - this way as they wouldn’t have to figure out how to dig out of whatever git status is left with and they could follow whatever tutorial showing up how to init repository, make initial commit, etc.
As you said, commit can fail for multiple reasons and it’s unlikely we would have special cases for all of them (or even know about all possibilities), but catching common ones early would make better user experience (IMO)
Git could possibly fail for other reasons though, not just because of a missing identity. Just catching the error and leaving the repo in a consistent state, possibly just carrying on without the commit, and printing the error, whatever it is, and a message about the impact thereof (no initial commit made), should robustly handle any commit issues, not just the identity issue.
Hey @zeorin, I hope you don’t mind if I reopen this issue - it’s great you found workaround but this is something we would like to fix, so keeping this issue open for people to find and possibly contribute is great way to do this