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

Chocolatey Simplification + Uninstall #358

Merged
merged 28 commits into from
Feb 6, 2017
Merged

Chocolatey Simplification + Uninstall #358

merged 28 commits into from
Feb 6, 2017

Conversation

dahlbyk
Copy link
Owner

@dahlbyk dahlbyk commented Jan 6, 2017

Closes #239, inspired by need for #357 hack to fix #355.

Specific changes:

  1. Chocolatey installer no longer adds code to $PROFILE that saves the pre–posh-git prompt
  2. Chocolatey installer also strips that legacy code from $PROFILE (if you want to keep the old behavior, make sure PoshGitPrompt doesn't appear in those lines)
  3. Added uninstaller that both deletes %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.

@dahlbyk dahlbyk added this to the v0.7 milestone Jan 6, 2017
@dahlbyk
Copy link
Owner Author

dahlbyk commented Jan 6, 2017

/cc @mwrock as the orignial author of the prompt override logic (534d602).

Copy link
Contributor

@mwrock mwrock left a 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.

rkeithhill
rkeithhill previously approved these changes Jan 6, 2017
Copy link
Collaborator

@rkeithhill rkeithhill left a 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
Copy link
Collaborator

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.

Copy link
Collaborator

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?

Copy link
Contributor

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

Copy link
Owner Author

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
Copy link
Collaborator

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.

@dahlbyk
Copy link
Owner Author

dahlbyk commented Jan 16, 2017

I've brought this up-to-date after #361 and am working toward using Add-PoshGitToProfile and (new, encoding-aware) Remove-PoshGitFromProfile for all activities that touch the profile.

@dahlbyk
Copy link
Owner Author

dahlbyk commented Jan 16, 2017

Yup, that's why I forced the result to be an array @() and then checked the count (length) of the array. Casting to [bool] like that works but isn't particularly "powershelly". And we typically don't use a return when it isn't needed. :-)

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 -match returns a boolean when matching a string and acts as a filter when used against an array/list.

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 $PROFILE.CurrentUserAllHosts I just happened to have created. So the fix is to force to array before the -match: c8bd3b5. Added a test for this scenario, too.

@rkeithhill
Copy link
Collaborator

I should have just gone to bed

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!" :-)

@dahlbyk
Copy link
Owner Author

dahlbyk commented Jan 26, 2017

This is blocked until #376, which has absorbed this PR's non-Chocolatey changes, has been merged.

@rkeithhill rkeithhill mentioned this pull request Jan 27, 2017
@dahlbyk dahlbyk force-pushed the chocolatey-uninstall branch 3 times, most recently from d902f42 to 1f94d29 Compare January 27, 2017 18:25
@dahlbyk dahlbyk dismissed rkeithhill’s stale review January 27, 2017 18:25

Pretty much everything has changed, so let's start over.

@dahlbyk
Copy link
Owner Author

dahlbyk commented Jan 27, 2017

This is blocked until #376, which has absorbed this PR's non-Chocolatey changes, has been merged.

Rebased on master and basically rewrote the entire branch with some refactoring, encoding awareness, etc. Haven't actually tested the Chocolatey package yet, but could use some feedback on the evolution.

Copy link
Collaborator

@rkeithhill rkeithhill left a 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
Copy link
Collaborator

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?

Copy link
Owner Author

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.

@dahlbyk
Copy link
Owner Author

dahlbyk commented Jan 30, 2017

Finally getting around to testing out the updated packaging.

  • Clean install
  • Upgrade
  • Uninstall

WARNING: do not take a dependency on anything here, nor the v0.7.0-pre1 tag. I'm hacking and slashing all over the place.

@rkeithhill
Copy link
Collaborator

You've been busy. ;-)

@dahlbyk
Copy link
Owner Author

dahlbyk commented Jan 30, 2017

Added another "fix" for the latest error: #381 (comment)

It looks like Chocolatey 0.10.* might have changed availability of $PROFILE?

@rkeithhill
Copy link
Collaborator

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}'"
Copy link
Collaborator

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}".

Copy link
Collaborator

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.

Copy link
Owner Author

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.

@dahlbyk
Copy link
Owner Author

dahlbyk commented Jan 31, 2017

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.

At this point I just want it to work. I may bug @ferventcoder later to figure out why $PROFILE is missing its properties.

Check out 4c8cbc6 for my workarounds. Everything finally seems to be working as expected with Chocolatey v0.10.3.

choco install poshgit --version=v0.7.0-pre4

@rkeithhill
Copy link
Collaborator

I hear ya on the "just want it to work" sentiment. :-) Otherwise, LGTM.

@ferventcoder
Copy link
Contributor

$PROFILE is missing its properties.

Chocolatey indeed hosting our own PowerShell Host, since 0.9.10. I thought we implemented a way for $PROFILE to work similarly to how it did before, but it may not have much more than the one profile path as its settings. My understanding is that a profile path is dependent on the PowerShell Host and not guaranteed. At least from what I've read. Open to suggestions to improve the custom Choco Host though.

@rkeithhill
Copy link
Collaborator

@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.

@dahlbyk
Copy link
Owner Author

dahlbyk commented Feb 1, 2017

$PROFILE is missing its properties.

Chocolatey indeed hosting our own PowerShell Host, since 0.9.10. I thought we implemented a way for $PROFILE to work similarly to how it did before, but it may not have much more than the one profile path as its settings. My understanding is that a profile path is dependent on the PowerShell Host and not guaranteed. At least from what I've read. Open to suggestions to improve the custom Choco Host though.

I think we're good now, but it wouldn't hurt for Chocolatey to learn about the extended $PROFILE properties: chocolatey/choco#1154.

This was referenced Feb 1, 2017
@ferventcoder
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error in $profile after poshgit installed? Uninstall through Chocolatey
4 participants