Skip to content

Commit 79087fd

Browse files
author
Matthew John Cheetham
authored
Fix various problems with install path and app path variables (#968)
2 parents 3795b52 + b848716 commit 79087fd

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

src/shared/Core/ApplicationBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static string GetEntryApplicationPath()
9191

9292
public static string GetInstallationDirectory()
9393
{
94-
return Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);
94+
return AppContext.BaseDirectory;
9595
}
9696

9797
/// <summary>

src/shared/Core/Authentication/AuthenticationBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ protected bool TryFindHelperCommand(string envar, string configName, string defa
140140

141141
Context.Trace.WriteLine($"UI helper override specified: '{helperName}'.");
142142
}
143+
else if (string.IsNullOrWhiteSpace(defaultValue))
144+
{
145+
Context.Trace.WriteLine("No default UI supplied.");
146+
return false;
147+
}
143148
else
144149
{
145150
Context.Trace.WriteLine($"Using default UI helper: '{defaultValue}'.");

src/shared/Core/Interop/Windows/WindowsEnvironment.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ internal WindowsEnvironment(IFileSystem fileSystem, IReadOnlyDictionary<string,
2222

2323
protected override string[] SplitPathVariable(string value)
2424
{
25-
return value.Split(';');
25+
// Ensure we don't return empty values here - callers may use this as the base
26+
// path for `Path.Combine(..)`, for which an empty value means 'current directory'.
27+
// We only ever want to use the current directory for path resolution explicitly.
28+
return value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
2629
}
2730

2831
public override void AddDirectoryToPath(string directoryPath, EnvironmentVariableTarget target)

src/shared/Core/PlatformUtils.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,11 @@ private static string GetWindowsEntryPath()
289289
IntPtr argv0Ptr = Marshal.ReadIntPtr(argvPtr);
290290
string argv0 = Marshal.PtrToStringAuto(argv0Ptr);
291291
Interop.Windows.Native.Kernel32.LocalFree(argvPtr);
292-
return argv0;
292+
293+
// If this isn't absolute then we should return null to prevent any
294+
// caller that expect only an absolute path from mis-using this result.
295+
// They will have to fall-back to other mechanisms for getting the entry path.
296+
return Path.IsPathRooted(argv0) ? argv0 : null;
293297
}
294298

295299
#endregion

src/shared/Git-Credential-Manager/Program.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,24 @@ public static void Main(string[] args)
4343
//
4444
// On UNIX systems we do the same check, except instead of a copy we use a symlink.
4545
//
46-
string oldName = PlatformUtils.IsWindows()
47-
? "git-credential-manager-core.exe"
48-
: "git-credential-manager-core";
4946

50-
if (appPath?.EndsWith(oldName, StringComparison.OrdinalIgnoreCase) ?? false)
47+
if (!string.IsNullOrWhiteSpace(appPath))
5148
{
52-
context.Streams.Error.WriteLine(
53-
"warning: git-credential-manager-core was renamed to git-credential-manager");
54-
context.Streams.Error.WriteLine(
55-
$"warning: see {Constants.HelpUrls.GcmExecRename} for more information");
49+
// Trim any (.exe) file extension if we're on Windows
50+
// Note that in some circumstances (like being called by Git when config is set
51+
// to just `helper = manager-core`) we don't always have ".exe" at the end.
52+
if (PlatformUtils.IsWindows() && appPath.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
53+
{
54+
appPath = appPath.Substring(0, appPath.Length - 4);
55+
}
56+
57+
if (appPath.EndsWith("git-credential-manager-core", StringComparison.OrdinalIgnoreCase))
58+
{
59+
context.Streams.Error.WriteLine(
60+
"warning: git-credential-manager-core was renamed to git-credential-manager");
61+
context.Streams.Error.WriteLine(
62+
$"warning: see {Constants.HelpUrls.GcmExecRename} for more information");
63+
}
5664
}
5765

5866
// Register all supported host providers at the normal priority.

0 commit comments

Comments
 (0)