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

remove gitDir config option #327

Merged
merged 9 commits into from Nov 11, 2017
Merged

remove gitDir config option #327

merged 9 commits into from Nov 11, 2017

Conversation

camacho
Copy link
Contributor

@camacho camacho commented Nov 6, 2017

close #271

@codecov
Copy link

codecov bot commented Nov 6, 2017

Codecov Report

Merging #327 into master will increase coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #327      +/-   ##
==========================================
+ Coverage   97.15%   97.28%   +0.12%     
==========================================
  Files          10       10              
  Lines         176      184       +8     
  Branches       26       25       -1     
==========================================
+ Hits          171      179       +8     
  Misses          5        5
Impacted Files Coverage Δ
src/runAll.js 100% <100%> (ø) ⬆️
src/resolveGitDir.js 100% <100%> (ø) ⬆️
src/runScript.js 100% <100%> (ø) ⬆️
src/generateTasks.js 100% <100%> (ø) ⬆️
src/getConfig.js 97.29% <100%> (+0.15%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0e40d2c...0e174ee. Read the comment docs.

@okonet
Copy link
Collaborator

okonet commented Nov 6, 2017

Amazing work @camacho! Does tests cover all edge cases? I didn't see any tests where gitDir isn't process.cwd. Could you add some, please?

okonet
okonet previously approved these changes Nov 6, 2017
@camacho
Copy link
Contributor Author

camacho commented Nov 6, 2017

Those cases should be covered by the spec changes. I adjusted the old tests to account for a different gitDir by mocking what is returned by the resolveGitDir and process.cwd functions (instead of passing in the gitDir config option). The test checks also including passing in the cwd option to execa if the gitDir is different than process.cwd and the bin is not git

@@ -77,8 +88,21 @@ describe('generateTasks', () => {
})
})

it('should not match non-children files', () => {
const relPath = path.resolve(path.join(process.cwd(), '..'))
resolveGitDir.mockReturnValueOnce(relPath)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@okonet check for filtering out files that aren't in the cwd but show up because gitDir is diff

it('should pass cwd to execa if gitDir option is set for non-npm tasks', async () => {
const res = runScript(['test', 'git add'], ['test.js'], scripts, { gitDir: '../' })
it('should pass cwd to execa if gitDir is different than process.cwd for non-npm tasks', async () => {
resolveGitDir.mockReturnValue('../')
Copy link
Contributor Author

@camacho camacho Nov 6, 2017

Choose a reason for hiding this comment

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

@okonet check for proper execa cwd if gitDir is diff than process.cwd

Copy link
Collaborator

@sudo-suhas sudo-suhas left a comment

Choose a reason for hiding this comment

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

Looks good overall, only minor changes required.

const fileList = files
// Only worry about children of the CWD
.filter(file => file.startsWith(cwd))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's use path-is-inside here. From the readme:

It turns out this question isn't trivial to answer using Node's built-in path APIs. A naive indexOf-based solution will fail sometimes on Windows, which is case-insensitive (see e.g. isaacs/npm#4214).

@@ -13,14 +12,4 @@ describe('resolveGitDir', () => {
expect(resolveGitDir('.')).toEqual(expected)
Copy link
Collaborator

Choose a reason for hiding this comment

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

resolveGitDir no longer accepts an argument. Please remove the parameter '.' in the function invocation.

@camacho
Copy link
Contributor Author

camacho commented Nov 7, 2017

@sudo-suhas updated based on feedback

sudo-suhas
sudo-suhas previously approved these changes Nov 7, 2017
Copy link
Collaborator

@sudo-suhas sudo-suhas left a comment

Choose a reason for hiding this comment

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

Thanks @camacho!

@sudo-suhas
Copy link
Collaborator

@okonet Do you think it would be a good idea to publish this with the next tag?

@okonet
Copy link
Collaborator

okonet commented Nov 8, 2017

@sudo-suhas why not do just breaking change? I feel like I'm not having enough time to batch changes into bigger releases and I don't want to postpone on new features from PRs.

@okonet
Copy link
Collaborator

okonet commented Nov 8, 2017

@camacho could you please resolve the conflicts and update the branch?

Also I don't quite get your comments on tests: do you mean our tests aren't exhausting or what exactly?

@camacho
Copy link
Contributor Author

camacho commented Nov 8, 2017

@okonet sorry for not being more clear. The tests seem extensive enough. I was trying to highlight the places in the code where we test the gitDir being different than the process cwd. As far as I can tell, all cases are covered, but I am happy to add more tests if you have any cases in mind that are uncovered.

conflicts resolved

@sudo-suhas
Copy link
Collaborator

@okonet Breaking changes is a good idea. That will suffice.

okonet
okonet previously approved these changes Nov 9, 2017
@okonet
Copy link
Collaborator

okonet commented Nov 9, 2017

@camacho one question that struck me before the merge: how this PR behaves with old configs that has the option? Will it output the deprecation message?

@sudo-suhas
Copy link
Collaborator

@okonet Good catch! I think it will print the Unknown option warning. We should update getConfig.js so that it prints the deprecation warning similar to https://www.npmjs.com/package/jest-validate#deprecation.

@okonet
Copy link
Collaborator

okonet commented Nov 9, 2017

I've tested it and it displays a generic message right now:

● Validation Warning:

  Unknown option "gitDir" with value "." was found.
  This is probably a typing mistake. Fixing it will remove this message.

Please refer to https://github.com/okonet/lint-staged#configuration for more information...

which is confusing. Let's add a proper deprecation message, please.

You'll need to add deprecatedConfig and pass it to the validation function here https://github.com/okonet/lint-staged/blob/master/src/getConfig.js#L123

See https://github.com/facebook/jest/tree/master/packages/jest-validate for more information.

@okonet
Copy link
Collaborator

okonet commented Nov 9, 2017

@camacho here is the patch you need to apply:

diff --git a/src/getConfig.js b/src/getConfig.js
index dc93440..fe8e684 100644
--- a/src/getConfig.js
+++ b/src/getConfig.js
@@ -30,6 +30,14 @@ const defaultConfig = {
   verbose: false
 }
 
+const deprecatedConfig = {
+  gitDir: config => `  Option ${chalk.bold('gitDir')} was removed.
+
+  lint-staged now automatically resolves '.git' directory.
+
+  Please remove ${chalk.bold('gitDir')} from your configuration.`
+}
+
 /**
  * Check if the config is "simple" i.e. doesn't contains any of full config keys
  *
@@ -121,6 +129,7 @@ function validateConfig(config) {
 
   const validation = validate(config, {
     exampleConfig,
+    deprecatedConfig,
     unknown: unknownValidationReporter,
     comment:
       'Please refer to https://github.com/okonet/lint-staged#configuration for more information...'

@camacho
Copy link
Contributor Author

camacho commented Nov 10, 2017

Requested changes pushed

@sudo-suhas
Copy link
Collaborator

@camacho could you please add a snapshot test for this?

Copy link
Collaborator

@sudo-suhas sudo-suhas left a comment

Choose a reason for hiding this comment

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

Only minor changes. Thank you @camacho for addressing all the feedback. Hopefully this is the last one 😉

@@ -211,6 +211,17 @@ describe('validateConfig', () => {
expect(console.printHistory()).toMatchSnapshot()
})

it('should not throw and should print validation warnings for old config', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we change this test title to should print deprecation warning for gitDir option?

@@ -211,6 +211,17 @@ describe('validateConfig', () => {
expect(console.printHistory()).toMatchSnapshot()
})

it('should not throw and should print validation warnings for old config', () => {
const invalidMixedConfig = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rename variable to configWithDeprecatedOpt please.

"
WARN ● Deprecation Warning:

Option gitDir was removed.
Copy link
Collaborator

Choose a reason for hiding this comment

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

@okonet Does the formatting for this text seem a bit odd to you?

@camacho
Copy link
Contributor Author

camacho commented Nov 11, 2017

updated

@okonet okonet merged commit 32d80de into lint-staged:master Nov 11, 2017
@okonet
Copy link
Collaborator

okonet commented Nov 11, 2017

Had to amend from master and force push master :(

Lessons learned: don't merge breaking changes from the bed on the iPad 🤦‍♂️

@okonet
Copy link
Collaborator

okonet commented Nov 11, 2017

Thanks again for your work!

@camacho
Copy link
Contributor Author

camacho commented Nov 11, 2017

Happy to contribute @okonet

okonet pushed a commit that referenced this pull request Nov 11, 2017
* Remove `gitDir` config option
* Automatically resolve `.git` directory in the project

Closes #271

BREAKING CHANGE: `gitDir` option deprecated and will be ignored
@sudo-suhas
Copy link
Collaborator

Had to amend from master and force push master :(

Good thing you caught it early.

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

Successfully merging this pull request may close these issues.

Get rid of gitDir config option and be smart about it
3 participants