Skip to content

Commit 5314f23

Browse files
authored
Merge pull request #1797 from gagoman/feature/1791
Added more verbose error description for upload size validator
2 parents df4f2e6 + dd53e6e commit 5314f23

File tree

3 files changed

+63
-8
lines changed

3 files changed

+63
-8
lines changed

lib/src/package.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class Package {
109109
}
110110

111111
/// Returns whether or not this package is in a Git repo.
112-
bool get _inGitRepo {
112+
bool get inGitRepo {
113113
if (_inGitRepoCache != null) return _inGitRepoCache;
114114

115115
if (dir == null || !git.isInstalled) {
@@ -242,7 +242,7 @@ class Package {
242242
// path package, since re-parsing a path is very expensive relative to
243243
// string operations.
244244
Iterable<String> files;
245-
if (useGitIgnore && _inGitRepo) {
245+
if (useGitIgnore && inGitRepo) {
246246
// List all files that aren't gitignored, including those not checked in
247247
// to Git. Use [beneath] as the working dir rather than passing it as a
248248
// parameter so that we list a submodule using its own git logic.

lib/src/validator/size.dart

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:async';
66
import 'dart:math' as math;
77

88
import '../entrypoint.dart';
9+
import '../io.dart';
910
import '../validator.dart';
1011

1112
/// The maximum size of the package to upload (100 MB).
@@ -21,8 +22,21 @@ class SizeValidator extends Validator {
2122
return packageSize.then((size) {
2223
if (size <= _MAX_SIZE) return;
2324
var sizeInMb = (size / math.pow(2, 20)).toStringAsPrecision(4);
24-
errors.add("Your package is $sizeInMb MB. Hosted packages must be "
25-
"smaller than 100 MB.");
25+
// Current implementation of Package.listFiles skips hidden files
26+
var ignoreExists = fileExists(entrypoint.root.path('.gitignore'));
27+
28+
var error = new StringBuffer("Your package is $sizeInMb MB. Hosted "
29+
"packages must be smaller than 100 MB.");
30+
31+
if (ignoreExists && !entrypoint.root.inGitRepo) {
32+
error.write(" Your .gitignore has no effect since your project "
33+
"does not appear to be in version control.");
34+
} else if (!ignoreExists && entrypoint.root.inGitRepo) {
35+
error.write(" Consider adding a .gitignore to avoid including "
36+
"temporary files.");
37+
}
38+
39+
errors.add(error.toString());
2640
});
2741
}
2842
}

test/validator/size_test.dart

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,56 @@ ValidatorCreator size(int size) {
1717
return (entrypoint) => new SizeValidator(entrypoint, new Future.value(size));
1818
}
1919

20+
expectSizeValidationError(Matcher matcher) {
21+
expect(validatePackage(size(100 * math.pow(2, 20) + 1)),
22+
completion(pairOf(contains(matcher), anything)));
23+
}
24+
2025
main() {
21-
setUp(d.validPackage.create);
26+
test('considers a package valid if it is <= 100 MB', () async {
27+
await d.validPackage.create();
2228

23-
test('considers a package valid if it is <= 100 MB', () {
2429
expectNoValidationError(size(100));
2530
expectNoValidationError(size(100 * math.pow(2, 20)));
2631
});
2732

28-
test('considers a package invalid if it is more than 100 MB', () {
29-
expectValidationError(size(100 * math.pow(2, 20) + 1));
33+
group('considers a package invalid if it is more than 100 MB', () {
34+
test('package is not under source control and no .gitignore exists',
35+
() async {
36+
await d.validPackage.create();
37+
38+
expectSizeValidationError(
39+
equals("Your package is 100.0 MB. Hosted packages must "
40+
"be smaller than 100 MB."));
41+
});
42+
43+
test('package is not under source control and .gitignore exists', () async {
44+
await d.validPackage.create();
45+
await d.dir(appPath, [d.file('.gitignore', 'ignored')]).create();
46+
47+
expectSizeValidationError(allOf(
48+
contains("Hosted packages must be smaller than 100 MB."),
49+
contains("Your .gitignore has no effect since your project "
50+
"does not appear to be in version control.")));
51+
});
52+
53+
test('package is under source control and no .gitignore exists', () async {
54+
await d.validPackage.create();
55+
await d.git(appPath).create();
56+
57+
expectSizeValidationError(allOf(
58+
contains("Hosted packages must be smaller than 100 MB."),
59+
contains("Consider adding a .gitignore to avoid including "
60+
"temporary files.")));
61+
});
62+
63+
test('package is under source control and .gitignore exists', () async {
64+
await d.validPackage.create();
65+
await d.git(appPath, [d.file('.gitignore', 'ignored')]).create();
66+
67+
expectSizeValidationError(
68+
equals("Your package is 100.0 MB. Hosted packages must "
69+
"be smaller than 100 MB."));
70+
});
3071
});
3172
}

0 commit comments

Comments
 (0)