-
-
Notifications
You must be signed in to change notification settings - Fork 802
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
Conversation
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.
LGTM. I agree with the simplified approach. This strategy was originally written to preserve a posh-hg prompt. I had repos for both source control providers and I wanted each to preserve the other. I think tha tis VERY much an edge case today and I personally don't use mercurial anymore but it still holds a soft place in my heart.
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.
Looks good but look over the file encoding comments to see what you think.
|
||
$newProfile += $line | ||
} | ||
Set-Content -path $profile -value $newProfile -Force |
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.
Set-Content defaults to ASCII. Either we should detect the current encoding like in the other install.ps1 or maybe use -Encoding Utf8
? But that will add the UTF-8 BOM. File encodings are such a PITA.
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.
Also, should we backup the profile before we actually modify it - just in case?
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.
Oh man yeah that BOM issue is a total pain. 👍 to backing up the old $PROFILE
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.
Conveniently enough, install.ps1
already knows how to detect encoding. Reasonable to tackle that as a separate PR since this case is just copy/paste of chocolateyInstall.ps1
?
} | ||
# Save any previous Prompt logic | ||
Insert-Script ([REF]$newProfile) $oldPromptOverride | ||
Set-Content -path $profile -value $newProfile -Force |
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.
See comment below about file encoding and creating a backup.
I've brought this up-to-date after #361 and am working toward using |
b2b6c0e
to
f2a29a2
Compare
Yeah, I should have just gone to bed. I was trying to troubleshoot a false positive and just couldn't figure it out. Turns out PS> 'posh-git' -match 'posh-git'
True
PS> @('posh-git') -match 'posh-git'
posh-git In retrospect, it's obvious: the false positive was from a one-line |
Heh, yeah that happens with me far too often. Sometimes when I look at my "late night code" the next day or two - wow! My wife keeps telling me - "you think you're twenty something but ... you're not!" :-) |
This is blocked until #376, which has absorbed this PR's non-Chocolatey changes, has been merged. |
d902f42
to
1f94d29
Compare
Pretty much everything has changed, so let's start over.
Rebased on |
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.
LGTM - just one question about determining "current" (or latest?) version.
Install-ChocolateyZipPackage 'poshgit' $poshGitInstall $poshgitPath | ||
$pgitDir = Dir "$poshgitPath\*posh-git*\" | Sort-Object -Property LastWriteTime | Select -Last 1 | ||
$currentVersionPath = Get-ChildItem "$poshgitPath\*posh-git*\" | Sort-Object -Property LastWriteTime | Select-Object -Last 1 |
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.
1197f56
to
08c9613
Compare
Finally getting around to testing out the updated packaging.
WARNING: do not take a dependency on anything here, nor the |
You've been busy. ;-) |
fc68001
to
38fe768
Compare
Added another "fix" for the latest error: #381 (comment) It looks like Chocolatey 0.10.* might have changed availability of |
Hmm, is Chocolatey implementing their own PowerShell host process (and not initializing $PROFILE)? Hard to believe Chocolatey would just whack the $PROFILE variable but unfortunately that variable is not readonly, so it is possible. |
src/Utils.ps1
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Here you want "... '$($Profile.CurrentUserAllHosts)'"
${}
is handy when you want to separate the variable from the next text e.g. "${foo}${bar}"
.
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.
Ditto for the other two below.
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.
Good catch, not sure what I was thinking.
c7d47c9
to
83ce339
Compare
83ce339
to
8161c8f
Compare
At this point I just want it to work. I may bug @ferventcoder later to figure out why Check out 4c8cbc6 for my workarounds. Everything finally seems to be working as expected with Chocolatey v0.10.3.
|
I hear ya on the "just want it to work" sentiment. :-) Otherwise, LGTM. |
Chocolatey indeed hosting our own PowerShell Host, since 0.9.10. I thought we implemented a way for |
@ferventcoder thanks for confirming. It makes more sense for us to handle this in the chocolatey install scripts. Any CurrentHost Profile scripts provided by Chocolatey would only apply when the install package is running in Chocolatey and not later when the current host is PowerShell console or ISE. |
I think we're good now, but it wouldn't hurt for Chocolatey to learn about the extended |
Not that you need it, but I just wanted to throw it out there that there is a chocolateyBeforeModify.ps1 (as of 0.9.10) that you can use before upgrade and before uninstall to ensure things are not running, etc. |
Closes #239, inspired by need for #357 hack to fix #355.
Specific changes:
$PROFILE
that saves the pre–posh-gitprompt
$PROFILE
(if you want to keep the old behavior, make surePoshGitPrompt
doesn't appear in those lines)%ChocolateyBinRoot%\poshgit
and removes lines we might have added to$PROFILE
We might consider reverting the second commit (and maybe the first) for now, to avoid a breaking change before 1.0 drops.