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

gatsby new fails if there's no git identity set #17766

Closed
zeorin opened this issue Sep 20, 2019 · 16 comments · Fixed by #18839
Closed

gatsby new fails if there's no git identity set #17766

zeorin opened this issue Sep 20, 2019 · 16 comments · Fixed by #18839
Labels
help wanted Issue with a clear description that the community can help with.

Comments

@zeorin
Copy link

zeorin commented Sep 20, 2019

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

@LekoArts LekoArts added help wanted Issue with a clear description that the community can help with. type: feature or enhancement labels Sep 23, 2019
@LekoArts
Copy link
Contributor

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!

@zeorin
Copy link
Author

zeorin commented Sep 23, 2019

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.:

GIT_COMMITTER_EMAIL=joe@example.com GIT_AUTHOR_EMAIL=joe@example.com gatsby new hello-world https://github.com/gatsbyjs/gatsby-starter-hello-world

It's not very ergonomic, but it works.

@zeorin zeorin closed this as completed Sep 23, 2019
@pieh
Copy link
Contributor

pieh commented Sep 23, 2019

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

@pieh pieh reopened this Sep 23, 2019
@pieh
Copy link
Contributor

pieh commented Sep 23, 2019

For anyone who would like to work on this:
I think easiest way is to add try/catch block inside

const createInitialGitCommit = async (rootPath, starterUrl) => {
report.info(`Create initial git commit in ${rootPath}`)
await spawn(`git add -A`, { cwd: rootPath })
// use execSync instead of spawn to handle git clients using
// pgp signatures (with password)
execSync(`git commit -m "Initial commit from gatsby: (${starterUrl})"`, {
cwd: rootPath,
})
}

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?

@zeorin
Copy link
Author

zeorin commented Sep 23, 2019

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.

@pieh
Copy link
Contributor

pieh commented Sep 23, 2019

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)

@wardpeet
Copy link
Contributor

@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 😛

@pieh
Copy link
Contributor

pieh commented Sep 23, 2019

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

@muescha
Copy link
Contributor

muescha commented Sep 23, 2019

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

@rajjeet
Copy link

rajjeet commented Sep 24, 2019

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

@anamritraj
Copy link
Contributor

Is this taken?

@sidharthachatterjee
Copy link
Contributor

@kcurtet is working on this!

@kcurtet
Copy link

kcurtet commented Oct 11, 2019

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?

@jmsv
Copy link
Contributor

jmsv commented Oct 19, 2019

can repro this with

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

image

@jmsv
Copy link
Contributor

jmsv commented Oct 19, 2019

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

@muescha
Copy link
Contributor

muescha commented Oct 19, 2019

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

await fs.remove(sysPath.join(rootPath, `.git`))
await install(rootPath)
const isGit = await isAlreadyGitRepository()
if (!isGit) await gitInit(rootPath)
await maybeCreateGitIgnore(rootPath)
if (!isGit) await createInitialGitCommit(rootPath, url)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issue with a clear description that the community can help with.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants