Skip to content

posh-git.psm1 sets $Env:HOME, which screws with Emacs #153

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

Closed
mrcslws opened this issue Aug 25, 2014 · 6 comments
Closed

posh-git.psm1 sets $Env:HOME, which screws with Emacs #153

mrcslws opened this issue Aug 25, 2014 · 6 comments
Assignees

Comments

@mrcslws
Copy link

mrcslws commented Aug 25, 2014

Emacs reads your .emacs from %HOME%\.emacs. Documentation: https://www.gnu.org/software/emacs/manual/html_node/emacs/Windows-HOME.html

If %HOME% isn't set, then it uses %APPDATA%\.emacs.

posh-git.psm1 specifically sets $Env:HOME.

So using posh-git causes Emacs to suddenly start loading the .emacs from a different location, which is really confusing. It took a while before I tracked down why Emacs was misbehaving, and longer before I tracked the issue down to posh-git.

(Otherwise posh-git has been very helpful!)

@dahlbyk
Copy link
Owner

dahlbyk commented Aug 27, 2014

The explicit setting of %HOME% was copied long ago from git.cmd, which appears to have been superseded by a git.exe wrapper in newer versions.

As long as we're using cmd\git.exe instead of bin\git.exe we should be fine to drop %HOME% manipulation from posh-git. Maybe the best option would be to add a warning if PowerShell is finding bin\git.exe?

@dahlbyk
Copy link
Owner

dahlbyk commented May 14, 2015

Proposal:

  1. If git resolves to cmd\git.exe, we're good.
  2. If git resolves as git.cmd, set %HOME% and warn with suggestion to upgrade Git.
  3. If git resolves as bin\git.exe, set %HOME% and warn with suggestion to adjustPATHand/or aliases to checkcmd` first.

@PetRose
Copy link

PetRose commented Aug 25, 2015

I have a somewhat related problem, during the Chef Learning exercise (chef-dk) and following this guideline here:
https://help.github.com/articles/set-up-git/#platform-windows
trying to set up Github Windows, on a fresh Win 8.1 (64bit), without Chocolatey (isn´t suggested during the install guidelines).
I get a "WARNING: git command could not be found. Please create an alias or add it to your PATH."
when I spin off a Git Shell from GIT. It seems theres several issues not being taken care of, during Github Windows install:

  1. Powershell User profile, not being amended with proper Git settings:
    %HOMEDRIVE%%HOMEPATH%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
    such as adding Git executables (or Command) to the %PATH% environment:
    %LOCALAPPDATA%\GitHub\shell.ps1
    and possibly the Module path too. I can read the 'shell.ps1' saying a few of the commands inside this would not be needed to run manually, its taken care of during install. Obviously not for me.

  2. The git executables (and commands) seems scattered across %LOCALAPPDATA% with weird foldernames (I a newbie, sure). The command 'dir C:\git.exe /s' on root drive, gives me these (my substition of LOCALAPPDATA variable inserted)
    Directory of
    %LOCALAPPDATA%\GitHub\PortableGit_c2ba306e536fdf878271f7fe636a147ff37326ad\bin
    19-12-2014 05:57 1.503.744 git.exe
    Directory of
    %LOCALAPPDATA%\GitHub\PortableGit_c2ba306e536fdf878271f7fe636a147ff37326ad\cmd
    19-12-2014 05:03 8.704 git.exe
    Directory of
    %LOCALAPPDATA%\GitHub\PortableGit_c2ba306e536fdf878271f7fe636a147ff37326ad\libexec\git-core
    19-12-2014 05:57 1.503.744 git.exe
    and no one of these folders are set up in PATH (of PS Profile), hence the cause of my problem: Git command could not be found.

Should I raise another Issue item ? And in the meantime, which one of these should I add to my PS Profile ?

@dahlbyk
Copy link
Owner

dahlbyk commented Aug 25, 2015

@PetRose GitHub for Windows only tries to set up its own "Git Shell" with its own $PROFILE; it doesn't (can't, perhaps?) touch your default $PROFILE. The "weird folder names" are an implementation detail that the team tries to hide from you to provide seamless Git & posh-git upgrades.

To mimic Git Shell in your default $PROFILE, add:

# Load posh-git example profile
. (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1")
. (Resolve-Path "$env:github_posh_git\profile.example.ps1")

@ammeep @shiftkey is there "official" guidance on usage of shell.ps1 somewhere, or is it still "use at your own risk"?

@shiftkey
Copy link
Contributor

@dahlbyk it's very specific to GitHub Desktop, but if you reference it like that it should stay in sync as updates come down.

@PetRose GitHub Desktop doesn't change the user or system environment variables (in case you already have Git installed) and so all the heavy-lifting for setting up the environment is done through the Git Shell shortcut. If you really don't want to use Git Shell, I'd suggest @dahlbyk's workaround above.

Alternatively, you could install Git for Windows if you're only interested in having the command line tools available (that should address your original issue, and have the Git tools available at a known location).

@dahlbyk
Copy link
Owner

dahlbyk commented Jan 6, 2017

I'm going to go ahead and close this since it doesn't seem to be an issue for the vast majority of users.

That said, I wouldn't be opposed to adding a note to the README about the module setting $Env:HOME.

@dahlbyk dahlbyk closed this as completed Jan 6, 2017
rkeithhill added a commit that referenced this issue Dec 1, 2019
@rkeithhill rkeithhill self-assigned this Dec 5, 2019
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

5 participants