Skip to content

Commit 5e6d79c

Browse files
#277: fixed working directory not being updated
remove initializeProcessContext method added initialization of working directory directly to git commands moved GIT_TERMINAL_PROMPT env var to constructor
1 parent b2444c5 commit 5e6d79c

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

cli/src/main/java/com/devonfw/tools/ide/context/GitContextImpl.java

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ public class GitContextImpl implements GitContext {
3030

3131
private final IdeContext context;
3232

33-
private ProcessContext processContext;
33+
private final ProcessContext processContext;
3434

3535
/**
3636
* @param context the {@link IdeContext context}.
3737
*/
3838
public GitContextImpl(IdeContext context) {
3939

4040
this.context = context;
41-
41+
this.processContext = this.context.newProcess().executable("git").withEnvVar("GIT_TERMINAL_PROMPT", "0");
4242
}
4343

4444
@Override
@@ -102,7 +102,6 @@ public void pullOrClone(String gitRepoUrl, String branch, Path targetRepository)
102102
throw new IllegalArgumentException("Invalid git URL '" + gitRepoUrl + "'!");
103103
}
104104

105-
initializeProcessContext(targetRepository);
106105
if (Files.isDirectory(targetRepository.resolve(".git"))) {
107106
// checks for remotes
108107
ProcessResult result = this.processContext.addArg("remote").run(ProcessMode.DEFAULT_CAPTURE);
@@ -128,8 +127,8 @@ public void pullOrClone(String gitRepoUrl, String branch, Path targetRepository)
128127
* Handles errors which occurred during git pull.
129128
*
130129
* @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.
133132
* @param result the {@link ProcessResult} to evaluate.
134133
*/
135134
private void handleErrors(Path targetRepository, ProcessResult result) {
@@ -142,8 +141,8 @@ private void handleErrors(Path targetRepository, ProcessResult result) {
142141
} else {
143142
this.context.error(message);
144143
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.");
147146
} else {
148147
this.context.error(
149148
"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) {
153152
}
154153
}
155154

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-
171155
@Override
172156
public void clone(GitUrl gitRepoUrl, Path targetRepository) {
173157

174158
URL parsedUrl = gitRepoUrl.parseUrl();
175-
initializeProcessContext(targetRepository);
159+
this.processContext.directory(targetRepository);
176160
ProcessResult result;
177161
if (!this.context.isOffline()) {
178162
this.context.getFileAccess().mkdirs(targetRepository);
@@ -202,7 +186,7 @@ public void clone(GitUrl gitRepoUrl, Path targetRepository) {
202186
@Override
203187
public void pull(Path targetRepository) {
204188

205-
initializeProcessContext(targetRepository);
189+
this.processContext.directory(targetRepository);
206190
ProcessResult result;
207191
// pull from remote
208192
result = this.processContext.addArg("--no-pager").addArg("pull").run(ProcessMode.DEFAULT_CAPTURE);
@@ -246,7 +230,7 @@ private Map<String, String> retrieveRemoteAndBranchName() {
246230
@Override
247231
public void reset(Path targetRepository, String remoteName, String branchName) {
248232

249-
initializeProcessContext(targetRepository);
233+
this.processContext.directory(targetRepository);
250234
ProcessResult result;
251235
// check for changed files
252236
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) {
268252
@Override
269253
public void cleanup(Path targetRepository) {
270254

271-
initializeProcessContext(targetRepository);
255+
this.processContext.directory(targetRepository);
272256
ProcessResult result;
273257
// check for untracked files
274258
result = this.processContext.addArg("ls-files").addArg("--other").addArg("--directory").addArg("--exclude-standard")

0 commit comments

Comments
 (0)