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 'log.dart' as log; |
11 import 'utils.dart'; | 12 import 'utils.dart'; |
12 | 13 |
13 /// Tests whether or not the git command-line app is available for use. | 14 /// Tests whether or not the git command-line app is available for use. |
14 Future<bool> get isInstalled { | 15 Future<bool> get isInstalled { |
15 if (_isGitInstalledCache != null) { | 16 if (_isGitInstalledCache != null) { |
16 // TODO(rnystrom): The sleep is to pump the message queue. Can use | 17 // TODO(rnystrom): The sleep is to pump the message queue. Can use |
17 // Future.immediate() when #3356 is fixed. | 18 // Future.immediate() when #3356 is fixed. |
18 return sleep(0).transform((_) => _isGitInstalledCache); | 19 return sleep(0).transform((_) => _isGitInstalledCache); |
19 } | 20 } |
20 | 21 |
(...skipping 29 matching lines...) Expand all Loading... |
50 | 51 |
51 return _tryGitCommand("git").chain((success) { | 52 return _tryGitCommand("git").chain((success) { |
52 if (success) return new Future.immediate("git"); | 53 if (success) return new Future.immediate("git"); |
53 | 54 |
54 // Git is sometimes installed on Windows as `git.cmd` | 55 // Git is sometimes installed on Windows as `git.cmd` |
55 return _tryGitCommand("git.cmd").transform((success) { | 56 return _tryGitCommand("git.cmd").transform((success) { |
56 if (success) return "git.cmd"; | 57 if (success) return "git.cmd"; |
57 return null; | 58 return null; |
58 }); | 59 }); |
59 }).transform((command) { | 60 }).transform((command) { |
| 61 log.fine('Determined git command $command.'); |
60 _gitCommandCache = command; | 62 _gitCommandCache = command; |
61 return command; | 63 return command; |
62 }); | 64 }); |
63 } | 65 } |
64 | 66 |
65 /// Checks whether [command] is the Git command for this computer. | 67 /// Checks whether [command] is the Git command for this computer. |
66 Future<bool> _tryGitCommand(String command) { | 68 Future<bool> _tryGitCommand(String command) { |
67 var completer = new Completer<bool>(); | 69 var completer = new Completer<bool>(); |
68 | 70 |
69 // If "git --version" prints something familiar, git is working. | 71 // If "git --version" prints something familiar, git is working. |
70 var future = runProcess(command, ["--version"]); | 72 var future = runProcess(command, ["--version"]); |
71 | 73 |
72 future.then((results) { | 74 future.then((results) { |
73 var regex = new RegExp("^git version"); | 75 var regex = new RegExp("^git version"); |
74 completer.complete(results.stdout.length == 1 && | 76 completer.complete(results.stdout.length == 1 && |
75 regex.hasMatch(results.stdout[0])); | 77 regex.hasMatch(results.stdout[0])); |
76 }); | 78 }); |
77 | 79 |
78 future.handleException((err) { | 80 future.handleException((err) { |
79 // If the process failed, they probably don't have it. | 81 // If the process failed, they probably don't have it. |
80 completer.complete(false); | 82 completer.complete(false); |
81 return true; | 83 return true; |
82 }); | 84 }); |
83 | 85 |
84 return completer.future; | 86 return completer.future; |
85 } | 87 } |
OLD | NEW |