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

Ejecting should ensure you have clean git status #2090

Closed
wants to merge 15 commits into from
Closed

Ejecting should ensure you have clean git status #2090

wants to merge 15 commits into from

Conversation

milocosmopolitan
Copy link
Contributor

@milocosmopolitan milocosmopolitan commented May 5, 2017

@Timer
Copy link
Contributor

Timer commented May 5, 2017

Wow, great! I'll take a peek at this soon.
Thank you!

@Timer Timer added this to the 0.10.0 milestone May 5, 2017
@@ -36,6 +37,31 @@ prompt(
process.exit(1);
}

// Make sure there are no dirty git status
const git = fs.existsSync(path.join(process.cwd(), '.git'));

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @thejameskyle, can you explain what are the benefits of using that library? Is it because it returns promised result? Cause I was trying to avoid using third-party library as possible. If promise is necessary I could just use instantiate Promise.

Copy link
Contributor

Choose a reason for hiding this comment

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

@milocosmopolitan someone might have their git directory several levels up the tree, especially if it's a monorepo.

However, you shouldn't be checking for the existence of .git at all -- simply execute a git command in the directory and see if it errors out 😄.

Copy link
Contributor

@Timer Timer May 5, 2017

Choose a reason for hiding this comment

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

See 1288's files for inspiration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Timer, I've made a change according to your suggestion.

try {
let stdout = execSync(`git status -s`).toString();
let status = { dirty: 0, untracked: 0 };
stdout.trim().split(/\r?\n/).forEach(file => {
Copy link
Contributor

Choose a reason for hiding this comment

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

You might want to use git status --porcelain for easier parsing.

Copy link
Contributor

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

See comment above.

@gaearon gaearon modified the milestones: 0.11.0, 0.10.0, 0.10.1 May 8, 2017
Copy link

@sunjay sunjay left a comment

Choose a reason for hiding this comment

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

Cool feature! Thanks for the PR! I saw some things, so I hope you don't mind the extra review. 😄

console.error(
`Git repository has ${status.dirty} dirty ${status.dirty > 1 ? 'files' : 'file'}. ` +
'We cannot continue as you would lose all the changes in that file or directory. ' +
'Please push commit before and run this command again.'
Copy link

Choose a reason for hiding this comment

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

I think this error message covers all the right bases. The grammar however is a bit confusing.

The first sentence mentions that you have 1 or more dirty files, but then the second sentence only refers to a single file or directory. The third sentence isn't totally clear grammatically and it states that you need to push as well as commit in order to make the directory clean. While pushing may be ideal, it isn't the same as committing and only committing is really necessary here.

What do you think of this as the error message instead?

`This git repository has ${status.dirty} dirty ${status.dirty > 1 ? 'files' : 'file'}. ` +
'We cannot continue as you would lose all of your changes. ' +
'Please commit your changes with `git commit` and then run this command again.'

This way, the user knows what to do to fix the problem and the message is completely clear.

Copy link

@taylorlapeyre taylorlapeyre May 10, 2017

Choose a reason for hiding this comment

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

My attempt at the grammar on this:

`This git repository has ${status.dirty} ${status.dirty > 1 ? 'files' : 'file'} with uncommitted changes.` +
'Ejecting would cause these files to be overwritten. ' +
'Please commit your changes with `git commit` and then run this command again.'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for those suggestions @sunjay, @taylorlapeyre. I personally liked @taylorlapeyre version. I will make an update soon.

function statusSync() {
try {
let stdout = execSync(`git status --porcelain`).toString();
let status = { dirty: 0, untracked: 0 };
Copy link

Choose a reason for hiding this comment

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

If you're also counting untracked files, why isn't that used in the dirty check below? If it shouldn't be used, why is it being counted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, I think untracked files should be exclude. I will make pull request on this tonight.

@gaearon gaearon removed this from the 1.0.1 milestone May 19, 2017
@gaearon gaearon modified the milestones: 1.0.x, 1.0.1 May 19, 2017
@Timer
Copy link
Contributor

Timer commented Jun 28, 2017

Hi! Could you please rebase this? I'd love to get this in.

@milocosmopolitan
Copy link
Contributor Author

milocosmopolitan commented Jul 2, 2017

@Timer thought it was merged
#2221

@Timer
Copy link
Contributor

Timer commented Jul 2, 2017

Oh, yeah I thought we had. Must've been a duplicate PR.

@Timer Timer closed this Jul 2, 2017
@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants