Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename entry executable to drop "-core" suffix #551

Merged
merged 3 commits into from
Oct 24, 2022

Conversation

mjcheetham
Copy link
Collaborator

@mjcheetham mjcheetham commented Nov 23, 2021

UPDATE

Rename the main entry executable from git-credential-manager-core(.exe) to simply git-credential-manager(.exe), now that the older GCM4W has been removed from the Git for Windows project as an option (and the GCMC project has been renamed).

We do not rename the Debian package ID, nor the Homebrew Cask name yet as this will require more thought forr migration.

To help with migration somewhat, create symlinks and shim/copy-executables for the original executable name "git-credential-manager-core(.exe)" for consumers who have not updated to the new version.

We detect if the consumer is launching us via the "-core" symlink or executable shim by consulting the platform-native APIs to get the original "argv[0]". All of the .NET APIs sadly don't give us the real "argv[0]", so we need to use native APIs...

If we detect use of the old name, print a warning that the user should update their configuration, and a help link for more information.

Link to rendered "rename" doc: https://github.com/mjcheetham/git-credential-manager/blob/exec-rename/docs/rename.md

@vtbassmatt
Copy link
Contributor

Is there a deprecation plan for the shims? It seems like a lot of hassle for low rewards if we have to carry those indefinitely. But if we can document their disappearance in, say, a year...

@ldennington
Copy link
Contributor

Do we have a way of knowing when VS takes a new mingit version?

Copy link
Contributor

@ldennington ldennington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exciting times! 🚀

.azure-pipelines/templates/osx/pack.signed/step5-dist.yml Outdated Show resolved Hide resolved
src/linux/Packaging.Linux/shim.sh Outdated Show resolved Hide resolved
src/windows/Installer.Windows/Setup.iss Show resolved Hide resolved
@mjcheetham
Copy link
Collaborator Author

Is there a deprecation plan for the shims? It seems like a lot of hassle for low rewards if we have to carry those indefinitely. But if we can document their disappearance in, say, a year...

That's a good point. I know @dscho was thinking of removing the Windows shim script from Git for Windows "at some future date".

Would you put the "this is temporary" message in the warnings too?

Regarding the rewards; I think this is really most important for Git for Windows users, and those who have installed outside of Homebrew (tarballs, macOS pkg, or Debian deb). Homebrew updates will do an uninstall first of the old one, so keeping clean.

@mjcheetham
Copy link
Collaborator Author

Do we have a way of knowing when VS takes a new mingit version?

Major releases certainly, and sometimes minor releases. It requires a full test pass on their side of things and is an expensive thing to do. They usually also update when we advise them to, for security reasons for example.

Rename the main entry executable from git-credential-manager-core(.exe)
to simply git-credential-manager(.exe), now that the older GCM4W has
been removed from the Git for Windows project as an option (and the GCMC
project has been renamed).

We do not rename the Debian package ID, nor the Homebrew Cask name yet
as this will require more thought for migration.
Copy link
Contributor

@ldennington ldennington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG IT'S HAPPENING! 🍾

Comment on lines +86 to +97
string argv0 = PlatformUtils.GetNativeArgv0()
?? Process.GetCurrentProcess().MainModule?.FileName
?? Environment.GetCommandLineArgs()[0];

if (Path.IsPathRooted(argv0))
{
return Path.ChangeExtension(candidatePath, null);
return argv0;
}

return candidatePath;
#endif
return Path.GetFullPath(
Path.Combine(Environment.CurrentDirectory, argv0)
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice simplification!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's changes like these (avoiding .NET and calling platform native APIs) that makes me wonder where the balance of "help" vs "hinder" .NET is for us... 🤔

Comment on lines +10 to +22
/// <summary>
/// Parses a Unicode command line string and returns an array of pointers
/// to the command line arguments, along with a count of such arguments,
/// in a way that is similar to the standard C run-time argv and argc values.
/// </summary>
/// <param name="lpCmdLine">
/// Pointer to a null-terminated Unicode string that contains the full command line.
/// If this parameter is an empty string the function returns the path to the current executable file.
/// </param>
/// <param name="pNumArgs">
/// Pointer to an int that receives the number of array elements returned, similar to argc.
/// </param>
/// <returns>A pointer to an array of LPWSTR values, similar to argv.</returns>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments are really helpful, thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They came directly from the Windows API docs online 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better 😁

Comment on lines +212 to +213
string cmdline = File.ReadAllText("/proc/self/cmdline");
return cmdline.Split('\0')[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow this is just so easy on Linux lol.

src/shared/Git-Credential-Manager/Program.cs Outdated Show resolved Hide resolved
@mjcheetham mjcheetham force-pushed the exec-rename branch 3 times, most recently from 0e6761a to 644336b Compare October 14, 2022 16:40
![Git Credential Manager Core renamed](img/gcmcore-rename.png)

At the time, the actual exectuable name was not updated and continued to be
`git-credential-manager-core`. As of [VERSION][rename-ver], the executable has
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The VERSION string is a placeholder for when we make the first release and know the version number of GCM.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a reminder alongside my reminder for the next release (all the reminders!) to update this along with the WINGIT_VERSION variable.

### Git for Windows

If you are using GCM bundled with Git for Windows (recommended), you should make
sure you have updated to at least version WINGIT_VERSION.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..similarly, the WINGET_VERISON will be updated once we know the version number of the Git for Windows release that ships GCM with the new name.

Comment on lines +27 to +28
These links will remain until _two_ major Git versions are released after GCM
VERSION, _**at which point the symlinks will no longer be included**_.
Copy link
Collaborator Author

@mjcheetham mjcheetham Oct 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think giving two major Git versions is a good runway. Thoughts? @ldennington @dscho

(By "major" of course I mean y in x.y.z.. not x!)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good clarification! I am fine with this timeline.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

@mjcheetham
Copy link
Collaborator Author

I'm going to wait until @dscho is back for their opinion on this solution before merging. We want to make sure this will be OK with Git for Windows.

Copy link
Collaborator

@dscho dscho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!!!

Assert.Single(actualValues);
Assert.Equal("true", actualValues[0]);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure whether this test was added intentionally? I might be misinterpreting, but nothing in that test speaks "drop the -core suffix" to me... Likewise with AzureReposHostProvider_UnconfigureAsync_User_Windows_UseHttpPathSetAndManagerHelper_RemovesEntry below.

Copy link
Collaborator Author

@mjcheetham mjcheetham Oct 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are to ensure that, on Windows, when uninstalling GCM (as installed from a standalone installer), we do NOT delete the useHttpPath setting that was placed in the --system config file by Git for Windows.

The new tests check to see if, when helper = manager, we don't remove the useHttpPath setting.

The existing tests check we don't remove the useHttpPath setting when helper = manager-core. This would be the case when installing and then uninstalling GCM standalone with an older version of Git for Windows present.

src/linux/Packaging.Linux/build.sh Show resolved Hide resolved
Create symlinks and shim/copy-executables for the original exec
"git-credential-manager-core(.exe)" name for consumers who have not
updated to the new name.

We detect if the consumer is launching us via the "-core" symlink or
executable shim by consulting the platform-native APIs to get the
original "argv[0]". All of the .NET APIs sadly don't give us the real
"argv[0]", so we need to use native APIs...

If we detect use of the old name, print a warning that the user should
update their configuration, and a help link for more information.
Add documentation with information about the GCM.exe rename, and how to
fix-up any configuration after the change.

The aka.ms/gcm/rename shortlink points to this document.
@mjcheetham mjcheetham merged commit 02204ac into git-ecosystem:main Oct 24, 2022
@mjcheetham mjcheetham deleted the exec-rename branch October 24, 2022 19:23
@ldennington ldennington mentioned this pull request Nov 3, 2022
ldennington added a commit that referenced this pull request Nov 3, 2022
Changes:

- Check for broken links in documentation (#700)
- Support macOS `arm64` installs via Homebrew (#798) 
- Validate installers before publishing (#813)
- Auto-generate maintainer away notification issues (#842)
- Install dotnet via Jammy feeds on Ubuntu 22.04 and greater (#839)
- Access Azure storage account using service principle credentials
(#851)
- Update documentation to use reference-style links (#680)
- Unify documentation line length (#862)
- Add generic username/password UI (#871)
- Bitbucket DC OAuth support (#607)
- Distribute GCM as a dotnet tool (#886)
- Drop `-core` suffix from entry executable #551 
- Speed up build graph (#924)
mjcheetham added a commit that referenced this pull request Nov 8, 2022
…ion (#951)

When we introduced the rename warning in #551, there was broken logic
for resolving the actual invoked program name on Mac and Linux.

**Windows**
We continue to use `CommandLineToArgvW(GetCommandLine(), ..)` to return
the _absolute, full path_ to the entry executable.

**macOS**
Switch from `_NSGetArgv()` to `_NSGetExecutablePath(..)` which, like the
Windows APIs above, returns the full path to the entry executable (or
symlink).

**Linux**
As there is no equivalent to `CommandLineToArgvW` or
`_NSGetExecutablePath` here, we instead do some path computation based
on the form of `argv[0]` that we get from `/proc/self/cmdline`.
- If the value is an absolute path, just use that.
- If the value is relative to the current directory (`./name`) then
combine this with the current directory.
- If the value contains a directory separator (`dir/name`) then also
resolve this from the current directory.
- Otherwise, this `argv[0]` value must have been a file name (`name`)
resolved from the `$PATH`.

If we still don't manage to resolve from the `$PATH`, try and resolve
the symlink `/proc/self/exe` that points to the executable image that
was loaded from disk. Note that we may miss any intermediate link names
here, but it's better than nothing.

---

In addition, we also never tested the .NET Tool scenario after updating
the `ICommandContext.ApplicationPath` to use the entry executable name,
whereas previously this was computed from the .NET assembly path.

Introduce a separate concept, the `InstallationDirectory` that always
points to the home of the core assemblies. This is used for resolving
things like in-box UI helpers.
@Moises3445

This comment was marked as spam.

@Favourjacobmudiaga

This comment was marked as spam.

mjcheetham added a commit that referenced this pull request Jul 5, 2023
Fixed path for user-only installation of GCM for Windows.
Seems #551 forgot to update this path.

version: v2.1.2
imagePath: `C:\Users\user`
```
$ git config --global credential.helper "/mnt/c/Users/user/AppData/Local/Programs/Git\ Credential\ Manager/git-credential-manager.exe"
$ git pull
Already up to date.
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants