Skip to content

Commit

Permalink
installer: offer to install Posh-Git
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dscho committed Dec 9, 2021
1 parent 018f62e commit ec4db6d
Showing 1 changed file with 58 additions and 2 deletions.
60 changes: 58 additions & 2 deletions installer/install.iss
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Name: windowsterminal; Description: "(NEW!) Add a Git Bash Profile to Windows Te
#ifdef WITH_SCALAR
Name: scalar; Description: "(NEW!) Scalar (Git add-on to manage large-scale repositories)"; Types: default
#endif
Name: poshgit; Description: "(NEW!) Install Posh-Git from the PSGallery"


[Run]
Expand Down Expand Up @@ -1096,8 +1097,8 @@ begin
end;
#endif
RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\GitForWindows','CurrentVersion',PreviousGitForWindowsVersion);
// The Windows Terminal profile is new in v2.32.0
HasUnseenComponents:=IsUpgrade('2.32.0');
// The Posh-Git option is new in v2.35.0
HasUnseenComponents:=IsUpgrade('2.35.0');
if HasUnseenComponents then
AddToSet(CustomPagesWithUnseenOptions,wpSelectComponents);
#if APP_VERSION!='0-test'
Expand Down Expand Up @@ -2940,6 +2941,7 @@ end;
procedure CurStepChanged(CurStep:TSetupStep);
var
DllPath,FileName,Cmd,Msg,Ico:String;
ExitCode:DWORD;
BuiltIns,ImageNames,EnvPath:TArrayOfString;
Count,i:Longint;
RootKey:Integer;
Expand Down Expand Up @@ -3366,6 +3368,40 @@ begin
InstallWindowsTerminalFragment();
end;
{
Install Posh-Git from the PSGallery
}
if (IsComponentSelected('poshgit')) then begin
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 -NoProfile -NoLogo -NonInteractive -WindowStyle Hidden -command "'+
'if (!(Get-PackageProvider -Name NuGet)) {'+
' Install-PackageProvider -Name NuGet -Force ' +
'} ' +
'$policy = (Get-PSRepository -Name PSGallery).InstallationPolicy; ' +
'if ($policy -ne """Trusted""") {' +
' Set-PSRepository -Name PSGallery -InstallationPolicy Trusted '+
'} ' +
'Uninstall-Package posh-git -Scope AllUsers -ErrorAction SilentlyContinue; ' +
'Install-Module -Repository PSGallery -Scope AllUsers posh-git; ' +
'$res=$?; ' +
'if ($policy -ne """Trusted""") {' +
' Set-PSRepository -Name PSGallery -InstallationPolicy $policy ' +
'} ' +
'if ($res) {' +
' Add-PoshGitToProfile -AllUsers; ' +
' $res=$? ' +
'} ' +
'if (!$res) {' +
' exit(1) ' +
'}"';
if not ExecWithCapture(Cmd,Msg,Msg,ExitCode) or (ExitCode<>0) then
LogError('Failed to install Posh-Git:'+#13+Msg);
end;
{
Optionally "skip" installing bundled SSH binaries conflicting with external OpenSSH:
}
Expand Down Expand Up @@ -3812,4 +3848,24 @@ begin
if not DeleteFile(FileName) then
LogError('Line {#__LINE__}: Unable to delete file "'+FileName+'". Please do it manually after logging off and on again.');
end;
{
Remove posh-git
}
if (IsComponentSelected('poshgit')) then begin
Cmd:='"'+ExpandConstant('{sysnative}\WindowsPowerShell\v1.0\powershell.exe')+'"'+
' -ExecutionPolicy Bypass -NoProfile -NoLogo -NonInteractive -WindowStyle Hidden -command "'+
'Uninstall-Package posh-git -Scope AllUsers -ErrorAction SilentlyContinue; ' +
'$res=$?; ' +
'if ($res) {' +
' Remove-PoshGitFromProfile -AllUsers; ' +
' $res=$? ' +
'} ' +
'if (!$res) {' +
' exit(1) ' +
'}"';
if not ExecWithCapture(Cmd,Msg,Msg,ExitCode) or (ExitCode<>0) then
LogError('Failed to install Posh-Git:'+#13+Msg);
end;
end;

0 comments on commit ec4db6d

Please sign in to comment.