Skip to content

Commit f2d6ceb

Browse files
committed
app: fix bug in oldname warning on Windows
Fix a bug in the old-name warning detection that only presents on Windows when bundled with Git for Windows, and when configured using the shorthand config `credential.helper=manager-core`. In this scenario, our argv[0] is missing the ".exe" extension (that's actually present in the file name of course) because ... mingw reasons. Instead of matching "git-credential-manager-core.exe" on Windows, just strip ".exe" if present on Windows, and always match "git-credential-manager-core" on all platforms.
1 parent 7ba0258 commit f2d6ceb

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

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)