-
Notifications
You must be signed in to change notification settings - Fork 9
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
Safe invoke of git command #45
base: master
Are you sure you want to change the base?
Conversation
var gitRevParseTopLevel = exec('git rev-parse --show-toplevel'); | ||
if (gitRevParseTopLevel.code !== 0) { | ||
console.error('guppy-cli needs a git repository to work with.'); | ||
return exit(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is the lib meant to be consumed by other packages (including the bin/index.js
), we should return an error to expose it to the caller, and let the caller handle the error (you can exit(1)
there), rather than doing it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for late response. Please check my latest commit. Does it now work out for you?
Thanks for the contribution! Just had one remark, if you can update your code accordingly, I should be able to merge this in soon thereafter. 👍 |
@@ -2,7 +2,6 @@ | |||
/* global error */ | |||
'use strict'; | |||
|
|||
require('shelljs/global'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, the call of exec()
in this file was the only need for this requirement. As I kicked those calls shelljs/global
is not needed anymore IMHO. Hence, it was code cleaning. If it's needed somewhere else, let's bring it back in.
Sidenote: My personal opinion on this library isn't quite positive at all as it pollutes the global scope and it becomes harder to trace where such global functions like exec
actually come from. But that's just a matter of taste. ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, thanks for clarifying!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to other solutions that don't pollute the global namespace. Feel free to create another PR if you'd like to see that changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll wait for your response before merging this, since it seems this PR may be obsoleted by removing shelljs.
Using
exec()
without any check of returned exit code makes the whole node process hang. A more real-world scenario is simply trying to runguppy
in a directory that is not part of a git repository:I introduced
findGitRoot()
helper to substitude the twoexec()
calls with a more advanced approach also checking the returned.code
property.Hence, this seems to be more an issue with
shelljs
?Fixes #39