Index: utils/pub/io.dart |
diff --git a/utils/pub/io.dart b/utils/pub/io.dart |
index 25e8d7fde85e7ef7c6236afdce4a0666bda86360..8604650a88c0b1a816c73b89968920babb2e8190 100644 |
--- a/utils/pub/io.dart |
+++ b/utils/pub/io.dart |
@@ -10,6 +10,7 @@ |
#import('dart:io'); |
#import('dart:isolate'); |
#import('dart:uri'); |
+#import('utils.dart'); |
/** Gets the current working directory. */ |
String get workingDir => new File('.').fullPathSync(); |
@@ -473,20 +474,35 @@ Future timeout(Future input, int milliSeconds, String message) { |
return completer.future; |
} |
-/** |
- * 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. |
+/// The cached Git command. |
+String _gitCommand; |
+ |
+/// Tests whether or not the git command-line app is available for use. |
+Future<bool> get isGitInstalled => gitCommand.transform((git) => git != null); |
+ |
+/// Returns the name of the git command-line app, or null if Git could not be |
+/// found on the user's PATH. |
+Future<String> get gitCommand { |
Bob Nystrom
2012/09/11 16:18:55
I would unify this with _runGit and just have a si
nweiz
2012/09/11 19:25:11
Done.
|
+ // TODO(nweiz): Just use Future.immediate once issue 3356 is fixed. |
+ if (_gitCommand != null) return sleep(0).transform((_) => _gitCommand); |
+ |
+ return _tryGitCommand("git").chain((success) { |
+ if (success) return new Future.immediate("git"); |
+ |
+ // Git is sometimes installed on Windows as `git.cmd` |
+ return _tryGitCommand("git.cmd").transform((success) { |
+ if (success) return "git.cmd"; |
+ return null; |
+ }); |
+ }); |
+} |
+/// Checks whether [command] is the Git command for this computer. |
+Future<bool> _tryGitCommand(String command) { |
var completer = new Completer<bool>(); |
// If "git --version" prints something familiar, git is working. |
- var future = runProcess("git", ["--version"]); |
+ var future = runProcess(command, ["--version"]); |
future.then((results) { |
var regex = new RegExp("^git version"); |