diff --git a/lib/src/command/lish.dart b/lib/src/command/lish.dart index 01dd0bf94b6e9ad9d4d7c3ec8516bb284d83b05c..2b0a506b4152a21cdd3e2b03eaad1837351fe546 100644 --- a/lib/src/command/lish.dart +++ b/lib/src/command/lish.dart @@ -117,7 +117,7 @@ class LishCommand extends PubCommand { 'pubspec.'); } - var files = entrypoint.root.listFiles(); + var files = entrypoint.root.listFiles(useGitIgnore: true); log.fine('Archiving and publishing ${entrypoint.root}.'); // Show the package contents so the user can verify they look OK. diff --git a/lib/src/package.dart b/lib/src/package.dart index 40e93e10ae14d6d18e76265a7dcb5100d73f0226..af0c750f606e8fe6505e53aaa3a1aa9cd7073d33 100644 --- a/lib/src/package.dart +++ b/lib/src/package.dart @@ -183,9 +183,13 @@ class Package { /// [recursive] is true, this will return all files beneath that path; /// otherwise, it will only return files one level beneath it. /// + /// If [useGitIgnore] is passed, this will take the .gitignore rules into + /// account if the package's root directory is a Git repository. + /// /// Note that the returned paths won't always be beneath [dir]. To safely /// convert them to paths relative to the package root, use [relative]. - List<String> listFiles({String beneath, recursive: true}) { + List<String> listFiles({String beneath, bool recursive: true, + bool useGitIgnore: false}) { if (beneath == null) { beneath = dir; } else { @@ -200,7 +204,7 @@ class Package { // path package, since re-parsing a path is very expensive relative to // string operations. var files; - if (git.isInstalled && dirExists(path('.git'))) { + if (useGitIgnore && git.isInstalled && dirExists(path('.git'))) { // Later versions of git do not allow a path for ls-files that appears to // be outside of the repo, so make sure we give it a relative path. var relativeBeneath = p.relative(beneath, from: dir); diff --git a/lib/src/validator/compiled_dartdoc.dart b/lib/src/validator/compiled_dartdoc.dart index 73b40e7f400149744bc845b2b2d8fb5ac6989ea4..10b351fb0563f6d91790b007081f3c0f9a68619e 100644 --- a/lib/src/validator/compiled_dartdoc.dart +++ b/lib/src/validator/compiled_dartdoc.dart @@ -20,7 +20,7 @@ class CompiledDartdocValidator extends Validator { Future validate() { return new Future.sync(() { - for (var entry in entrypoint.root.listFiles()) { + for (var entry in entrypoint.root.listFiles(useGitIgnore: true)) { if (path.basename(entry) != "nav.json") continue; var dir = path.dirname(entry); diff --git a/test/package_list_files_test.dart b/test/package_list_files_test.dart index 9b5a06c315dd7a990322d2a3ce2723232ae041ed..56d8fb85e6b7f0d1a65d4af93c7621f403bb51e1 100644 --- a/test/package_list_files_test.dart +++ b/test/package_list_files_test.dart @@ -13,8 +13,8 @@ import '../lib/src/system_cache.dart'; import 'descriptor.dart' as d; import 'test_pub.dart'; -var root; -var entrypoint; +String root; +Entrypoint entrypoint; main() { initConfig(); @@ -78,7 +78,7 @@ main() { }); }); - integration("ignores files that are gitignored", () { + integration("ignores files that are gitignored if desired", () { d.dir(appPath, [ d.file('.gitignore', '*.txt'), d.file('file1.txt', 'contents'), @@ -90,13 +90,23 @@ main() { ]).create(); schedule(() { - expect(entrypoint.root.listFiles(), unorderedEquals([ + expect(entrypoint.root.listFiles(useGitIgnore: true), unorderedEquals([ path.join(root, 'pubspec.yaml'), path.join(root, '.gitignore'), path.join(root, 'file2.text'), path.join(root, 'subdir', 'subfile2.text') ])); }); + + schedule(() { + expect(entrypoint.root.listFiles(), unorderedEquals([ + path.join(root, 'pubspec.yaml'), + path.join(root, 'file1.txt'), + path.join(root, 'file2.text'), + path.join(root, 'subdir', 'subfile1.txt'), + path.join(root, 'subdir', 'subfile2.text') + ])); + }); }); commonTests(); diff --git a/test/serve/does_not_serve_gitignored_assets_in_a_path_dependency_test.dart b/test/serve/does_not_serve_gitignored_assets_in_a_path_dependency_test.dart deleted file mode 100644 index d92eb261bbf94e379556cea5b4c3a588232a91f1..0000000000000000000000000000000000000000 --- a/test/serve/does_not_serve_gitignored_assets_in_a_path_dependency_test.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS d.file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -library pub_tests; - -import '../descriptor.dart' as d; -import '../test_pub.dart'; -import 'utils.dart'; - -main() { - initConfig(); - integration("doesn't serve .gitignored assets in a path dependency", () { - ensureGit(); - - d.dir(appPath, [ - d.appPubspec({"foo": {"path": "../foo"}}), - ]).create(); - - d.git("foo", [ - d.libPubspec("foo", "1.0.0"), - d.dir("lib", [ - d.file("outer.txt", "outer contents"), - d.file("visible.txt", "visible"), - d.dir("dir", [ - d.file("inner.txt", "inner contents"), - ]) - ]), - d.file(".gitignore", "/lib/outer.txt\n/lib/dir") - ]).create(); - - pubServe(shouldGetFirst: true); - requestShould404("packages/foo/outer.txt"); - requestShould404("packages/foo/dir/inner.txt"); - requestShouldSucceed("packages/foo/visible.txt", "visible"); - endPubServe(); - }); -} diff --git a/test/serve/does_not_serve_gitignored_assets_test.dart b/test/serve/does_not_serve_gitignored_assets_test.dart deleted file mode 100644 index 598ecf79010e2021a4dc1ac988ebe29832533b5e..0000000000000000000000000000000000000000 --- a/test/serve/does_not_serve_gitignored_assets_test.dart +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS d.file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -library pub_tests; - -import '../descriptor.dart' as d; -import '../test_pub.dart'; -import 'utils.dart'; - -main() { - initConfig(); - integration("doesn't serve .gitignored assets", () { - ensureGit(); - - d.git(appPath, [ - d.appPubspec(), - d.dir("web", [ - d.file("outer.txt", "outer contents"), - d.dir("dir", [ - d.file("inner.txt", "inner contents"), - ]) - ]), - d.file(".gitignore", "/web/outer.txt\n/web/dir") - ]).create(); - - pubServe(); - requestShould404("outer.txt"); - requestShould404("dir/inner.txt"); - endPubServe(); - }); -} diff --git a/test/serve/serves_hidden_assets_that_arent_gitignored_test.dart b/test/serve/serves_hidden_assets_that_arent_gitignored_test.dart deleted file mode 100644 index 5ef198f5b008f5cf1c3cb9b74feab5cb83ffd9b0..0000000000000000000000000000000000000000 --- a/test/serve/serves_hidden_assets_that_arent_gitignored_test.dart +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS d.file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -library pub_tests; - -import '../descriptor.dart' as d; -import '../test_pub.dart'; -import 'utils.dart'; - -main() { - initConfig(); - integration("serves hidden assets that aren't .gitignored", () { - ensureGit(); - - d.git(appPath, [ - d.appPubspec(), - d.dir("web", [ - d.file(".outer.txt", "outer contents"), - d.dir(".dir", [ - d.file("inner.txt", "inner contents"), - ]) - ]) - ]).create(); - - pubServe(); - requestShouldSucceed(".outer.txt", "outer contents"); - requestShouldSucceed(".dir/inner.txt", "inner contents"); - endPubServe(); - }); -} diff --git a/test/validator/compiled_dartdoc_test.dart b/test/validator/compiled_dartdoc_test.dart index 38ee28499a4971794183290c79b30f6eda9ca1c0..d269b0619f6d88bb5bf75d71a10ac1c302377409 100644 --- a/test/validator/compiled_dartdoc_test.dart +++ b/test/validator/compiled_dartdoc_test.dart @@ -102,4 +102,4 @@ main() { expectValidationWarning(compiledDartdoc); }); }); -} +} \ No newline at end of file