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

Ignore .git, .svn and .hg directories #4906

Merged
merged 2 commits into from Jul 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cli/util.js
Expand Up @@ -403,6 +403,7 @@ function eachFilename(context, patterns, callback) {
if (ignoreNodeModules) {
patterns = patterns.concat(["!**/node_modules/**", "!./node_modules/**"]);
}
patterns = patterns.concat(["!**/.{git,svn,hg}/**", "!./.{git,svn,hg}/**"]);
Copy link
Member

Choose a reason for hiding this comment

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

It seems the !./.{git,svn,hg}/** part is unnecessary, and so does !./node_modules/**.

$ tree test
test
├── dir
│   ├── node_modules
│   │   └── x.js
│   └── x.js
├── node_modules
│   └── x.js
└── x.js

$ node -e 'console.log(
  require("globby").sync(
    ["**/*.js", "!**/node_modules/**"],
    { cwd: "test" }
  )
)'
[ 'dir/x.js', 'x.js' ]

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Try re-running that with ./**/*.js as the glob.

Copy link
Member

Choose a reason for hiding this comment

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

Cool, didn't know that. Can you add a comment for it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure.


try {
const filePaths = globby
Expand Down
10 changes: 10 additions & 0 deletions tests_integration/__tests__/__snapshots__/ignore-vcs-files.js.snap
@@ -0,0 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ignores files in version control systems (stderr) 1`] = `""`;

exports[`ignores files in version control systems (stdout) 1`] = `
"file.js
"
`;

exports[`ignores files in version control systems (write) 1`] = `Array []`;
Expand Up @@ -72,7 +72,7 @@ directory/nested-directory/nested-directory-file.js
exports[`multiple patterns with non exists pattern (write) 1`] = `Array []`;

exports[`multiple patterns, throw error and exit with non zero code on non existing files (stderr) 1`] = `
"[error] No matching files. Patterns tried: non-existent.js other-non-existent.js !**/node_modules/** !./node_modules/**
"[error] No matching files. Patterns tried: non-existent.js other-non-existent.js !**/node_modules/** !./node_modules/** !**/.{git,svn,hg}/** !./.{git,svn,hg}/**
"
`;

Expand Down
16 changes: 16 additions & 0 deletions tests_integration/__tests__/ignore-vcs-files.js
@@ -0,0 +1,16 @@
"use strict";

const runPrettier = require("../runPrettier");

expect.addSnapshotSerializer(require("../path-serializer"));

describe("ignores files in version control systems", () => {
runPrettier("cli/ignore-vcs-files", [
".svn/file.js",
".hg/file.js",
"file.js",
"-l"
]).test({
status: 1
});
});
1 change: 1 addition & 0 deletions tests_integration/cli/ignore-vcs-files/.hg/file.js
@@ -0,0 +1 @@
'use strict';
2 changes: 2 additions & 0 deletions tests_integration/cli/ignore-vcs-files/.svn/file.js
@@ -0,0 +1,2 @@
/* eslint-disable */
'use strict';
1 change: 1 addition & 0 deletions tests_integration/cli/ignore-vcs-files/file.js
@@ -0,0 +1 @@
'use strict';