@@ -39,46 +39,103 @@ protected void Initialize()
39
39
Logging . TracingEnabled = UserSettings . Get ( Constants . TraceLoggingKey , false ) ;
40
40
ProcessManager = new ProcessManager ( Environment , Platform . GitEnvironment , CancellationToken ) ;
41
41
Platform . Initialize ( ProcessManager , TaskManager ) ;
42
- GitClient = new GitClient ( Environment , ProcessManager , TaskManager ) ;
42
+ ITaskManager taskManager = TaskManager ;
43
+ GitClient = new GitClient ( Environment , ProcessManager , taskManager . Token ) ;
43
44
SetupMetrics ( ) ;
44
45
}
45
46
46
47
public void Run ( bool firstRun )
47
48
{
48
- new ActionTask ( SetupGit ( ) )
49
+ Logger . Trace ( "Run - CurrentDirectory {0}" , NPath . CurrentDirectory ) ;
50
+
51
+ SetupGit ( )
49
52
. Then ( RestartRepository )
50
53
. ThenInUI ( InitializeUI )
51
54
. Start ( ) ;
52
55
}
53
56
54
- private async Task SetupGit ( )
57
+ private ITask SetupGit ( )
55
58
{
56
- Logger . Trace ( "Run - CurrentDirectory {0}" , NPath . CurrentDirectory ) ;
59
+ return BuildDetermineGitPathTask ( )
60
+ . Then ( ( b , path ) => {
61
+ Logger . Trace ( "Setting GitExecutablePath: {0}" , path ) ;
62
+ Environment . GitExecutablePath = path ;
63
+ } )
64
+ . Then ( ( ) => {
65
+ if ( Environment . GitExecutablePath == null )
66
+ {
67
+ if ( Environment . IsWindows )
68
+ {
69
+ GitClient . GetConfig ( "credential.helper" , GitConfigSource . Global ) . Then (
70
+ ( b , credentialHelper ) => {
71
+ if ( ! string . IsNullOrEmpty ( credentialHelper ) )
72
+ {
73
+ Logger . Trace ( "Windows CredentialHelper: {0}" , credentialHelper ) ;
74
+ }
75
+ else
76
+ {
77
+ Logger . Warning (
78
+ "No Windows CredentialHeloper found: Setting to wincred" ) ;
79
+
80
+ GitClient . SetConfig ( "credential.helper" , "wincred" , GitConfigSource . Global ) . Start ( ) . Wait ( ) ;
81
+ }
82
+ } ) ;
83
+ }
84
+ }
85
+ } )
86
+ . ThenInUI ( ( ) => {
87
+ Environment . User . Initialize ( GitClient ) ;
88
+ } ) ;
89
+ }
57
90
58
- if ( Environment . GitExecutablePath == null )
91
+ private TaskBase < NPath > BuildDetermineGitPathTask ( )
92
+ {
93
+ TaskBase < NPath > determinePath = new FuncTask < NPath > ( CancellationToken , ( ) => {
94
+ if ( Environment . GitExecutablePath != null )
95
+ {
96
+ return Environment . GitExecutablePath ;
97
+ }
98
+
99
+ var gitExecutablePath = SystemSettings . Get ( Constants . GitInstallPathKey ) ? . ToNPath ( ) ;
100
+ if ( gitExecutablePath != null && gitExecutablePath . FileExists ( ) )
101
+ {
102
+ Logger . Trace ( "Using git install path from settings" ) ;
103
+ return gitExecutablePath ;
104
+ }
105
+
106
+ return null ;
107
+ } ) ;
108
+
109
+ var environmentIsWindows = Environment . IsWindows ;
110
+ if ( environmentIsWindows )
59
111
{
60
- Environment . GitExecutablePath = await DetermineGitExecutablePath ( ) ;
112
+ var applicationDataPath = Environment . GetSpecialFolder ( System . Environment . SpecialFolder . LocalApplicationData ) . ToNPath ( ) ;
113
+ var installDetails = new PortableGitInstallDetails ( applicationDataPath , true ) ;
114
+ var installTask = new PortableGitInstallTask ( CancellationToken , Environment , installDetails ) ;
61
115
62
- Logger . Trace ( "Environment.GitExecutablePath \" {0}\" Exists:{1}" , Environment . GitExecutablePath , Environment . GitExecutablePath . FileExists ( ) ) ;
116
+ determinePath = determinePath . Then ( new ShortCircuitTask < NPath > ( CancellationToken , installTask ) ) ;
117
+ }
63
118
64
- if ( Environment . IsWindows )
65
- {
66
- var credentialHelper = await GitClient . GetConfig ( "credential.helper" , GitConfigSource . Global ) . StartAwait ( ) ;
119
+ if ( ! environmentIsWindows )
120
+ {
121
+ determinePath = determinePath . Then ( new ShortCircuitTask < NPath > ( CancellationToken , ( ) => {
122
+ var p = new NPath ( "/usr/local/bin/git" ) ;
67
123
68
- if ( ! string . IsNullOrEmpty ( credentialHelper ) )
124
+ if ( p . FileExists ( ) )
69
125
{
70
- Logger . Trace ( "Windows CredentialHelper: {0}" , credentialHelper ) ;
126
+ return p ;
71
127
}
72
- else
73
- {
74
- Logger . Warning ( "No Windows CredentialHeloper found: Setting to wincred" ) ;
75
128
76
- await GitClient . SetConfig ( "credential.helper" , "wincred" , GitConfigSource . Global ) . StartAwait ( ) ;
77
- }
78
- }
129
+ return null ;
130
+ } ) ) ;
131
+
132
+ var findExecTask = new FindExecTask ( "git" , CancellationToken ) ;
133
+ findExecTask . Configure ( ProcessManager ) ;
134
+
135
+ determinePath = determinePath . Then ( new ShortCircuitTask < NPath > ( CancellationToken , findExecTask ) ) ;
79
136
}
80
137
81
- Environment . User . Initialize ( GitClient ) ;
138
+ return determinePath ;
82
139
}
83
140
84
141
public ITask InitializeRepository ( )
@@ -136,27 +193,6 @@ public void RestartRepository()
136
193
}
137
194
}
138
195
139
- private async Task < NPath > DetermineGitExecutablePath ( ProgressReport progress = null )
140
- {
141
- var gitExecutablePath = SystemSettings . Get ( Constants . GitInstallPathKey ) ? . ToNPath ( ) ;
142
- if ( gitExecutablePath != null && gitExecutablePath . FileExists ( ) )
143
- {
144
- Logger . Trace ( "Using git install path from settings" ) ;
145
- return gitExecutablePath ;
146
- }
147
-
148
- var gitInstaller = new GitInstaller ( Environment , CancellationToken ) ;
149
- var setupDone = await gitInstaller . SetupIfNeeded ( progress ? . Percentage , progress ? . Remaining ) ;
150
- if ( setupDone )
151
- {
152
- Logger . Trace ( "Setup performed using new path" ) ;
153
- return gitInstaller . GitExecutablePath ;
154
- }
155
-
156
- Logger . Trace ( "Finding git install path" ) ;
157
- return await GitClient . FindGitInstallation ( ) . SafeAwait ( ) ;
158
- }
159
-
160
196
protected void SetupMetrics ( string unityVersion , bool firstRun )
161
197
{
162
198
Logger . Trace ( "Setup metrics" ) ;
0 commit comments