Skip to content

Commit ec4db6d

Browse files
committed
installer: offer to install Posh-Git
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 <[email protected]>
1 parent 018f62e commit ec4db6d

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

installer/install.iss

+58-2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ Name: windowsterminal; Description: "(NEW!) Add a Git Bash Profile to Windows Te
118118
#ifdef WITH_SCALAR
119119
Name: scalar; Description: "(NEW!) Scalar (Git add-on to manage large-scale repositories)"; Types: default
120120
#endif
121+
Name: poshgit; Description: "(NEW!) Install Posh-Git from the PSGallery"
121122

122123

123124
[Run]
@@ -1096,8 +1097,8 @@ begin
10961097
end;
10971098
#endif
10981099
RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\GitForWindows','CurrentVersion',PreviousGitForWindowsVersion);
1099-
// The Windows Terminal profile is new in v2.32.0
1100-
HasUnseenComponents:=IsUpgrade('2.32.0');
1100+
// The Posh-Git option is new in v2.35.0
1101+
HasUnseenComponents:=IsUpgrade('2.35.0');
11011102
if HasUnseenComponents then
11021103
AddToSet(CustomPagesWithUnseenOptions,wpSelectComponents);
11031104
#if APP_VERSION!='0-test'
@@ -2940,6 +2941,7 @@ end;
29402941
procedure CurStepChanged(CurStep:TSetupStep);
29412942
var
29422943
DllPath,FileName,Cmd,Msg,Ico:String;
2944+
ExitCode:DWORD;
29432945
BuiltIns,ImageNames,EnvPath:TArrayOfString;
29442946
Count,i:Longint;
29452947
RootKey:Integer;
@@ -3366,6 +3368,40 @@ begin
33663368
InstallWindowsTerminalFragment();
33673369
end;
33683370
3371+
{
3372+
Install Posh-Git from the PSGallery
3373+
}
3374+
3375+
if (IsComponentSelected('poshgit')) then begin
3376+
WizardForm.StatusLabel.Caption:='Installing Posh-Git from the PSGallery';
3377+
// Must use the sysnative version of PowerShell, otherwise will target the wrong profile
3378+
Cmd:='"'+ExpandConstant('{sysnative}\WindowsPowerShell\v1.0\powershell.exe')+'"'+
3379+
' -ExecutionPolicy Bypass -NoProfile -NoLogo -NonInteractive -WindowStyle Hidden -command "'+
3380+
'if (!(Get-PackageProvider -Name NuGet)) {'+
3381+
' Install-PackageProvider -Name NuGet -Force ' +
3382+
'} ' +
3383+
'$policy = (Get-PSRepository -Name PSGallery).InstallationPolicy; ' +
3384+
'if ($policy -ne """Trusted""") {' +
3385+
' Set-PSRepository -Name PSGallery -InstallationPolicy Trusted '+
3386+
'} ' +
3387+
'Uninstall-Package posh-git -Scope AllUsers -ErrorAction SilentlyContinue; ' +
3388+
'Install-Module -Repository PSGallery -Scope AllUsers posh-git; ' +
3389+
'$res=$?; ' +
3390+
'if ($policy -ne """Trusted""") {' +
3391+
' Set-PSRepository -Name PSGallery -InstallationPolicy $policy ' +
3392+
'} ' +
3393+
'if ($res) {' +
3394+
' Add-PoshGitToProfile -AllUsers; ' +
3395+
' $res=$? ' +
3396+
'} ' +
3397+
'if (!$res) {' +
3398+
' exit(1) ' +
3399+
'}"';
3400+
if not ExecWithCapture(Cmd,Msg,Msg,ExitCode) or (ExitCode<>0) then
3401+
LogError('Failed to install Posh-Git:'+#13+Msg);
3402+
end;
3403+
3404+
33693405
{
33703406
Optionally "skip" installing bundled SSH binaries conflicting with external OpenSSH:
33713407
}
@@ -3812,4 +3848,24 @@ begin
38123848
if not DeleteFile(FileName) then
38133849
LogError('Line {#__LINE__}: Unable to delete file "'+FileName+'". Please do it manually after logging off and on again.');
38143850
end;
3851+
3852+
{
3853+
Remove posh-git
3854+
}
3855+
3856+
if (IsComponentSelected('poshgit')) then begin
3857+
Cmd:='"'+ExpandConstant('{sysnative}\WindowsPowerShell\v1.0\powershell.exe')+'"'+
3858+
' -ExecutionPolicy Bypass -NoProfile -NoLogo -NonInteractive -WindowStyle Hidden -command "'+
3859+
'Uninstall-Package posh-git -Scope AllUsers -ErrorAction SilentlyContinue; ' +
3860+
'$res=$?; ' +
3861+
'if ($res) {' +
3862+
' Remove-PoshGitFromProfile -AllUsers; ' +
3863+
' $res=$? ' +
3864+
'} ' +
3865+
'if (!$res) {' +
3866+
' exit(1) ' +
3867+
'}"';
3868+
if not ExecWithCapture(Cmd,Msg,Msg,ExitCode) or (ExitCode<>0) then
3869+
LogError('Failed to install Posh-Git:'+#13+Msg);
3870+
end;
38153871
end;

0 commit comments

Comments
 (0)