|
3 | 3 | using System;
|
4 | 4 | using System.Collections.Generic;
|
5 | 5 | using System.Diagnostics;
|
| 6 | +using System.IO; |
| 7 | +using System.Reflection; |
6 | 8 | using System.Threading.Tasks;
|
7 | 9 |
|
8 | 10 | namespace Microsoft.Git.CredentialManager.Authentication
|
@@ -86,5 +88,47 @@ protected void ThrowIfTerminalPromptsDisabled()
|
86 | 88 | throw new InvalidOperationException("Cannot prompt because terminal prompts have been disabled.");
|
87 | 89 | }
|
88 | 90 | }
|
| 91 | + |
| 92 | + protected bool TryFindHelperExecutablePath(string envar, string configName, string defaultValue, out string path) |
| 93 | + { |
| 94 | + bool isOverride = false; |
| 95 | + if (Context.Settings.TryGetSetting( |
| 96 | + envar, Constants.GitConfiguration.Credential.SectionName, configName, out string helperName)) |
| 97 | + { |
| 98 | + Context.Trace.WriteLine($"UI helper override specified: '{helperName}'."); |
| 99 | + isOverride = true; |
| 100 | + } |
| 101 | + else |
| 102 | + { |
| 103 | + // Use the default helper if none was specified. |
| 104 | + // On Windows append ".exe" for the default helpers only. If a user has specified their own |
| 105 | + // helper they should append the correct extension. |
| 106 | + helperName = PlatformUtils.IsWindows() ? $"{defaultValue}.exe" : defaultValue; |
| 107 | + } |
| 108 | + |
| 109 | + if (Path.IsPathRooted(helperName)) |
| 110 | + { |
| 111 | + path = helperName; |
| 112 | + } |
| 113 | + else |
| 114 | + { |
| 115 | + string executableDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); |
| 116 | + path = Path.Combine(executableDirectory!, helperName); |
| 117 | + } |
| 118 | + |
| 119 | + if (!Context.FileSystem.FileExists(path)) |
| 120 | + { |
| 121 | + // Only warn for missing helpers specified by the user, not in-box ones |
| 122 | + if (isOverride) |
| 123 | + { |
| 124 | + Context.Trace.WriteLine($"UI helper '{helperName}' was not found at '{path}'."); |
| 125 | + Context.Streams.Error.WriteLine($"warning: could not find configured UI helper '{helperName}'"); |
| 126 | + } |
| 127 | + |
| 128 | + return false; |
| 129 | + } |
| 130 | + |
| 131 | + return true; |
| 132 | + } |
89 | 133 | }
|
90 | 134 | }
|
0 commit comments