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

using simple-git before running 'git config' #80

Open
sherousee opened this issue Mar 27, 2016 · 4 comments
Open

using simple-git before running 'git config' #80

sherousee opened this issue Mar 27, 2016 · 4 comments

Comments

@sherousee
Copy link

After rebuilding my webserver, I accidentally did not run git config --global user.email "you@example.com" or git config --global user.name "Your Name". This oversight seemed to cause git.commit() to 'hang'. Here is the general idea:

git('/path/to/repo')
  .add('./*')
  .commit('commit message', function(e, data) {
    console.log(e); //null
    console.log(data); //false
  })
  .revparse(['HEAD'], function(e, data) {
    //not reached
  });

Inside the commit() callback, e is set to null and data is set to false. Additionally, the revparse() callback is not executed.

Is this the intended/expected behavior? If you use git commit from the command line before running either of the config steps, you will see a message that looks something like this:

19:00:28: *** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

Do you think this message should be interpreted as an error? In any case, should git.commit() and related methods provide some sort of indication that the global git config has not been set?

Just thought I'd get your opinion on this before I looked at how to do it.

@steveukx
Copy link
Owner

Hi, thanks for all the detail. Please can you confirm that you are using the latest release of the library, 1.27.0 added handling for errors in the child process that may resolve this. If you are on latest I will look to add a test case to cover it shortly.

@sherousee
Copy link
Author

No problem. Yes, I am 1.31.0.

@istanishev
Copy link

istanishev commented Aug 16, 2016

I can see the same (with 1.45)

@mpodolsk
Copy link

mpodolsk commented Jun 29, 2021

steps to repo with node-alpine:14

$ docker run -it --tty 5ec529353938 /bin/ash 
/ # apk update && apk add --no-cache git
(7/7) Installing git (2.30.2-r0)
/app # git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint: 	git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint: 	git branch -m <name>
Initialized empty Git repository in /app/.git/
/app # cat .git/config 
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
/app # npm init
/app # npm install simple-git
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN app@1.0.0 No description
npm WARN app@1.0.0 No repository field.

+ simple-git@2.40.0
added 5 packages from 5 contributors and audited 5 packages in 1.775s
found 0 vulnerabilities

/app # node
Welcome to Node.js v14.17.1.
Type ".help" for more information.
> const s = require('simple-git')
undefined
> const repo = s('./')
undefined
> const fs = require('fs')
> fs.writeFileSync('xxx','hello')
> repo.add('./').then(x=>console.log(x))
Promise { <pending> }
> repo.commit('file aded',{'--author':'somebody <somebody@xxxxx.com>'}).then(x=>console.log(x))
Promise { <pending> }
> (node:41) UnhandledPromiseRejectionWarning: Error: Committer identity unknown

*** 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: unable to auto-detect email address (got 'root@7d6fd2566017.(none)')

    at Object.action (/app/node_modules/simple-git/src/lib/plugins/error-detection.plugin.js:30:33)
    at PluginStore.exec (/app/node_modules/simple-git/src/lib/plugins/plugin-store.js:21:33)
    at /app/node_modules/simple-git/src/lib/runners/git-executor-chain.js:95:45
    at new Promise (<anonymous>)
    at GitExecutorChain.handleTaskData (/app/node_modules/simple-git/src/lib/runners/git-executor-chain.js:93:16)
    at GitExecutorChain.<anonymous> (/app/node_modules/simple-git/src/lib/runners/git-executor-chain.js:77:46)
    at Generator.next (<anonymous>)
    at fulfilled (/app/node_modules/simple-git/src/lib/runners/git-executor-chain.js:5:58)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:41) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:41) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

> .exit 
/app # git --version
git version 2.30.2
/app # 

adding global user and email fixes the issue

/app # git config --global user.email "you@example.com"
/app # git config --global user.name "xxx"
/app # node
Welcome to Node.js v14.17.1.
> const s = require('simple-git')
> const repo = s('./')
> const fs = require('fs')
> fs.writeFileSync('xxx22','hello')
> repo.add('./').then(x=>console.log(x))
Promise { <pending> }
> 
> repo.commit('file aded',{'--author':'somebody <somebody@xxxxx.com>'}).then(x=>console.log(x))
Promise { <pending> }
> {
  author: { email: 'somebody@xxxxx.com', name: 'somebody' },
  branch: 'master',
  commit: '3620d92',
  root: true,
  summary: { changes: 304, insertions: 9921, deletions: 0 }
}

CONCLUSION 🙈 :
looks like intended git behavior.
you will get same error when using git without global config set and no local user/emailed configured.
in my case the git config was not set correctly for me in the dockerfile when building the image
You should set the global config after installing git or explicitly configure the repo using .git/config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants