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

Error in $profile after poshgit installed? #355

Closed
ewgoforth opened this issue Jan 4, 2017 · 8 comments · Fixed by #358
Closed

Error in $profile after poshgit installed? #355

ewgoforth opened this issue Jan 4, 2017 · 8 comments · Fixed by #358

Comments

@ewgoforth
Copy link

I'm seeing the following message when my $profile gets executed:

Rename-Item : Cannot rename because item at 'Function:\Prompt' does not exist.
At C:\Users\myuser\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:66 char:1
+ Rename-Item Function:\Prompt PoshGitPrompt -Force

here's what the relevant line looks like:

. 'C:\tools\poshgit\dahlbyk-posh-git-464601f\profile.example.ps1'
Rename-Item Function:\Prompt PoshGitPrompt -Force
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}

@rkeithhill
Copy link
Collaborator

Are you using latest bits from this repo or the latest poshgit from Chocolatey?

If you are using the latest bits from this repo (the not yet released 0.7.0) you can comment out the these lines e.g.:

# Rename-Item Function:\Prompt PoshGitPrompt -Force
# 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}

Even if you're not using the latest repo bits, you might try commenting out the lines above.

BTW which version of PowerShell are you using (check with $PSVersionTable.PSVersion)?

@dahlbyk
Copy link
Owner

dahlbyk commented Jan 5, 2017

Are you using latest bits from this repo or the latest poshgit from Chocolatey?

C:\tools\poshgit\dahlbyk-posh-git-464601f SHA is the merge of #349: https://github.com/dahlbyk/posh-git/commits/464601f. For the record, this is why we need to pin the Chocolatey package to the tagged version rather than master. 😒

I would not expect loading profile.example.ps1 to result in Function:\Prompt being missing. It looks like we might be getting confused if Function:Prompt doesn't exist when the module is imported?


For reference, this is what a Chocolatey-installed $PROFILE looks like:

if(Test-Path Function:\Prompt) {Rename-Item Function:\Prompt PrePoshGitPrompt -Force}

# Load posh-git example profile
. 'C:\tools\poshgit\dahlbyk-posh-git-464601f\profile.example.ps1'

Rename-Item Function:\Prompt PoshGitPrompt -Force
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}

I'd love for all of this to be replaced in 1.0 with Import-Module posh-git.

@dahlbyk
Copy link
Owner

dahlbyk commented Jan 5, 2017

Yeah, the code to set prompt is definitely broken if prompt doesn't exist: #357

Thanks for the bug report, @ewgoforth!

@ewgoforth
Copy link
Author

I'm using the following powershell version:

PS>$PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      14393  187


PS>

I am using the latest from chocolatey as of yesterday. If I comment out everything it's normal, but I don't get the posh-git functionality:

#if(Test-Path Function:\Prompt) {Rename-Item Function:\Prompt PrePoshGitPrompt -Force}
# Load posh-git example profile. 'C:\tools\poshgit\dahlbyk-posh-git-464601f\profile.example.ps1'
#Rename-Item Function:\Prompt PoshGitPrompt -Force
#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}

@dahlbyk
Copy link
Owner

dahlbyk commented Jan 5, 2017

I would uncomment the second line (by which I mean add a newline after "example profile" and before the .) and delete the other three - they shouldn't be necessary, and will be removed when we move to 1.0.

@ewgoforth
Copy link
Author

I did that like so:

#if(Test-Path Function:\Prompt) {Rename-Item Function:\Prompt PrePoshGitPrompt -Force}
# Load posh-git example profile
. 'C:\tools\poshgit\dahlbyk-posh-git-464601f\profile.example.ps1'
#Rename-Item Function:\Prompt PoshGitPrompt -Force
#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}

and I seem to have the full poshgit functionality.

@rkeithhill
Copy link
Collaborator

So as an action item for this issue, is there something in the Chocolatey package that needs to be tweaked for 0.7.0? Also, just removing those lines probably wouldn't help someone who has a previously (Chocolatey) installed version of poshgit. What should we do there?

@dahlbyk
Copy link
Owner

dahlbyk commented Jan 6, 2017

@ewgoforth if you don't mind, could you do a choco install poshgit --force to get latest and verify that the error doesn't return if you uncomment all those lines?

So as an action item for this issue, is there something in the Chocolatey package that needs to be tweaked for 0.7.0?

I believe #357 is technically sufficient, but we have #239 marked for 0.7 so: #358.

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

Successfully merging a pull request may close this issue.

3 participants