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

HOME environment variable not recognized #2293

Closed
patricktokeeffe opened this issue Mar 18, 2014 · 7 comments
Closed

HOME environment variable not recognized #2293

patricktokeeffe opened this issue Mar 18, 2014 · 7 comments

Comments

@patricktokeeffe
Copy link

When I started GitExtensions 2.47.3 this morning, it prompted me to find my .gitconfig file:
startup_error

But I do have a HOME environment variable set and it does contain a .gitconfig:
env_vars

At first, pressing 'Yes' to have GE locate the folder caused it to create a new .gitconfig in the directory shown in the dialog (C:\...\pokeeffe.CEE). After a few iterations deleting that new file, exiting GE and restarting, it finally caught my intended .gitconfig:
located

But it still does not recognize my HOME environment variable:
confirm

Is this behavior by design? I do see a comment in #685 suggesting the system HOME env var is ignored in favor of per-user HOME vars.

@KindDragon
Copy link
Contributor

Changes from #685 will only works if you set HOME for user (not for system)

@patricktokeeffe
Copy link
Author

Ok. That seems a little silly. I propose the behavior be changed to include system-wide HOME. It's not uncommon in corporate environments (e.g. network profiles) for this env. var. to be set at the system level. Maybe it gets lower priority than user HOME but, if set, is still preferred to HOMEDRIVE``HOMEPATH.

@patricktokeeffe
Copy link
Author

Could the issue lie in the GitCommandHelpers class?

GitCommands/Git/GitCommandHelpers.cs:

public static void SetEnvironmentVariable(bool reload = false)
{
    string path = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process);
    if (!string.IsNullOrEmpty(AppSettings.GitBinDir) && !path.Contains(AppSettings.GitBinDir))
        Environment.SetEnvironmentVariable("PATH", string.Concat(path, ";", AppSettings.GitBinDir), EnvironmentVariableTarget.Process);

    if (!string.IsNullOrEmpty(AppSettings.CustomHomeDir))
    {
        Environment.SetEnvironmentVariable(
            "HOME",
            AppSettings.CustomHomeDir);
        return;
    }

    if (AppSettings.UserProfileHomeDir)
    {
        Environment.SetEnvironmentVariable(
            "HOME",
            Environment.GetEnvironmentVariable("USERPROFILE"));
        return;
    }

    if (reload)
    {
        Environment.SetEnvironmentVariable(
            "HOME",
            UserHomeDir);
    }

    //Default!
    Environment.SetEnvironmentVariable("HOME", GetDefaultHomeDir());
    //to prevent from leaking processes see issue #1092 for details
    Environment.SetEnvironmentVariable("TERM", "msys");
    string sshAskPass = Path.Combine(AppSettings.GetInstallDir(), @"GitExtSshAskPass.exe");
    if (EnvUtils.RunningOnWindows())
    {
        if (File.Exists(sshAskPass))
            Environment.SetEnvironmentVariable("SSH_ASKPASS", sshAskPass);
    }
    else if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SSH_ASKPASS")))
        Environment.SetEnvironmentVariable("SSH_ASKPASS", "ssh-askpass");
}

^ At least on my system, USERPROFILE is the same as HOMEDRIVE``HOMEPATH.

public static string GetHomeDir()
{
    return Environment.GetEnvironmentVariable("HOME") ?? "";
}

public static string GetDefaultHomeDir()
{
    if (!string.IsNullOrEmpty(UserHomeDir))
        return UserHomeDir;

    if (EnvUtils.RunningOnWindows())
    {
        return WindowsDefaultHomeDir;
    }
    return Environment.GetFolderPath(Environment.SpecialFolder.Personal);
}

private static string WindowsDefaultHomeDir
{
    get
    {
        if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HOMEDRIVE")))
        {
            string homePath = Environment.GetEnvironmentVariable("HOMEDRIVE");
            homePath += Environment.GetEnvironmentVariable("HOMEPATH");
            return homePath;
        }
        return Environment.GetEnvironmentVariable("USERPROFILE");
    }
}

^ Should WindowsDefaultHomeDir check for HOME before using HOMEDRIVE``HOMEPATH? Calling GetDefaultHomeDir() before/instead of GetHomeDir() would result in the behavior I reported (I think, maybe).

@KindDragon
Copy link
Contributor

Should WindowsDefaultHomeDir check for HOME before using HOMEDRIVEHOMEPATH?

I don't know. It's very old code.

Calling GetDefaultHomeDir() before/instead of GetHomeDir() would result in the behavior I reported (I think, maybe).

We can't, because SetEnvironmentVariable() set "HOME" variable and can be called several times.

@spdr870
Copy link
Member

spdr870 commented Aug 14, 2014

The environment variable USERPROFILE is not the same as HOMEDRIVE HOMEPATH. On my system they are different.
echo %USERPROFILE% -> c:\users\hwesthuis
echo %HOMEDRIVE% -> U:
echo %HOMEPATH% -> \

I wrote the code above to have the same behaviour as the default msysgit behaviour.

@KindDragon
Copy link
Contributor

@spdr870 Why GitExt use only user level %HOME%?

private static readonly string UserHomeDir = Environment.GetEnvironmentVariable("HOME", EnvironmentVariableTarget.User);

@spdr870
Copy link
Member

spdr870 commented Aug 15, 2014

Not sure. I guess the process level environment variable could not be used, because it is set by gitext. The machine level variable can be used. 

-------- Oorspronkelijk bericht --------
Van: Arkadiy Shapkin notifications@github.com
Datum:08-14-2014 21:26 (GMT+01:00)
Aan: gitextensions/gitextensions gitextensions@noreply.github.com
Cc: Henk Westhuis henk.westhuis@gmail.com
Onderwerp: Re: [gitextensions] HOME environment variable not recognized (#2293)

@spdr870 Why GitExt use only user level %HOME%?

private static readonly string UserHomeDir = Environment.GetEnvironmentVariable("HOME", EnvironmentVariableTarget.User);

Reply to this email directly or view it on GitHub.

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

4 participants