| 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 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 _isInstalledCache = command != null; | 35 _isInstalledCache = command != null; |
| 36 return _isInstalledCache; | 36 return _isInstalledCache; |
| 37 } | 37 } |
| 38 bool _isInstalledCache; | 38 bool _isInstalledCache; |
| 39 | 39 |
| 40 /// Run a git process with [args] from [workingDir]. | 40 /// Run a git process with [args] from [workingDir]. |
| 41 /// | 41 /// |
| 42 /// Returns the stdout as a list of strings if it succeeded. Completes to an | 42 /// Returns the stdout as a list of strings if it succeeded. Completes to an |
| 43 /// exception if it failed. | 43 /// exception if it failed. |
| 44 Future<List<String>> run(List<String> args, | 44 Future<List<String>> run(List<String> args, |
| 45 {String workingDir, Map<String, String> environment}) { | 45 {String workingDir, Map<String, String> environment}) async { |
| 46 if (!isInstalled) { | 46 if (!isInstalled) { |
| 47 fail("Cannot find a Git executable.\n" | 47 fail("Cannot find a Git executable.\n" |
| 48 "Please ensure Git is correctly installed."); | 48 "Please ensure Git is correctly installed."); |
| 49 } | 49 } |
| 50 | 50 |
| 51 log.muteProgress(); | 51 log.muteProgress(); |
| 52 return runProcess(command, args, workingDir: workingDir, | 52 try { |
| 53 environment: environment).then((result) { | 53 var result = await runProcess(command, args, workingDir: workingDir, |
| 54 environment: environment); |
| 54 if (!result.success) throw new GitException(args, result.stderr.join("\n")); | 55 if (!result.success) throw new GitException(args, result.stderr.join("\n")); |
| 55 | |
| 56 return result.stdout; | 56 return result.stdout; |
| 57 }).whenComplete(() { | 57 } finally { |
| 58 log.unmuteProgress(); | 58 log.unmuteProgress(); |
| 59 }); | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 /// Like [run], but synchronous. | 62 /// Like [run], but synchronous. |
| 63 List<String> runSync(List<String> args, {String workingDir, | 63 List<String> runSync(List<String> args, {String workingDir, |
| 64 Map<String, String> environment}) { | 64 Map<String, String> environment}) { |
| 65 if (!isInstalled) { | 65 if (!isInstalled) { |
| 66 fail("Cannot find a Git executable.\n" | 66 fail("Cannot find a Git executable.\n" |
| 67 "Please ensure Git is correctly installed."); | 67 "Please ensure Git is correctly installed."); |
| 68 } | 68 } |
| 69 | 69 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 var result = runProcessSync(command, ["--version"]); | 112 var result = runProcessSync(command, ["--version"]); |
| 113 var regexp = new RegExp("^git version"); | 113 var regexp = new RegExp("^git version"); |
| 114 return result.stdout.length == 1 && regexp.hasMatch(result.stdout.single); | 114 return result.stdout.length == 1 && regexp.hasMatch(result.stdout.single); |
| 115 } on ProcessException catch (error, stackTrace) { | 115 } on ProcessException catch (error, stackTrace) { |
| 116 var chain = new Chain.forTrace(stackTrace); | 116 var chain = new Chain.forTrace(stackTrace); |
| 117 // If the process failed, they probably don't have it. | 117 // If the process failed, they probably don't have it. |
| 118 log.error('Git command is not "$command": $error\n$chain'); | 118 log.error('Git command is not "$command": $error\n$chain'); |
| 119 return false; | 119 return false; |
| 120 } | 120 } |
| 121 } | 121 } |
| OLD | NEW |