gatsby new fails if there's no git identity set

Created on 20 Sep 2019  路  16Comments  路  Source: gatsbyjs/gatsby

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 [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] 馃敆  Linking dependencies...
warning "gatsby > [email protected]" has incorrect peer dependency "[email protected]".
warning "gatsby > @typescript-eslint/eslint-plugin > [email protected]" 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聽顐奥爖eorin聽顐奥爚聽顐甭燾ode聽顐奥爂atsby 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 [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] 馃敆  Linking dependencies...
warning "gatsby > [email protected]" has incorrect peer dependency "[email protected]".
warning "gatsby > @typescript-eslint/eslint-plugin > [email protected]" 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 "[email protected]"
  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 "[email protected]"
  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 "[email protected]"
    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

help wanted

All 16 comments

Thanks for opening the issue!

It would probably be best in this case then if the CLI bails the commit and removes .git. We're happy to receive a PR from the community to implement this, however we (the core team) won't fix this. Thanks for using Gatsby!

I've just discovered a workaround: need to set the GIT_COMMITTER_EMAIL and GIT_AUTHOR_EMAIL environment variables, and git will use those values for the initial commit that gatsby makes. E.g.:

[email protected] [email protected] gatsby new hello-world https://github.com/gatsbyjs/gatsby-starter-hello-world

It's not very ergonomic, but it works.

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

For anyone who would like to work on this:
I think easiest way is to add try/catch block inside https://github.com/gatsbyjs/gatsby/blob/ffeed10c8e11e17fd9b6edd04b50c438ca1402d0/packages/gatsby-cli/src/init-starter.js#L83-L92

It would be great if we could determine if git identity is set before doing git add there to not leave git status in very weird spot when lot of files are staged - possibly running git config user.email and git config user.name and checking if those are not empty is reasonable way to do it?

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.

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)

@pieh We could try catch the whole git process if it fails we rimraf the .git directory and we should be back without git support. I might be missing something 馃槢

Sure, let's do that ;) I was probably overthinking this

if this is skipped a info message should be printed to console ...

@siddhant1 I want to take this, but can't assign myself to it (probably because I'm not listed as an contributor)

Is this taken?

@kcurtet is working on this!

Gatsby CLI version: 2.7.58
package.json from gatsby-cli source code

{
  "name": "gatsby-cli",
  "version": "2.7.58",
  ...
}

HI, I have some issues for recreating the error with the source code.

First i change my ~/.gitconfig to look like this:

[user]
        useConfigOnly = true

Then I try the command with the official gatsby package.

gatsby new gatsby-starter https://github.com/gatsbyjs/gatsby-starter-hello-world

The error appears.
gatsby git error

Next I build the source code from gatsbyjs/gatsby/packages/gatsby-cli.

I try to reproduce the error with:

# pwd: gatsby repo
node packages/gatsby-cli/lib/index.js new gatsby-starter https://github.com/gatsbyjs/gatsby-starter-hello-world

And the command creates a new starter without git initialized. I don't see any error.
Imgur

Maybe it's already fixed?

can repro this with

mv ~/.gitconfig ~/.gitconfig.backup
./<path to gatsby repo>/packages/gatsby-cli/lib/index.js new gatsby-site

image

PR above removes .git directory when initial commit fails, as discussed by @wardpeet and @pieh. Also added info message as per @muescha's comment.

i am a little against deleting the .git directory per default

is there an situation if there is an already exisiting .git directory from a previous usage and we delete this directory without an question

here it is already removed before... so not mind my comment

https://github.com/gatsbyjs/gatsby/blob/d2345b6199421c1230415daf179e78c960e1a5d2/packages/gatsby-cli/src/init-starter.js#L177-L183

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kalinchernev picture kalinchernev  路  3Comments

brandonmp picture brandonmp  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

benstr picture benstr  路  3Comments

signalwerk picture signalwerk  路  3Comments