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

Hide profile.example.ps1 warning for Chocolatey #444

Merged
merged 4 commits into from
Feb 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chocolatey/tools/chocolateyInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand Down
1 change: 1 addition & 0 deletions chocolatey/tools/chocolateyUninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion profile.example.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ 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."
Write-Warning "Consider using `Add-PoshGitToProfile -StartSshAgent` instead."
}
9 changes: 9 additions & 0 deletions src/Utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -93,6 +95,10 @@ function Add-PoshGitToProfile {
[switch]
$Force,

[Parameter()]
[switch]
$StartSshAgent,

[Parameter(ValueFromRemainingArguments)]
[psobject[]]
$TestParams
Expand Down Expand Up @@ -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
}
}

<#
Expand Down
17 changes: 17 additions & 0 deletions test/Utils.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
Expand Down