Index: utils/pub/git.dart |
diff --git a/utils/pub/git.dart b/utils/pub/git.dart |
index b216735f64c94d1dc78800ff46e253b7e956a14d..df2e8565c3a2fc8ea8d77c20b4c2012498bad3d0 100644 |
--- a/utils/pub/git.dart |
+++ b/utils/pub/git.dart |
@@ -5,6 +5,7 @@ |
/// Helper functionality for invoking Git. |
library git; |
+import 'dart:async'; |
import 'io.dart'; |
import 'log.dart' as log; |
import 'utils.dart'; |
@@ -14,18 +15,18 @@ Future<bool> get isInstalled { |
if (_isGitInstalledCache != null) { |
// TODO(rnystrom): The sleep is to pump the message queue. Can use |
// Future.immediate() when #3356 is fixed. |
- return sleep(0).transform((_) => _isGitInstalledCache); |
+ return sleep(0).then((_) => _isGitInstalledCache); |
} |
- return _gitCommand.transform((git) => git != null); |
+ return _gitCommand.then((git) => git != null); |
} |
/// Run a git process with [args] from [workingDir]. Returns the stdout as a |
/// list of strings if it succeeded. Completes to an exception if it failed. |
Future<List<String>> run(List<String> args, {String workingDir}) { |
- return _gitCommand.chain((git) { |
+ return _gitCommand.then((git) { |
return runProcess(git, args, workingDir: workingDir); |
- }).transform((result) { |
+ }).then((result) { |
if (!result.success) throw new Exception( |
'Git error. Command: git ${Strings.join(args, " ")}\n' |
'${Strings.join(result.stderr, "\n")}'); |
@@ -44,18 +45,18 @@ String _gitCommandCache; |
Future<String> get _gitCommand { |
// TODO(nweiz): Just use Future.immediate once issue 3356 is fixed. |
if (_gitCommandCache != null) { |
- return sleep(0).transform((_) => _gitCommandCache); |
+ return sleep(0).then((_) => _gitCommandCache); |
} |
- return _tryGitCommand("git").chain((success) { |
+ return _tryGitCommand("git").then((success) { |
if (success) return new Future.immediate("git"); |
// Git is sometimes installed on Windows as `git.cmd` |
- return _tryGitCommand("git.cmd").transform((success) { |
+ return _tryGitCommand("git.cmd").then((success) { |
if (success) return "git.cmd"; |
return null; |
}); |
- }).transform((command) { |
+ }).then((command) { |
log.fine('Determined git command $command.'); |
_gitCommandCache = command; |
return command; |
@@ -69,17 +70,16 @@ Future<bool> _tryGitCommand(String command) { |
// If "git --version" prints something familiar, git is working. |
var future = runProcess(command, ["--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; |
- }); |
+ future |
+ .then((results) { |
+ var regex = new RegExp("^git version"); |
+ completer.complete(results.stdout.length == 1 && |
+ regex.hasMatch(results.stdout[0])); |
+ }) |
+ .catchError((err) { |
+ // If the process failed, they probably don't have it. |
+ completer.complete(false); |
+ }); |
return completer.future; |
} |