Chromium Code Reviews| 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(rnystrom): Git packages could in theory be cached, but that adds a | 11 // TODO(rnystrom): Git packages could in theory be cached, but that adds a |
| 12 // lot of complexity. When you install a git package, you are installing | 12 // lot of complexity. When you install a git package, you are installing |
| 13 // and pinning to a specific commit. That means different installs of the | 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 | 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. | 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. | 16 // For now, we are punting and simply not caching them. |
| 17 final bool shouldCache = false; | 17 final bool shouldCache = false; |
| 18 | 18 |
| 19 GitSource(); | 19 GitSource(); |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * Clones a Git repo to the local filesystem. | 22 * Clones a Git repo to the local filesystem. |
| 23 */ | 23 */ |
| 24 Future<bool> install(PackageId id, String destPath) { | 24 Future<bool> install(PackageId id, String destPath) { |
| 25 return runProcess("git", ["clone", "--progress", id.description, destPath], | 25 return isGitInstalled.chain((installed) { |
| 26 pipeStdout: true, pipeStderr: true). | 26 if (installed) { |
| 27 transform((result) => result.success); | 27 return runProcess("git", ["clone", "--progress", id.description, destPat h], |
|
nweiz
2012/05/23 00:46:26
Line length
Bob Nystrom
2012/05/23 16:32:33
Done.
| |
| 28 pipeStdout: true, pipeStderr: true). | |
| 29 transform((result) => result.success); | |
| 30 } else { | |
| 31 throw new Exception( | |
| 32 "Cannot install '${id.name}' from Git (${id.description}).\n" | |
| 33 "Please ensure Git is correctly installed."); | |
| 34 } | |
| 35 }); | |
| 28 } | 36 } |
| 29 | 37 |
| 30 /** | 38 /** |
| 31 * The package name of a Git repo is the name of the directory into which | 39 * The package name of a Git repo is the name of the directory into which |
| 32 * it'll be cloned. | 40 * it'll be cloned. |
| 33 */ | 41 */ |
| 34 String packageName(PackageId id) => | 42 String packageName(PackageId id) => |
| 35 basename(id.description).replaceFirst(const RegExp("\.git\$"), ""); | 43 basename(id.description).replaceFirst(const RegExp("\.git\$"), ""); |
| 36 | 44 |
| 37 /** | 45 /** |
| 38 * Ensures [description] is a Git URL. | 46 * Ensures [description] is a Git URL. |
| 39 */ | 47 */ |
| 40 void validateDescription(description) { | 48 void validateDescription(description) { |
| 41 if (description is! String) { | 49 if (description is! String) { |
| 42 throw new FormatException("The description must be a git URL."); | 50 throw new FormatException("The description must be a git URL."); |
| 43 } | 51 } |
| 44 } | 52 } |
| 45 } | 53 } |
| OLD | NEW |