11using GitHub . Logging ;
22using System ;
3+ using System . Collections . Generic ;
34using System . Diagnostics ;
45
56namespace GitHub . Unity
@@ -17,58 +18,86 @@ public ProcessEnvironment(IEnvironment environment)
1718
1819 public void Configure ( ProcessStartInfo psi , NPath workingDirectory , bool dontSetupGit = false )
1920 {
20- Guard . ArgumentNotNull ( psi , "psi" ) ;
21-
2221 psi . WorkingDirectory = workingDirectory ;
2322 psi . EnvironmentVariables [ "HOME" ] = NPath . HomeDirectory ;
2423 psi . EnvironmentVariables [ "TMP" ] = psi . EnvironmentVariables [ "TEMP" ] = NPath . SystemTemp ;
24+
25+ var path = Environment . Path ;
2526 psi . EnvironmentVariables [ "GHU_WORKINGDIR" ] = workingDirectory ;
26- psi . EnvironmentVariables [ "PATH" ] = Environment . Path ;
27- psi . EnvironmentVariables [ "GHU_FULLPATH" ] = Environment . Path ;
2827
29- // if we don't know where git is, then there's nothing else to configure
30- if ( ! Environment . GitInstallPath . IsInitialized || dontSetupGit )
28+ if ( dontSetupGit )
29+ {
30+ psi . EnvironmentVariables [ "GHU_FULLPATH" ] = path ;
31+ psi . EnvironmentVariables [ "PATH" ] = path ;
3132 return ;
32-
33- var httpProxy = Environment . GetEnvironmentVariable ( "HTTP_PROXY" ) ;
34- if ( ! String . IsNullOrEmpty ( httpProxy ) )
35- psi . EnvironmentVariables [ "HTTP_PROXY" ] = httpProxy ;
36-
37- var httpsProxy = Environment . GetEnvironmentVariable ( "HTTPS_PROXY" ) ;
38- if ( ! String . IsNullOrEmpty ( httpsProxy ) )
39- psi . EnvironmentVariables [ "HTTPS_PROXY" ] = httpsProxy ;
40-
41- //TODO: Remove with Git LFS Locking becomes standard
42- psi . EnvironmentVariables [ "GITLFSLOCKSENABLED" ] = "1" ;
33+ }
34+
35+ Guard . ArgumentNotNull ( psi , "psi" ) ;
36+
37+ var pathEntries = new List < string > ( ) ;
38+ string separator = Environment . IsWindows ? ";" : ":" ;
4339
44- if ( Environment . IsWindows )
40+ if ( Environment . GitInstallPath . IsInitialized )
4541 {
46- // We need to essentially fake up what git-cmd.bat does
4742 var gitPathRoot = Environment . GitInstallPath ;
48-
43+ var gitExecutableDir = Environment . GitExecutablePath . Parent ; // original path to git (might be different from install path if it's a symlink)
44+
4945 var baseExecPath = gitPathRoot ;
50- if ( baseExecPath . DirectoryExists ( "mingw32" ) )
51- baseExecPath = baseExecPath . Combine ( "mingw32" ) ;
52- else
53- baseExecPath = baseExecPath . Combine ( "mingw64" ) ;
54- var binPath = baseExecPath . Combine ( "bin" ) ;
55-
46+ var binPath = baseExecPath ;
47+ if ( Environment . IsWindows )
48+ {
49+ if ( baseExecPath . DirectoryExists ( "mingw32" ) )
50+ baseExecPath = baseExecPath . Combine ( "mingw32" ) ;
51+ else
52+ baseExecPath = baseExecPath . Combine ( "mingw64" ) ;
53+ binPath = baseExecPath . Combine ( "bin" ) ;
54+ }
55+
5656 var execPath = baseExecPath . Combine ( "libexec" , "git-core" ) ;
5757 if ( ! execPath . DirectoryExists ( ) )
5858 execPath = NPath . Default ;
5959
60- var userPath = @"C:\windows\system32;C:\windows" ;
61- var path = $ "{ gitPathRoot } \\ cmd;{ gitPathRoot } \\ usr\\ bin;{ execPath } ;{ binPath } ";
62-
60+ if ( Environment . IsWindows )
61+ {
62+ pathEntries . AddRange ( new [ ] { gitPathRoot . Combine ( "cmd" ) . ToString ( ) , gitPathRoot . Combine ( "usr" , "bin" ) } ) ;
63+ }
64+ else
65+ {
66+ pathEntries . Add ( gitExecutableDir . ToString ( ) ) ;
67+ }
68+ if ( execPath . IsInitialized )
69+ pathEntries . Add ( execPath ) ;
70+ pathEntries . Add ( binPath ) ;
71+
6372 if ( execPath . IsInitialized )
6473 psi . EnvironmentVariables [ "GIT_EXEC_PATH" ] = execPath . ToString ( ) ;
65-
66- psi . EnvironmentVariables [ "PATH" ] = path ;
67- psi . EnvironmentVariables [ "GHU_FULLPATH" ] = path ;
68-
69- psi . EnvironmentVariables [ "PLINK_PROTOCOL" ] = "ssh" ;
70- psi . EnvironmentVariables [ "TERM" ] = "msys" ;
7174 }
75+
76+ if ( Environment . GitLfsInstallPath . IsInitialized && Environment . GitInstallPath != Environment . GitLfsInstallPath )
77+ {
78+ pathEntries . Add ( Environment . GitLfsInstallPath ) ;
79+ }
80+
81+ pathEntries . Add ( "END" ) ;
82+
83+ path = String . Join ( separator , pathEntries . ToArray ( ) ) + separator + path ;
84+
85+ psi . EnvironmentVariables [ "GHU_FULLPATH" ] = path ;
86+ psi . EnvironmentVariables [ "PATH" ] = path ;
87+
88+ //TODO: Remove with Git LFS Locking becomes standard
89+ psi . EnvironmentVariables [ "GITLFSLOCKSENABLED" ] = "1" ;
90+
91+ psi . EnvironmentVariables [ "PLINK_PROTOCOL" ] = "ssh" ;
92+ psi . EnvironmentVariables [ "TERM" ] = "msys" ;
93+
94+ var httpProxy = Environment . GetEnvironmentVariable ( "HTTP_PROXY" ) ;
95+ if ( ! String . IsNullOrEmpty ( httpProxy ) )
96+ psi . EnvironmentVariables [ "HTTP_PROXY" ] = httpProxy ;
97+
98+ var httpsProxy = Environment . GetEnvironmentVariable ( "HTTPS_PROXY" ) ;
99+ if ( ! String . IsNullOrEmpty ( httpsProxy ) )
100+ psi . EnvironmentVariables [ "HTTPS_PROXY" ] = httpsProxy ;
72101 }
73102 }
74103}
0 commit comments