| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * A package source that installs packages from Git repos. | 6 * A package source that installs packages from Git repos. |
| 7 */ | 7 */ |
| 8 class GitSource extends Source { | 8 class GitSource extends Source { |
| 9 final String name = "git"; | 9 final String name = "git"; |
| 10 | 10 |
| 11 // TODO(nweiz): this should be cached since it uses the network, but until we | 11 // TODO(rnystrom): Git packages could in theory be cached, but that adds a |
| 12 // support versions there's no good way to distinguish between different | 12 // lot of complexity. When you install a git package, you are installing |
| 13 // checkouts of the same repository. | 13 // and pinning to a specific commit. That means different installs of the |
| 14 // same git path but at different commits need to be disambiguated in the |
| 15 // system cache. It may also lead to a lot of garbage in the system cache. |
| 16 // For now, we are punting and simply not caching them. |
| 14 final bool shouldCache = false; | 17 final bool shouldCache = false; |
| 15 | 18 |
| 16 GitSource(); | 19 GitSource(); |
| 17 | 20 |
| 18 /** | 21 /** |
| 19 * Clones a Git repo to the local filesystem. | 22 * Clones a Git repo to the local filesystem. |
| 20 */ | 23 */ |
| 21 Future<bool> install(PackageId id, String destPath) { | 24 Future<bool> install(PackageId id, String destPath) { |
| 22 return runProcess("git", ["clone", "--progress", id.fullName, destPath], | 25 return runProcess("git", ["clone", "--progress", id.description, destPath], |
| 23 pipeStdout: true, pipeStderr: true). | 26 pipeStdout: true, pipeStderr: true). |
| 24 transform((result) => result.success); | 27 transform((result) => result.success); |
| 25 } | 28 } |
| 26 | 29 |
| 27 /** | 30 /** |
| 28 * The package name of a Git repo is the name of the directory into which | 31 * The package name of a Git repo is the name of the directory into which |
| 29 * it'll be cloned. | 32 * it'll be cloned. |
| 30 */ | 33 */ |
| 31 String packageName(PackageId id) => | 34 String packageName(PackageId id) => |
| 32 basename(id.fullName).replaceFirst(const RegExp("\.git\$"), ""); | 35 basename(id.description).replaceFirst(const RegExp("\.git\$"), ""); |
| 36 |
| 37 /** |
| 38 * Ensures [description] is a Git URL. |
| 39 */ |
| 40 void validateDescription(description) { |
| 41 if (description is! String) { |
| 42 throw new FormatException("The description must be a git URL."); |
| 43 } |
| 44 } |
| 33 } | 45 } |
| OLD | NEW |