@@ -30,15 +30,15 @@ public class GitContextImpl implements GitContext {
30
30
31
31
private final IdeContext context ;
32
32
33
- private ProcessContext processContext ;
33
+ private final ProcessContext processContext ;
34
34
35
35
/**
36
36
* @param context the {@link IdeContext context}.
37
37
*/
38
38
public GitContextImpl (IdeContext context ) {
39
39
40
40
this .context = context ;
41
-
41
+ this . processContext = this . context . newProcess (). executable ( "git" ). withEnvVar ( "GIT_TERMINAL_PROMPT" , "0" );
42
42
}
43
43
44
44
@ Override
@@ -102,7 +102,6 @@ public void pullOrClone(String gitRepoUrl, String branch, Path targetRepository)
102
102
throw new IllegalArgumentException ("Invalid git URL '" + gitRepoUrl + "'!" );
103
103
}
104
104
105
- initializeProcessContext (targetRepository );
106
105
if (Files .isDirectory (targetRepository .resolve (".git" ))) {
107
106
// checks for remotes
108
107
ProcessResult result = this .processContext .addArg ("remote" ).run (ProcessMode .DEFAULT_CAPTURE );
@@ -128,8 +127,8 @@ public void pullOrClone(String gitRepoUrl, String branch, Path targetRepository)
128
127
* Handles errors which occurred during git pull.
129
128
*
130
129
* @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
131
- * It is not the parent directory where git will by default create a sub-folder by default on clone but the * final
132
- * folder that will contain the ".git" subfolder.
130
+ * It is not the parent directory where git will by default create a sub-folder by default on clone but the *
131
+ * final folder that will contain the ".git" subfolder.
133
132
* @param result the {@link ProcessResult} to evaluate.
134
133
*/
135
134
private void handleErrors (Path targetRepository , ProcessResult result ) {
@@ -142,8 +141,8 @@ private void handleErrors(Path targetRepository, ProcessResult result) {
142
141
} else {
143
142
this .context .error (message );
144
143
if (this .context .isOnline ()) {
145
- this .context . error (
146
- "See above error for details. If you have local changes, please stash or revert and retry." );
144
+ this .context
145
+ . error ( "See above error for details. If you have local changes, please stash or revert and retry." );
147
146
} else {
148
147
this .context .error (
149
148
"It seems you are offline - please ensure Internet connectivity and retry or activate offline mode (-o or --offline)." );
@@ -153,26 +152,11 @@ private void handleErrors(Path targetRepository, ProcessResult result) {
153
152
}
154
153
}
155
154
156
- /**
157
- * Lazily initializes the {@link ProcessContext}.
158
- *
159
- * @param targetRepository the {@link Path} to the target folder where the git repository should be cloned or pulled.
160
- * It is not the parent directory where git will by default create a sub-folder by default on clone but the * final
161
- * folder that will contain the ".git" subfolder.
162
- */
163
- private void initializeProcessContext (Path targetRepository ) {
164
-
165
- if (this .processContext == null ) {
166
- this .processContext = this .context .newProcess ().directory (targetRepository ).executable ("git" )
167
- .withEnvVar ("GIT_TERMINAL_PROMPT" , "0" );
168
- }
169
- }
170
-
171
155
@ Override
172
156
public void clone (GitUrl gitRepoUrl , Path targetRepository ) {
173
157
174
158
URL parsedUrl = gitRepoUrl .parseUrl ();
175
- initializeProcessContext (targetRepository );
159
+ this . processContext . directory (targetRepository );
176
160
ProcessResult result ;
177
161
if (!this .context .isOffline ()) {
178
162
this .context .getFileAccess ().mkdirs (targetRepository );
@@ -202,7 +186,7 @@ public void clone(GitUrl gitRepoUrl, Path targetRepository) {
202
186
@ Override
203
187
public void pull (Path targetRepository ) {
204
188
205
- initializeProcessContext (targetRepository );
189
+ this . processContext . directory (targetRepository );
206
190
ProcessResult result ;
207
191
// pull from remote
208
192
result = this .processContext .addArg ("--no-pager" ).addArg ("pull" ).run (ProcessMode .DEFAULT_CAPTURE );
@@ -246,7 +230,7 @@ private Map<String, String> retrieveRemoteAndBranchName() {
246
230
@ Override
247
231
public void reset (Path targetRepository , String remoteName , String branchName ) {
248
232
249
- initializeProcessContext (targetRepository );
233
+ this . processContext . directory (targetRepository );
250
234
ProcessResult result ;
251
235
// check for changed files
252
236
result = this .processContext .addArg ("diff-index" ).addArg ("--quiet" ).addArg ("HEAD" ).run (ProcessMode .DEFAULT_CAPTURE );
@@ -268,7 +252,7 @@ public void reset(Path targetRepository, String remoteName, String branchName) {
268
252
@ Override
269
253
public void cleanup (Path targetRepository ) {
270
254
271
- initializeProcessContext (targetRepository );
255
+ this . processContext . directory (targetRepository );
272
256
ProcessResult result ;
273
257
// check for untracked files
274
258
result = this .processContext .addArg ("ls-files" ).addArg ("--other" ).addArg ("--directory" ).addArg ("--exclude-standard" )
0 commit comments