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