From 6efec4f48c7b2bba05f565b883a262a61116d548 Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Fri, 24 Feb 2017 20:58:39 -0600 Subject: [PATCH 1/4] Hide profile.example.ps1 warning if installed w/ choco Either we'll keep Chocolatey support for 1.0 and handle profile.example.ps1 gracefully, or we'll never release a version that doesn't include the file (so the warning is meaningless). --- chocolatey/tools/chocolateyInstall.ps1 | 2 +- profile.example.ps1 | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/chocolatey/tools/chocolateyInstall.ps1 b/chocolatey/tools/chocolateyInstall.ps1 index a09893e43..0f01a6c3f 100644 --- a/chocolatey/tools/chocolateyInstall.ps1 +++ b/chocolatey/tools/chocolateyInstall.ps1 @@ -27,7 +27,7 @@ if ($line -like '*PoshGitPrompt*') { continue; } if($line -like '. *posh-git*profile.example.ps1*') { - $line = ". '$currentVersionPath\profile.example.ps1'" + $line = ". '$currentVersionPath\profile.example.ps1' choco" } if($line -like 'Import-Module *\src\posh-git.psd1*') { $line = "Import-Module '$currentVersionPath\src\posh-git.psd1'" diff --git a/profile.example.ps1 b/profile.example.ps1 index fe86c74b8..b5b339105 100644 --- a/profile.example.ps1 +++ b/profile.example.ps1 @@ -17,4 +17,6 @@ else { Start-SshAgent -Quiet -Write-Warning "posh-git's profile.example.ps1 will be removed in a future version. To avoid a change in behavior, copy its contents into your $PROFILE." +if ($args[0] -ne 'choco') { + Write-Warning "posh-git's profile.example.ps1 will be removed in a future version. To avoid a change in behavior, copy its contents into your $PROFILE." +} From b4ba48ef71e94dece2b7c1ebac80e257f9df885e Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Fri, 24 Feb 2017 21:20:36 -0600 Subject: [PATCH 2/4] Add StartSshAgent parameter to Add-PoshGitToProfile --- profile.example.ps1 | 3 ++- src/Utils.ps1 | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/profile.example.ps1 b/profile.example.ps1 index b5b339105..92b0d3c9f 100644 --- a/profile.example.ps1 +++ b/profile.example.ps1 @@ -18,5 +18,6 @@ else { Start-SshAgent -Quiet if ($args[0] -ne 'choco') { - Write-Warning "posh-git's profile.example.ps1 will be removed in a future version. To avoid a change in behavior, copy its contents into your $PROFILE." + Write-Warning "posh-git's profile.example.ps1 will be removed in a future version." + Write-Warning "Consider using `Add-PoshGitToProfile -StartSshAgent` instead." } diff --git a/src/Utils.ps1 b/src/Utils.ps1 index eb3318726..0e86634b3 100644 --- a/src/Utils.ps1 +++ b/src/Utils.ps1 @@ -69,6 +69,8 @@ function Invoke-Utf8ConsoleCommand([ScriptBlock]$cmd) { .PARAMETER Force Do not check if the specified profile script is already importing posh-git. Just add Import-Module posh-git command. +.PARAMETER StartSshAgent + Also add `Start-SshAgent -Quiet` to the specified profile script. .EXAMPLE PS C:\> Add-PoshGitToProfile Updates your profile script for the current PowerShell host to import the @@ -93,6 +95,10 @@ function Add-PoshGitToProfile { [switch] $Force, + [Parameter()] + [switch] + $StartSshAgent, + [Parameter(ValueFromRemainingArguments)] [psobject[]] $TestParams @@ -173,6 +179,9 @@ function Add-PoshGitToProfile { if ($PSCmdlet.ShouldProcess($profilePath, "Add 'Import-Module posh-git' to profile")) { Add-Content -LiteralPath $profilePath -Value $profileContent -Encoding UTF8 } + if ($StartSshAgent -and $PSCmdlet.ShouldProcess($profilePath, "Add 'Start-SshAgent -Quiet' to profile")) { + Add-Content -LiteralPath $profilePath -Value 'Start-SshAgent -Quiet' -Encoding UTF8 + } } <# From 57848d3e785745db8a2f4e18f04234072941e988 Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Fri, 24 Feb 2017 21:27:32 -0600 Subject: [PATCH 3/4] choco uninstall: remove Start-SshAgent from $PROFILE --- chocolatey/tools/chocolateyUninstall.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/chocolatey/tools/chocolateyUninstall.ps1 b/chocolatey/tools/chocolateyUninstall.ps1 index 48fe9fc40..2e3285b31 100644 --- a/chocolatey/tools/chocolateyUninstall.ps1 +++ b/chocolatey/tools/chocolateyUninstall.ps1 @@ -13,6 +13,7 @@ foreach($line in $oldProfile) { if ($line -like '*PoshGitPrompt*') { continue; } if ($line -like '*Load posh-git example profile*') { continue; } + if ($line -like '*Start-SshAgent*') { continue; } if($line -like '. *posh-git*profile.example.ps1*') { continue; From 1f321b83336895cdbde4ce5c73697721e63ac50e Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Sat, 25 Feb 2017 20:21:23 -0600 Subject: [PATCH 4/4] Test Add-PoshGitToProfile -StartSshAgent --- test/Utils.Tests.ps1 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/Utils.Tests.ps1 b/test/Utils.Tests.ps1 index d2c0964f8..8c5f773fe 100644 --- a/test/Utils.Tests.ps1 +++ b/test/Utils.Tests.ps1 @@ -80,6 +80,23 @@ New-Alias pscore C:\Users\Keith\GitHub\rkeithhill\PowerShell\src\powershell-win- $profileContent += "${newLine}${newLine}Import-Module posh-git" $content -join $newLine | Should BeExactly $profileContent } + It 'Adds Start-SshAgent if posh-git is not installed' { + Add-PoshGitToProfile $profilePath -StartSshAgent + + Test-Path -LiteralPath $profilePath | Should Be $true + $last = Get-Content $profilePath | Select-Object -Last 1 + $last | Should BeExactly "Start-SshAgent -Quiet" + } + It 'Does not add Start-SshAgent if posh-git is installed' { + $profileContent = 'Import-Module posh-git' + Set-Content $profilePath -Value $profileContent + + Add-PoshGitToProfile $profilePath -StartSshAgent + + Test-Path -LiteralPath $profilePath | Should Be $true + $content = Get-Content $profilePath + $content | Should BeExactly $profileContent + } } Context 'Test-PoshGitImportedInScript Tests' {