| 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", |
| 28 ["clone", "--progress", id.description, destPath], |
| 29 pipeStdout: true, pipeStderr: true). |
| 30 transform((result) => result.success); |
| 31 } else { |
| 32 throw new Exception( |
| 33 "Cannot install '${id.name}' from Git (${id.description}).\n" |
| 34 "Please ensure Git is correctly installed."); |
| 35 } |
| 36 }); |
| 28 } | 37 } |
| 29 | 38 |
| 30 /** | 39 /** |
| 31 * The package name of a Git repo is the name of the directory into which | 40 * The package name of a Git repo is the name of the directory into which |
| 32 * it'll be cloned. | 41 * it'll be cloned. |
| 33 */ | 42 */ |
| 34 String packageName(PackageId id) => | 43 String packageName(PackageId id) => |
| 35 basename(id.description).replaceFirst(const RegExp("\.git\$"), ""); | 44 basename(id.description).replaceFirst(const RegExp("\.git\$"), ""); |
| 36 | 45 |
| 37 /** | 46 /** |
| 38 * Ensures [description] is a Git URL. | 47 * Ensures [description] is a Git URL. |
| 39 */ | 48 */ |
| 40 void validateDescription(description) { | 49 void validateDescription(description) { |
| 41 if (description is! String) { | 50 if (description is! String) { |
| 42 throw new FormatException("The description must be a git URL."); | 51 throw new FormatException("The description must be a git URL."); |
| 43 } | 52 } |
| 44 } | 53 } |
| 45 } | 54 } |
| OLD | NEW |