-
-
Notifications
You must be signed in to change notification settings - Fork 815
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
Chocolatey Simplification + Uninstall #358
Changes from 18 commits
297e07a
48f61c9
35c57a9
c1c9748
8248f03
e1d10ac
6abca6a
962d38b
1c77805
7e42038
7fd9638
9f6b256
6fd6a31
9d559c4
3755191
5f8c899
a4edddd
6bdac52
77aaa9c
5c8e048
9a1d91d
8161c8f
c9c1b52
4c8cbc6
7620aaf
04c2415
f8d9639
8a4207d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pushd $PSScriptRoot | ||
choco pack poshgit.nuspec | ||
choco install -f -y poshgit -pre -s . | ||
popd |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,17 @@ function Add-PoshGitToProfile([switch]$AllHosts, [switch]$Force, [switch]$WhatIf | |
} | ||
} | ||
|
||
if (!$profilePath) { | ||
Write-Warning "Skipping add of posh-git import; no profile found." | ||
Write-Verbose "`$profilePath = '$profilePath'" | ||
Write-Verbose "`$PROFILE = '$PROFILE'" | ||
Write-Verbose "CurrentUserCurrentHost = '${PROFILE.CurrentUserCurrentHost}'" | ||
Write-Verbose "CurrentUserAllHosts = '${PROFILE.CurrentUserAllHosts}'" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you want There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto for the other two below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, not sure what I was thinking. |
||
Write-Verbose "AllUsersCurrentHost = '${PROFILE.AllUsersCurrentHost}'" | ||
Write-Verbose "AllUsersAllHosts = '${PROFILE.AllUsersAllHosts}'" | ||
return | ||
} | ||
|
||
# Check if the location of this module file is in the PSModulePath | ||
if (Test-InPSModulePath $ModuleBasePath) { | ||
$profileContent = "`nImport-Module posh-git" | ||
|
@@ -215,7 +226,9 @@ function Test-PoshGitImportedInScript { | |
return $false | ||
} | ||
|
||
(@(Get-Content $Path -ErrorAction SilentlyContinue) -match 'posh-git').Count -gt 0 | ||
$match = (@(Get-Content $Path -ErrorAction SilentlyContinue) -match 'posh-git').Count -gt 0 | ||
if ($match) { Write-Verbose "posh-git found in '$Path'" } | ||
$match | ||
} | ||
|
||
function dbg($Message, [Diagnostics.Stopwatch]$Stopwatch) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it would be better to sort on the directory name if it includes a lexicographic sortable version number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really just defensive programming. A few lines up we try to
remove-item $poshgitPath
, so this folder will almost always have a single subfolder.