Skip to content

Commit 4b76d74

Browse files
committed
Properly handle Git URLs with trailing slashes.
BUG=3493 Review URL: https://chromiumcodereview.appspot.com//10875056 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@11343 260f80e4-7a28-3924-810f-c04153c831b5
1 parent 36575ab commit 4b76d74

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

utils/pub/git_source.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ class GitSource extends Source {
6464
* The package name of a Git repo is the name of the directory into which
6565
* it'll be cloned.
6666
*/
67-
String packageName(description) =>
68-
basename(_getUrl(description)).replaceFirst(const RegExp("\.git\$"), "");
67+
String packageName(description) {
68+
return basename(_getUrl(description)
69+
.replaceFirst(const RegExp(@"(\.git)?/?$"), ""));
70+
}
6971

7072
/**
7173
* Ensures [description] is a Git URL.

utils/pub/pubspec.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ class Pubspec {
110110

111111
source.validateDescription(description, fromLockFile: false);
112112

113+
var nameFromSource = source.packageName(description);
114+
if (nameFromSource != name) {
115+
throw new FormatException('The name you specified for your '
116+
'dependency, "$name", doesn\'t match the name "$nameFromSource" '
117+
'(from "$description").');
118+
}
119+
113120
dependencies.add(new PackageRef(
114121
source, versionConstraint, description));
115122
});

utils/tests/pub/pub_install_git_test.dart

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,32 @@ main() {
7878
run();
7979
});
8080

81+
test('requires the repository name to match the name in the pubspec', () {
82+
ensureGit();
83+
84+
git('foo.git', [
85+
file('foo.dart', 'main() => "foo";')
86+
]).scheduleCreate();
87+
88+
dir(appPath, [
89+
pubspec({
90+
"name": "myapp",
91+
"dependencies": {
92+
"weird-name": {"git": "../foo.git"}
93+
}
94+
})
95+
]).scheduleCreate();
96+
97+
// TODO(nweiz): clean up this RegExp when either issue 4706 or 4707 is
98+
// fixed.
99+
schedulePub(args: ['install'],
100+
error: const RegExp(@'^FormatException: The name you specified for '
101+
@'your dependency, "weird-name", doesn' @"'" @'t match the name '
102+
@'"foo" \(from "\.\./foo\.git"\)\.'));
103+
104+
run();
105+
});
106+
81107
test('checks out and updates a package from Git', () {
82108
ensureGit();
83109

@@ -310,4 +336,34 @@ main() {
310336

311337
run();
312338
});
339+
340+
group("(regression)", () {
341+
test('checks out a package from Git with a trailing slash', () {
342+
ensureGit();
343+
344+
git('foo.git', [
345+
file('foo.dart', 'main() => "foo";')
346+
]).scheduleCreate();
347+
348+
appDir([{"git": "../foo.git/"}]).scheduleCreate();
349+
350+
schedulePub(args: ['install'],
351+
output: const RegExp(@"Dependencies installed!$"));
352+
353+
dir(cachePath, [
354+
dir('git', [
355+
dir('cache', [gitPackageCacheDir('foo')]),
356+
gitPackageCacheDir('foo')
357+
])
358+
]).scheduleValidate();
359+
360+
dir(packagesPath, [
361+
dir('foo', [
362+
file('foo.dart', 'main() => "foo";')
363+
])
364+
]).scheduleValidate();
365+
366+
run();
367+
});
368+
});
313369
}

0 commit comments

Comments
 (0)