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 /// Helper functionality for invoking Git. | 5 /// Helper functionality for invoking Git. |
6 library git; | 6 library git; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'io.dart'; | 9 import 'io.dart'; |
10 import 'log.dart' as log; | 10 import 'log.dart' as log; |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 /// Run a git process with [args] from [workingDir]. Returns the stdout as a | 22 /// Run a git process with [args] from [workingDir]. Returns the stdout as a |
23 /// list of strings if it succeeded. Completes to an exception if it failed. | 23 /// list of strings if it succeeded. Completes to an exception if it failed. |
24 Future<List<String>> run(List<String> args, | 24 Future<List<String>> run(List<String> args, |
25 {String workingDir, Map<String, String> environment}) { | 25 {String workingDir, Map<String, String> environment}) { |
26 return _gitCommand.then((git) { | 26 return _gitCommand.then((git) { |
27 return runProcess(git, args, workingDir: workingDir, | 27 return runProcess(git, args, workingDir: workingDir, |
28 environment: environment); | 28 environment: environment); |
29 }).then((result) { | 29 }).then((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 ${args.join(" ")}\n' |
32 '${Strings.join(result.stderr, "\n")}'); | 32 '${result.stderr.join("\n")}'); |
33 | 33 |
34 return result.stdout; | 34 return result.stdout; |
35 }); | 35 }); |
36 } | 36 } |
37 | 37 |
38 bool _isGitInstalledCache; | 38 bool _isGitInstalledCache; |
39 | 39 |
40 /// The cached Git command. | 40 /// The cached Git command. |
41 String _gitCommandCache; | 41 String _gitCommandCache; |
42 | 42 |
(...skipping 23 matching lines...) Expand all Loading... |
66 Future<bool> _tryGitCommand(String command) { | 66 Future<bool> _tryGitCommand(String command) { |
67 // If "git --version" prints something familiar, git is working. | 67 // If "git --version" prints something familiar, git is working. |
68 return runProcess(command, ["--version"]).then((results) { | 68 return runProcess(command, ["--version"]).then((results) { |
69 var regexp = new RegExp("^git version"); | 69 var regexp = new RegExp("^git version"); |
70 return results.stdout.length == 1 && regexp.hasMatch(results.stdout[0]); | 70 return results.stdout.length == 1 && regexp.hasMatch(results.stdout[0]); |
71 }).catchError((err) { | 71 }).catchError((err) { |
72 // If the process failed, they probably don't have it. | 72 // If the process failed, they probably don't have it. |
73 return false; | 73 return false; |
74 }); | 74 }); |
75 } | 75 } |
OLD | NEW |