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

Safe invoke of git command #45

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

mhoyer
Copy link

@mhoyer mhoyer commented Aug 3, 2016

Using exec() without any check of returned exit code makes the whole node process hang. A more real-world scenario is simply trying to run guppy in a directory that is not part of a git repository:

mkdir tmp
cd tmp
npm install guppy-cli
./node_modules/.bin/guppy pre-commit
# ... hangs

I introduced findGitRoot() helper to substitude the two exec() calls with a more advanced approach also checking the returned .code property.

Hence, this seems to be more an issue with shelljs?

Fixes #39

@mhoyer mhoyer changed the title Safe invoke of git command Safe invoke of git command - fixes #39 Aug 3, 2016
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);
Copy link
Owner

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.

Copy link
Author

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?

@therealklanni
Copy link
Owner

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

@therealklanni therealklanni changed the title Safe invoke of git command - fixes #39 Safe invoke of git command Aug 4, 2016
@therealklanni therealklanni self-assigned this Aug 4, 2016
@@ -2,7 +2,6 @@
/* global error */
'use strict';

require('shelljs/global');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed?

Copy link
Author

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. ;-)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, thanks for clarifying!

Copy link
Owner

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.

Copy link
Owner

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.

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

Successfully merging this pull request may close these issues.

2 participants