Skip to content

Loading…

Added option to use environment variable for git executable #15

Closed
wants to merge 1 commit into from

2 participants

@erezak

"Git bash" recommended method of working is not putting git in path.
This commits adds the possiblity to use an environment variable pointing
to the git executable.
Also, the non-silent installation now shows clearer errors.

@erezak erezak Option for environment variable for git + errors
"Git bash" recommended method of working is *not* putting git in path.
This commits adds the possiblity to use an environment variable pointing
to the git executable.
Also, the non-silent installation now shows clearer errors.
0713c93
@anurse
Owner

Rather than an arbitrary environment variable, I'd rather have the install process accept the path to git as a parameter, so I'm doing that. I'm closing this PR since I've written the code to do it via an argument.

@anurse anurse closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 12, 2012
  1. @erezak

    Option for environment variable for git + errors

    erezak committed
    "Git bash" recommended method of working is *not* putting git in path.
    This commits adds the possiblity to use an environment variable pointing
    to the git executable.
    Also, the non-silent installation now shows clearer errors.
Showing with 25 additions and 33 deletions.
  1. +1 −32 README.md
  2. +24 −1 git-credential-winstore/Program.cs
View
33 README.md
@@ -1,32 +1 @@
-# Windows Credential Store for Git
-This application is a small helper app designed to follow the git credentials API as defined by the [Git Documentation](https://github.com/gitster/git-htmldocs/blob/master/technical/api-credentials.txt).
-## Installation
-
-1. Download the git-credential-winstore.exe file from the downloads section
-2. Run it (make sure you have git in your PATH)
-
-## FAQs
-
-### Why doesn't it work?
-Make sure you're running the latest version of msysgit. The credential API is fairly new. I've tested this on version 1.7.10.
-
-### Why doesn't it install?
-Make sure you're running with GIT on your PATH (perhaps by running from the GIT bash shell)
-
-### Where are you storing my credentials?
-This app just uses the existing Windows Credential Store to hold your credentials. You can see the stored credentials by going to Control Panel > User Accounts > Credential Manager and choosing "Windows Credentials". The entries starting "git:" are from git-credential-winstore.
-
-### I have another question?
-That's not a question.
-
-### But I actually have another question...
-Ok, you can email me at [andrew@andrewnurse.net](mailto:andrew@andrewnurse.net).
-
-## Special Thanks
-* [Paul Betts](http://paulbetts.org/) for creating our handy-dandy installer.
-* [Matt Wrock](https://github.com/mwrock) for adding a silent option to the installer.
-* [mattn](https://github.com/mattn) for adding support for Windows XP.
-* [Marc Brooks](https://github.com/IDisposable) for some readme tweaks.
-
-## License
-This code is Copyright Andrew Nurse and other contributors 2012. You are hereby granted a license to use the software and code under the terms of the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html)
+# Windows Credential Store for Git
View
25 git-credential-winstore/Program.cs
@@ -22,6 +22,8 @@ class Program
{ "erase", EraseCommand }
};
+ static String GIT_EXECUTABLE_ENVIRONMENT_VARIABLE = "GIT_EXECUTABLE";
+
static void Main(string[] args)
{
TryLaunchDebugger(ref args);
@@ -130,7 +132,28 @@ private static void InstallTheApp(bool silent)
var dest = new FileInfo(Environment.ExpandEnvironmentVariables(@"%AppData%\GitCredStore\git-credential-winstore.exe"));
File.Copy(Assembly.GetExecutingAssembly().Location, dest.FullName, true);
- Process.Start("git", string.Format("config --global credential.helper \"!'{0}'\"", dest.FullName));
+ var gitArguments = string.Format("config --global credential.helper \"!'{0}'\"", dest.FullName);
+
+ try {
+ Process.Start("git", gitArguments);
+ } catch (System.ComponentModel.Win32Exception e) {
+ // Running git failed - try the environment variable (sometimes git will not be in the path -
+ // e.g. when running git bash in recommended setting
+ var gitExecutablePath = System.Environment.GetEnvironmentVariable(GIT_EXECUTABLE_ENVIRONMENT_VARIABLE);
+ if (string.IsNullOrEmpty(gitExecutablePath)) {
+ MessageBox.Show("Git is not in path and environment variable " + GIT_EXECUTABLE_ENVIRONMENT_VARIABLE +
+ " is not set.", "No git executable found", MessageBoxButtons.OK);
+ } else {
+ try {
+ Process.Start(gitExecutablePath, gitArguments);
+ } catch (Exception e1) {
+ MessageBox.Show("Git is not in path and environment variable " + GIT_EXECUTABLE_ENVIRONMENT_VARIABLE +
+ " doesn't point to a correct git executable.", "No git executable found", MessageBoxButtons.OK);
+ }
+ }
+
+ }
+
}
static IEnumerable<Tuple<string, string>> GetCommand(IDictionary<string, string> args)
Something went wrong with that request. Please try again.