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

Failed to import posh-git #442

Closed
OswaldGlinkmeyer opened this issue Feb 24, 2017 · 8 comments
Closed

Failed to import posh-git #442

OswaldGlinkmeyer opened this issue Feb 24, 2017 · 8 comments
Assignees
Milestone

Comments

@OswaldGlinkmeyer
Copy link

System Details

  • posh-git version/path: 0.7.0 C:\tools\poshgit\dahlbyk-posh-git-7d93c81\src
  • PowerShell version: 3.0
  • git version 1.9.5.msysgit.1
  • OS: Microsoft Windows NT 6.1.7601 Service Pack 1

Issue Description

Amateur here who uses posh-git for hobby projects. posh-git's been working fine. On a whim, I updated the other day, now when I start my powershell I get a yellow warning saying I should copy the contents of the profile.example.ps1 to the $PROFILE. When I copy the contents of the profile.example.ps1 into my Microsoft.PowerShell_profile.ps1 file, I get the error message "Failed to import posh-git" and posh-git will not work.
I thought I might type in the commandlet to see what I get:
get-module posh-git -ListAvailable
But I get nothing. If I restore my Powershell profile back so it points to the original profile.example.ps1, it again works fine. It's as if the import only works when it is in the original location. Basically, git and posh-git are the only things I really use Powershell for at the present time. Am I misunderstanding the instructions? What am I missing?
Microsoft.PowerShell_profile.txt <--my current non-working profile

@rkeithhill
Copy link
Collaborator

What output do you get when you run $env:PSModulePath in PowerShell?

@OswaldGlinkmeyer
Copy link
Author

\BI2011SERVER\RedirectedFolders\cseiler\My Documents\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v 1.0\Modules;c:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules;C:\Program Files\Microsoft Azure Recovery Services Agent\bin\Modules;C:\Program Files (x86)\Microsoft SQL Server\130\Tools\PowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules\

Posh-git is in a folder called c:\tools\poshgit\dahlbyk-posh-git-7d93c81. So is that my issue? I need to have that directory in the PSModulePath?

@rkeithhill
Copy link
Collaborator

There are several ways to solve this. You could add that path to your system's PSModulePath environment variable but that path will likely change when you update to a new version (new SHA1). Another option is to simply import the module by path. Remove all the stuff you added from profile.example.ps1 and add this to your profile:

Import-Module C:\tools\poshgit\dahlbyk-posh-git-7d93c81\src\posh-git.psd1

Start-SshAgent -Quiet

When you update to a newer version you will need to remember to update your profile to use the new path. But I think it is easier to edit a file than it is to edit an environment variable.

@OswaldGlinkmeyer
Copy link
Author

Thanks. That explains it.

@dahlbyk
Copy link
Owner

dahlbyk commented Feb 24, 2017

On a whim, I updated the other day, now when I start my powershell I get a yellow warning saying I should copy the contents of the profile.example.ps1 to the $PROFILE.

Did you upgrade using Chocolatey? I would expect the latest version on Chocolatey to have automatically switched your $PROFILE to Import-Module...

☝️ is what I was going to say, and then I checked the code and noticed that it is set up to continue using profile.example.ps1. And then I realized that the "copy its contents into your $PROFILE" suggestion is simply wrong (as you have observed) in nearly all cases. So we should fix that.

@dahlbyk dahlbyk reopened this Feb 24, 2017
@dahlbyk dahlbyk added this to the v0.7.1 milestone Feb 24, 2017
@OswaldGlinkmeyer
Copy link
Author

OswaldGlinkmeyer commented Feb 24, 2017

Yes, I did install via chocolatey. Originally (a few years ago), I followed the instructions at https://mva.microsoft.com/en-us/training-courses/using-git-with-visual-studio-2013-jump-start-8306?l=WGG4QtYy_8604984382

Just to further fill in how I got here: What started the notion to upgrade posh-git is that I found that git and posh-git were not working, having not used them in several months. So I went to posh-git and saw the chocolately instructions, and remembered that's how I originally installed. I had to reinstall chocolatey because it wasn't working correctly. After I got chocolatey back working, I then installed using choco install poshgit. At that point, upon first running Powershell, I see the yellow error message mentioned.

@dahlbyk
Copy link
Owner

dahlbyk commented Feb 24, 2017

Thanks for the detail. There's a good chance you still had the old profile.example.ps1 line in your $PROFILE, so the new choco install poshgit would have updated it to the new path.

@dahlbyk
Copy link
Owner

dahlbyk commented Feb 25, 2017

Started working on improving this experience: #444

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

No branches or pull requests

3 participants