Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(962)

Unified Diff: utils/pub/io.dart

Issue 10421026: Make pub handle missing git more gracefully. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: utils/pub/io.dart
diff --git a/utils/pub/io.dart b/utils/pub/io.dart
index 22982b049e354dec3b22f445bef2a47b5f76dd58..3a94965df92282b585aa8a1d5225e8d1871f1ad0 100644
--- a/utils/pub/io.dart
+++ b/utils/pub/io.dart
@@ -13,6 +13,14 @@
String get workingDir() => new File('.').fullPathSync();
/**
+ * Prints the given string to `stderr` on its own line.
+ */
+void printError(value) {
+ stderr.writeString(value.toString());
+ stderr.writeString('\n');
+}
+
+/**
* Joins a number of path string parts into a single path. Handles
* platform-specific path separators. Parts can be [String], [Directory], or
* [File] objects.
@@ -319,6 +327,36 @@ Future<PubProcessResult> runProcess(String executable, List<String> args,
}
/**
+ * Tests whether or not the git command-line app is available for use.
+ */
+Future<bool> get isGitInstalled() {
+ // TODO(rnystrom): We could cache this after the first check. We aren't right
+ // now because Future.immediate() will invoke its callback synchronously.
+ // That does bad things in cases where the caller expects futures to always
+ // be async. In particular, withGit() in the pub tests which calls
+ // expectAsync() will fail horribly if the test isn't actually async.
+
+ var completer = new Completer<bool>();
+
+ // If "git --version" prints something familiar, git is working.
+ var future = runProcess("git", ["--version"]);
+
+ future.then((results) {
+ var regex = new RegExp("^git version");
+ completer.complete(results.stdout.length == 1 &&
+ regex.hasMatch(results.stdout[0]));
+ });
+
+ future.handleException((err) {
+ // If the process failed, they probably don't have it.
+ completer.complete(false);
+ return true;
+ });
+
+ return completer.future;
+}
+
+/**
* Contains the results of invoking a [Process] and waiting for it to complete.
*/
class PubProcessResult {

Powered by Google App Engine
This is Rietveld 408576698