diff --git a/chocolatey/packAndLocalInstall.ps1 b/chocolatey/packAndLocalInstall.ps1 new file mode 100644 index 000000000..9c2a9a6b4 --- /dev/null +++ b/chocolatey/packAndLocalInstall.ps1 @@ -0,0 +1,20 @@ +param ($Remote = 'origin', [switch]$Force) +pushd $PSScriptRoot + +$nuspec = [xml](Get-Content poshgit.nuspec) +$version = $nuspec.package.metadata.version +$tag = "v$version" + +if ($Force) { + git tag -f $tag + git push -f $Remote $tag +} +elseif (!$(git ls-remote $Remote $tag)) { + Write-Warning "'$Remote/$tag' not found! Use -Force to create tag at HEAD." + return +} + +choco pack poshgit.nuspec +choco install -f -y poshgit -pre --version=$version -s . + +popd diff --git a/chocolatey/poshgit.nuspec b/chocolatey/poshgit.nuspec index 661b5ff6c..5e137a72f 100644 --- a/chocolatey/poshgit.nuspec +++ b/chocolatey/poshgit.nuspec @@ -3,7 +3,7 @@ poshgit posh-git - 0.6.1.20160330 + 0.7.0-pre5 Keith Dahlby, Mark Embling, Jeremy Skinner Keith Dahlby ### posh-git diff --git a/chocolatey/tools/chocolateyInstall.ps1 b/chocolatey/tools/chocolateyInstall.ps1 index a72a52a5c..0f6caf308 100644 --- a/chocolatey/tools/chocolateyInstall.ps1 +++ b/chocolatey/tools/chocolateyInstall.ps1 @@ -1,58 +1,48 @@ -function Insert-Script([ref]$originalScript, $script) { - if(!($originalScript.Value -Contains $script)) { $originalScript.Value += $script } -} - -try { +try { $binRoot = Get-BinRoot - - $oldPromptOverride = "if(Test-Path Function:\Prompt) {Rename-Item Function:\Prompt PrePoshGitPrompt -Force}" - $newPromptOverride = "function Prompt() {if(Test-Path Function:\PrePoshGitPrompt){++`$global:poshScope; New-Item function:\script:Write-host -value `"param([object] ```$object, ```$backgroundColor, ```$foregroundColor, [switch] ```$nonewline) `" -Force | Out-Null;`$private:p = PrePoshGitPrompt; if(--`$global:poshScope -eq 0) {Remove-Item function:\Write-Host -Force}}PoshGitPrompt}" - $poshgitPath = join-path $binRoot 'poshgit' try { if (test-path($poshgitPath)) { - Write-Host "Attempting to remove existing `'$poshgitPath`' prior to install." + Write-Host "Attempting to remove existing `'$poshgitPath`'." remove-item $poshgitPath -recurse -force } } catch { - Write-Host 'Could not remove poshgit folder' + Write-Host "Could not remove `'$poshgitPath`'" } - $poshGitInstall = if($env:poshGit -ne $null){ $env:poshGit } else {'https://github.com/dahlbyk/posh-git/zipball/master'} - Install-ChocolateyZipPackage 'poshgit' $poshGitInstall $poshgitPath - $pgitDir = Dir "$poshgitPath\*posh-git*\" | Sort-Object -Property LastWriteTime | Select -Last 1 + $version = "v$Env:chocolateyPackageVersion" + if ($version -eq 'v') { $version = 'master' } + $poshGitInstall = if ($env:poshGit ) { $env:poshGit } else { "https://github.com/dahlbyk/posh-git/zipball/$version" } + $zip = Install-ChocolateyZipPackage 'poshgit' $poshGitInstall $poshgitPath + $currentVersionPath = Get-ChildItem "$poshgitPath\*posh-git*\" | Sort-Object -Property LastWriteTime | Select-Object -Last 1 if(Test-Path $PROFILE) { $oldProfile = @(Get-Content $PROFILE) + + . $currentVersionPath\src\Utils.ps1 + $oldProfileEncoding = Get-FileEncoding $PROFILE + $newProfile = @() - #If old profile exists replace with new one and make sure prompt preservation function is on top - $pgitExample = "$pgitDir\profile.example.ps1" foreach($line in $oldProfile) { - if($line.ToLower().Contains("$poshgitPath".ToLower())) { - Insert-Script ([REF]$newProfile) $oldPromptOverride - $line = ". '$pgitExample'" + if ($line -like '*PoshGitPrompt*') { continue; } + + if($line -like '. *posh-git*profile.example.ps1*') { + $line = ". '$currentVersionPath\profile.example.ps1'" + } + if($line -like 'Import-Module *\src\posh-git.psd1*') { + $line = "Import-Module '$currentVersionPath\src\posh-git.psd1'" } - if($line.Trim().Length -gt 0) { $newProfile += $line } + $newProfile += $line } - # Save any previous Prompt logic - Insert-Script ([REF]$newProfile) $oldPromptOverride - Set-Content -path $profile -value $newProfile -Force + Set-Content -path $profile -value $newProfile -Force -Encoding $oldProfileEncoding } - $installer = Join-Path $pgitDir 'install.ps1' + $installer = Join-Path $currentVersionPath 'install.ps1' & $installer - - $newProfile = @(Get-Content $PROFILE) - Insert-Script ([REF]$newProfile) "Rename-Item Function:\Prompt PoshGitPrompt -Force" - - # function that will run previous prompt logic and then the poshgit logic - # all output from previous prompts will be swallowed - Insert-Script ([REF]$newProfile) $newPromptOverride - Set-Content -path $profile -value $newProfile -Force } catch { try { - if($oldProfile){ Set-Content -path $PROFILE -value $oldProfile -Force } + if($oldProfile){ Set-Content -path $PROFILE -value $oldProfile -Force -Encoding $oldProfileEncoding } } catch {} throw diff --git a/chocolatey/tools/chocolateyUninstall.ps1 b/chocolatey/tools/chocolateyUninstall.ps1 new file mode 100644 index 000000000..311fb9878 --- /dev/null +++ b/chocolatey/tools/chocolateyUninstall.ps1 @@ -0,0 +1,44 @@ +try { + $binRoot = Get-BinRoot + $poshgitPath = join-path $binRoot 'poshgit' + + $currentVersionPath = Get-ChildItem "$poshgitPath\*posh-git*\" | Sort-Object -Property LastWriteTime | Select-Object -Last 1 + + if(Test-Path $PROFILE) { + $oldProfile = @(Get-Content $PROFILE) + + . $currentVersionPath\src\Utils.ps1 + $oldProfileEncoding = Get-FileEncoding $PROFILE + + $newProfile = @() + foreach($line in $oldProfile) { + if ($line -like '*PoshGitPrompt*') { continue; } + if ($line -like '*Load posh-git example profile*') { continue; } + + if($line -like '. *posh-git*profile.example.ps1*') { + continue; + } + if($line -like 'Import-Module *\src\posh-git.psd1*') { + continue; + } + $newProfile += $line + } + Set-Content -path $profile -value $newProfile -Force -Encoding $oldProfileEncoding + } + + try { + if (test-path($poshgitPath)) { + Write-Host "Attempting to remove existing `'$poshgitPath`'." + remove-item $poshgitPath -recurse -force + } + } catch { + Write-Host "Could not remove `'$poshgitPath`'" + } +} catch { + try { + if($oldProfile){ Set-Content -path $PROFILE -value $oldProfile -Force -Encoding $oldProfileEncoding } + } + catch {} + throw +} +