From ac9be18a149c7f141fcde94e6c126cbebc82e9ec Mon Sep 17 00:00:00 2001
From: "rnystrom@google.com" <rnystrom@google.com>
Date: Thu, 25 Sep 2014 00:38:54 +0000
Subject: [PATCH] Don't use .gitignore when determining what to
 build/serve/run.

(Still use it for publishing.)

BUG=https://code.google.com/p/dart/issues/detail?id=9841
R=nweiz@google.com

Review URL: https://codereview.chromium.org//599303002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge@40661 260f80e4-7a28-3924-810f-c04153c831b5
---
 lib/src/command/lish.dart                     |  2 +-
 lib/src/package.dart                          |  8 +++-
 lib/src/validator/compiled_dartdoc.dart       |  2 +-
 test/package_list_files_test.dart             | 18 +++++++--
 ...ored_assets_in_a_path_dependency_test.dart | 38 -------------------
 ...does_not_serve_gitignored_assets_test.dart | 32 ----------------
 ...den_assets_that_arent_gitignored_test.dart | 31 ---------------
 test/validator/compiled_dartdoc_test.dart     |  2 +-
 8 files changed, 23 insertions(+), 110 deletions(-)
 delete mode 100644 test/serve/does_not_serve_gitignored_assets_in_a_path_dependency_test.dart
 delete mode 100644 test/serve/does_not_serve_gitignored_assets_test.dart
 delete mode 100644 test/serve/serves_hidden_assets_that_arent_gitignored_test.dart

diff --git a/lib/src/command/lish.dart b/lib/src/command/lish.dart
index 01dd0bf9..2b0a506b 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 40e93e10..af0c750f 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 73b40e7f..10b351fb 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 9b5a06c3..56d8fb85 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 d92eb261..00000000
--- 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 598ecf79..00000000
--- 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 5ef198f5..00000000
--- 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 38ee2849..d269b061 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
-- 
GitLab