| 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 * Helper functionality for invoking Git. | 6 * Helper functionality for invoking Git. |
| 7 */ | 7 */ |
| 8 library git; | 8 library git; |
| 9 | 9 |
| 10 import 'io.dart'; | 10 import 'io.dart'; |
| 11 import 'utils.dart'; | 11 import 'utils.dart'; |
| 12 | 12 |
| 13 /// Tests whether or not the git command-line app is available for use. | 13 /// Tests whether or not the git command-line app is available for use. |
| 14 Future<bool> get isInstalled { | 14 Future<bool> get isInstalled { |
| 15 if (_isGitInstalledCache != null) { | 15 if (_isGitInstalledCache != null) { |
| 16 // TODO(rnystrom): The sleep is to pump the message queue. Can use | 16 // TODO(rnystrom): The sleep is to pump the message queue. Can use |
| 17 // Future.immediate() when #3356 is fixed. | 17 // Future.immediate() when #3356 is fixed. |
| 18 return sleep(0).transform((_) => _isGitInstalledCache); | 18 return sleep(0).transform((_) => _isGitInstalledCache); |
| 19 } | 19 } |
| 20 | 20 |
| 21 return _gitCommand.transform((git) => git != null); | 21 return _gitCommand.transform((git) => git != null); |
| 22 } | 22 } |
| 23 | 23 |
| 24 /// Run a git process with [args] from [workingDir]. Returns the stdout as a | 24 /// Run a git process with [args] from [workingDir]. Returns the stdout as a |
| 25 /// list of strings if it succeeded. Completes to an exception if it failed. | 25 /// list of strings if it succeeded. Completes to an exception if it failed. |
| 26 Future<List<String>> run(List<String> args, [String workingDir]) { | 26 Future<List<String>> run(List<String> args, {String workingDir}) { |
| 27 return _gitCommand.chain((git) { | 27 return _gitCommand.chain((git) { |
| 28 return runProcess(git, args, workingDir: workingDir); | 28 return runProcess(git, args, workingDir: workingDir); |
| 29 }).transform((result) { | 29 }).transform((result) { |
| 30 if (!result.success) throw new Exception( | 30 if (!result.success) throw new Exception( |
| 31 'Git error. Command: git ${Strings.join(args, " ")}\n' | 31 'Git error. Command: git ${Strings.join(args, " ")}\n' |
| 32 '${Strings.join(result.stderr, "\n")}'); | 32 '${Strings.join(result.stderr, "\n")}'); |
| 33 | 33 |
| 34 return result.stdout; | 34 return result.stdout; |
| 35 }); | 35 }); |
| 36 } | 36 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 }); | 76 }); |
| 77 | 77 |
| 78 future.handleException((err) { | 78 future.handleException((err) { |
| 79 // If the process failed, they probably don't have it. | 79 // If the process failed, they probably don't have it. |
| 80 completer.complete(false); | 80 completer.complete(false); |
| 81 return true; | 81 return true; |
| 82 }); | 82 }); |
| 83 | 83 |
| 84 return completer.future; | 84 return completer.future; |
| 85 } | 85 } |
| OLD | NEW |