Index: sdk/lib/_internal/pub/lib/src/entrypoint.dart |
diff --git a/sdk/lib/_internal/pub/lib/src/entrypoint.dart b/sdk/lib/_internal/pub/lib/src/entrypoint.dart |
index 9341c9b39a70ed467225c973687f2243fe9f208e..b9e4ac7d1dbaf916dbc419057a03ae73da48c7da 100644 |
--- a/sdk/lib/_internal/pub/lib/src/entrypoint.dart |
+++ b/sdk/lib/_internal/pub/lib/src/entrypoint.dart |
@@ -8,6 +8,7 @@ import 'dart:async'; |
import 'package:pathos/path.dart' as path; |
+import 'git.dart' as git; |
import 'io.dart'; |
import 'lock_file.dart'; |
import 'log.dart' as log; |
@@ -215,4 +216,43 @@ class Entrypoint { |
if (entryExists(symlink)) deleteEntry(symlink); |
createSymlink(packagesDir, symlink, relative: true); |
} |
+ |
+ /// The basenames of files that are automatically excluded from archives. |
+ final _BLACKLISTED_FILES = const ['pubspec.lock']; |
+ |
+ /// The basenames of directories that are automatically excluded from |
+ /// archives. |
+ final _BLACKLISTED_DIRS = const ['packages']; |
+ |
+ /// Returns a list of files that are considered to be part of this package. |
+ /// |
+ /// If this is a Git repository, this will respect .gitignore; otherwise, it |
+ /// will return all non-hidden, non-blacklisted files. |
+ /// |
+ /// If [beneath] is passed, this will only return files beneath that path. |
+ Future<List<String>> packageFiles({String beneath}) { |
Andrei Mouravski
2013/05/13 22:40:33
Do you have a test for the .gitignore bit?
nweiz
2013/05/13 23:32:59
Actually, no; prior to this, we only ran this code
|
+ if (beneath == null) beneath = root.dir; |
+ |
+ return git.isInstalled.then((gitInstalled) { |
+ if (dirExists(path.join(root.dir, '.git')) && gitInstalled) { |
+ // List all files that aren't gitignored, including those not checked |
+ // in to Git. |
+ return git.run(["ls-files", "--cached", "--others", |
+ "--exclude-standard", beneath]).then((files) { |
+ // Git always prints files relative to the project root, but we want |
+ // them relative to the working directory. |
+ return files.map((file) => path.join(root.dir, file)); |
+ }); |
+ } |
+ |
+ // Skip directories and broken symlinks. |
+ return listDir(beneath, recursive: true).where(fileExists); |
+ }).then((files) { |
+ return files.where((file) { |
+ var relative = path.relative(file, from: beneath); |
+ if (_BLACKLISTED_FILES.contains(path.basename(relative))) return false; |
+ return !path.split(relative).any(_BLACKLISTED_DIRS.contains); |
+ }).toList(); |
+ }); |
+ } |
} |