-
Notifications
You must be signed in to change notification settings - Fork 612
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
Offer to install Posh-Git in the installer #401
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pulling this over from git-for-windows/git#1384 (comment):
Should we uninstall Posh-Git when uninstalling Git for Windows?
Importing posh-git without a git
command available logs a warning. Not fatal, but not ideal; better to be able to uninstall.
Can you tell if Git for Windows was installed with the poshgit
component? Ideally we'd leave the module alone if it was installed some other way.
If so, how do I remove it from the users' profile, programmatically?
Relevant code exists as of dahlbyk/posh-git#358; we can clean that up and export Remove-PoshGitFromProfile -AllUsers
.
installer/install.iss
Outdated
WizardForm.StatusLabel.Caption:='Installing Posh-Git from the PSGallery'; | ||
// Must use the sysnative version of PowerShell, otherwise will target the wrong profile | ||
Cmd:='"'+ExpandConstant('{sysnative}\WindowsPowerShell\v1.0\powershell.exe')+'"'+ | ||
' -ExecutionPolicy Bypass -NoLogo -NonInteractive -WindowStyle Hidden -command "'+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might add -NoProfile
, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
'if ($policy -ne """Trusted""") {' + | ||
' Set-PSRepository -Name PSGallery -InstallationPolicy Trusted '+ | ||
'} ' + | ||
'Install-Module -Repository PSGallery -Scope AllUsers posh-git; ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If posh-git is already installed, this is a no-op.
WARNING: Version '0.7.3' of module 'posh-git' is already installed at 'C:\Program Files\WindowsPowerShell\Modules\posh-git\0.7.3'. To install version '1.0.0', run Install-Module and add the -Force parameter, this command will install version '1.0.0' side-by-side with version '0.7.3'.
-Force
leaving old versions behind doesn't seem ideal.
We can detect an existing install with Get-Package posh-git -Scope AllUsers -ErrorAction SilentlyContinue
. Would be nice to be able to Update-Module -Scope AllUsers
, but it didn't learn -Scope
until somewhat recently.
Maybe try to Uninstall-Package posh-git -Scope AllUsers -ErrorAction SilentlyContinue
first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To test for posh-git already being installed, I think you want Get-Module posh-git -ListAvailable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to test for that, or do we simply just uninstall? I am of two minds there. If a user uninstalled Posh-Git manually, they would probably want to be notified that Git still thinks it should be installed, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if they ask to install a system posh-git, we clear out any existing system installs.
For the record, we're installing with Windows PowerShell but there are separate AllUsers
install locations (with higher precedence) for PowerShell Core which we're leaving alone.
' Set-PSRepository -Name PSGallery -InstallationPolicy $policy ' + | ||
'} ' + | ||
'if ($res) {' + | ||
' Add-PoshGitToProfile -AllUsers; ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This includes a check if posh-git is already imported in any of the current user's profiles, which would prevent the expected system-wide install here. It would seem reasonable for posh-git to be changed to only test the file to which the import would be added.
However, when testing this I also noticed that importing posh-git from two different locations (e.g. from the system install and then from a user install) can lead to unexpected behavior. So maybe better to err on the side of leaving all profiles alone if there's evidence of posh-git?
(No change required, here. Just thinking out loud about how posh-git should behave.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This includes a check if posh-git is already imported in any of the current user's profiles, which would prevent the expected system-wide install here. It would seem reasonable for posh-git to be changed to only test the file to which the import would be added.
I did not include this change in v1.1.0, but I do think it makes sense for adding to a specific profile to only check for an existing Import-Module
in that file. We can't use -Force
.
However, when testing this I also noticed that importing posh-git from two different locations (e.g. from the system install and then from a user install) can lead to unexpected behavior. So maybe better to err on the side of leaving all profiles alone if there's evidence of posh-git?
I believe the problem with importing different versions of posh-git
is that we're is we're defining multiple versions of class PoshGitCellColor
and such. It gets confused when the streams are crossed.
Yes. We simply ask
That would be nice! Do you think you can do it? I ask because 1) I am almost a PowerShell illiterate, and 2) I am currently overwhelmed with working on an unwelcome blocker. |
489804d
to
ec4db6d
Compare
@dahlbyk I updated the commit (anticipating suppport for |
Actually, let me give it a shot (while waiting for the MSYS2 runtime to compile). |
This is needed to be able to install/uninstall Posh-Git via Git for Windows' installer/uninstaller. See git-for-windows/build-extra#401 for details. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
ec4db6d
to
23fae10
Compare
installer/install.iss
Outdated
'Uninstall-Package posh-git -Scope AllUsers -ErrorAction SilentlyContinue; ' + | ||
'$res=$?; ' + | ||
'if ($res) {' + | ||
' Remove-PoshGitFromProfile -AllUsers; ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this function will be provided by the module, should we uninstall after it has been removed from profile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But of course 😁
Posh-Git is a very neat PowerShell module that serves as a PowerShell equivalent to Git's Bash prompt and tab completion. Let's offer it as an optional component; When selected, it will be installed from the PSGallery for all users and will then also be added to the profile. When selected, the uninstaller will also uninstall `posh-git`. This addresses git-for-windows/git#1384 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
23fae10
to
126917c
Compare
This is needed to be able to install/uninstall Posh-Git via Git for Windows' installer/uninstaller. See git-for-windows/build-extra#401 for details. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This is needed to be able to install/uninstall Posh-Git via Git for Windows' installer/uninstaller. See git-for-windows/build-extra#401 for details. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dahlbyk here you are: dahlbyk/posh-git#877 BTW I also wanted to verify that it passes the test suite, but it failed. The test suite failed also without my changes, though, so I opened dahlbyk/posh-git#878 which I hope you find the time to look into? |
Oh, and of course that PR (as well as a Posh-Git release after merging it) is a blocker for this here PR. |
Git for Windows v2.35.0-rc0 is due either tonight or tomorrow morning. I had hoped to get Posh-Git into that release, but it is cutting it too close now even if we can get the project to offer Posh-Git via Git for Windows moving forward again. |
Agree. Still ramping up after disconnected entirely over break, but hope to get back into this soon. |
-rc2 is due Wednesday. We've time to get this integrated until then, or after 2.35.0. |
If you don't see progress on this tonight, let's assume we're waiting for vNext. |
Even if it is too late for yet another Git for Windows version, let's push this forward so that we do not miss the next train, too. First stop: tell me how I can fix the CI runs (which all fail right now), then take a sweep at the open PRs/issues (most importantly, dahlbyk/posh-git#877 and dahlbyk/posh-git#885). |
Git for Windows v2.35.0 was released yesterday. @dahlbyk I would like to push for Posh-Git to have a working GitHub workflow, the to accept the two PRs I opened, and then to have a new release so that we can go forward with this here PR. |
💯 🔜 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So now that you waited months for Remove-PoshGitFromProfile
, I'm more and more convinced we should just leave all profiles alone and just find a way to communicate that the user can Add-PoshGitToProfile
from any PowerShell host to auto-import the system-installed module.
- Profile scripts don't work without changing Execution Policy; we could have the installer offer to change that for folks (need to give options), but I wouldn't want to do it silently
- Installing to
CurrentHost
means any host except the default (e.g. in VS Code) won't have posh-git, so the user will need to know aboutAdd-PoshGitToProfile
to turn it on there- Or we could use
AllHosts
, but there may be hosts that don't work well with posh-git and you can't opt out
- Or we could use
- PowerShell Core uses entirely different
$PROFILE
s, so we could either install there too or we're back to needing education aboutAdd-PoshGitToProfile
In other words, this could well turn into a whole new page of the installer devoted to configuring the PowerShell environment:
- Execution Policy?
- Current or All Users?
- Windows PowerShell: Default Host, All Hosts, or none?
- PowerShell Core (if
pwsh.exe
): Default Host, All Hosts, or none?
Or we could just figure out somewhere for the installer to link to Learn More. 🤷♂️
'if ($policy -ne """Trusted""") {' + | ||
' Set-PSRepository -Name PSGallery -InstallationPolicy Trusted '+ | ||
'} ' + | ||
'Install-Module -Repository PSGallery -Scope AllUsers posh-git; ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if they ask to install a system posh-git, we clear out any existing system installs.
For the record, we're installing with Windows PowerShell but there are separate AllUsers
install locations (with higher precedence) for PowerShell Core which we're leaving alone.
' Set-PSRepository -Name PSGallery -InstallationPolicy $policy ' + | ||
'} ' + | ||
'if ($res) {' + | ||
' Add-PoshGitToProfile -AllUsers; ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This includes a check if posh-git is already imported in any of the current user's profiles, which would prevent the expected system-wide install here. It would seem reasonable for posh-git to be changed to only test the file to which the import would be added.
I did not include this change in v1.1.0, but I do think it makes sense for adding to a specific profile to only check for an existing Import-Module
in that file. We can't use -Force
.
However, when testing this I also noticed that importing posh-git from two different locations (e.g. from the system install and then from a user install) can lead to unexpected behavior. So maybe better to err on the side of leaving all profiles alone if there's evidence of posh-git?
I believe the problem with importing different versions of posh-git
is that we're is we're defining multiple versions of class PoshGitCellColor
and such. It gets confused when the streams are crossed.
I'm not sure that I buy this argument. The problem I see here is that a user installed Git for Windows, clicked the option to install |
I'm not sure we can avoid this. Even setting aside PS Core, a different user could install the system posh-git from their user-specific profile and we can't reasonably fix that on their behalf. The simplest we can make this:
Conflicting installs and other profiles are on the user to manage. How easy would it be to make adding to profile an option, either binary or pick All/Current User/Host? Would the uninstall remember what was chosen? |
Sounds good. I'm a bit too out of my depth to make that happen, though. (In addition, I have too much else on my plate.)
That could be a checkbox. Here and here are valuable pages about this. It would look somewhat like this:
I would assume so. If it did not remember, we could add specific code to remember. |
The
|
Sounds good, as long as |
This is needed to be able to install/uninstall Posh-Git via Git for Windows' installer/uninstaller. See git-for-windows/build-extra#401 for details. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Posh-Git is a very neat PowerShell module that serves as a PowerShell equivalent to Git's Bash prompt and tab completion.
Let's offer it as an optional component; When selected, it will be installed from the PSGallery for all users and will then also be added to the profile.
This addresses git-for-windows/git#1384
/cc @dahlbyk