Skip to content

Commit

Permalink
#277: implemented requested changes
Browse files Browse the repository at this point in the history
moved ProcessMode to constant
changed ProcessMode from DEFAULT_CAPTURE to DEFAULT
  • Loading branch information
jan-vcapgemini committed Apr 5, 2024
1 parent 32e0472 commit 6278317
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions cli/src/main/java/com/devonfw/tools/ide/context/GitContextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
public class GitContextImpl implements GitContext {
private static final Duration GIT_PULL_CACHE_DELAY_MILLIS = Duration.ofMillis(30 * 60 * 1000);

;

private final IdeContext context;

private final ProcessContext processContext;

private final ProcessMode PROCESS_MODE = ProcessMode.DEFAULT;

/**
* @param context the {@link IdeContext context}.
*/
Expand Down Expand Up @@ -104,7 +104,7 @@ public void pullOrClone(String gitRepoUrl, String branch, Path targetRepository)

if (Files.isDirectory(targetRepository.resolve(".git"))) {
// checks for remotes
ProcessResult result = this.processContext.addArg("remote").run(ProcessMode.DEFAULT_CAPTURE);
ProcessResult result = this.processContext.addArg("remote").run(PROCESS_MODE);
List<String> remotes = result.getOut();
if (remotes.isEmpty()) {
String message = targetRepository
Expand Down Expand Up @@ -166,14 +166,14 @@ public void clone(GitUrl gitRepoUrl, Path targetRepository) {
this.processContext.addArg("-q");
}
this.processContext.addArgs("--recursive", gitRepoUrl.url(), "--config", "core.autocrlf=false", ".");
result = this.processContext.run(ProcessMode.DEFAULT_CAPTURE);
result = this.processContext.run(PROCESS_MODE);
if (!result.isSuccessful()) {
this.context.warning("Git failed to clone {} into {}.", parsedUrl, targetRepository);
}
String branch = gitRepoUrl.branch();
if (branch != null) {
this.processContext.addArgs("checkout", branch);
result = this.processContext.run(ProcessMode.DEFAULT_CAPTURE);
result = this.processContext.run(PROCESS_MODE);
if (!result.isSuccessful()) {
this.context.warning("Git failed to checkout to branch {}", branch);
}
Expand All @@ -189,7 +189,7 @@ public void pull(Path targetRepository) {
this.processContext.directory(targetRepository);
ProcessResult result;
// pull from remote
result = this.processContext.addArg("--no-pager").addArg("pull").run(ProcessMode.DEFAULT_CAPTURE);
result = this.processContext.addArg("--no-pager").addArg("pull").run(PROCESS_MODE);

if (!result.isSuccessful()) {
Map<String, String> remoteAndBranchName = retrieveRemoteAndBranchName();
Expand All @@ -202,7 +202,7 @@ public void pull(Path targetRepository) {
private Map<String, String> retrieveRemoteAndBranchName() {

Map<String, String> remoteAndBranchName = new HashMap<>();
ProcessResult remoteResult = this.processContext.addArg("branch").addArg("-vv").run(ProcessMode.DEFAULT_CAPTURE);
ProcessResult remoteResult = this.processContext.addArg("branch").addArg("-vv").run(PROCESS_MODE);
List<String> remotes = remoteResult.getOut();
if (!remotes.isEmpty()) {
for (String remote : remotes) {
Expand Down Expand Up @@ -233,14 +233,14 @@ public void reset(Path targetRepository, String remoteName, String branchName) {
this.processContext.directory(targetRepository);
ProcessResult result;
// check for changed files
result = this.processContext.addArg("diff-index").addArg("--quiet").addArg("HEAD").run(ProcessMode.DEFAULT_CAPTURE);
result = this.processContext.addArg("diff-index").addArg("--quiet").addArg("HEAD").run(PROCESS_MODE);

if (!result.isSuccessful()) {
// reset to origin/master
context.warning("Git has detected modified files -- attempting to reset {} to '{}/{}'.", targetRepository,
remoteName, branchName);
result = this.processContext.addArg("reset").addArg("--hard").addArg(remoteName + "/" + branchName)
.run(ProcessMode.DEFAULT_CAPTURE);
.run(PROCESS_MODE);

if (!result.isSuccessful()) {
context.warning("Git failed to reset {} to '{}/{}'.", remoteName, branchName, targetRepository);
Expand All @@ -256,12 +256,12 @@ public void cleanup(Path targetRepository) {
ProcessResult result;
// check for untracked files
result = this.processContext.addArg("ls-files").addArg("--other").addArg("--directory").addArg("--exclude-standard")
.run(ProcessMode.DEFAULT_CAPTURE);
.run(PROCESS_MODE);

if (!result.getOut().isEmpty()) {
// delete untracked files
context.warning("Git detected untracked files in {} and is attempting a cleanup.", targetRepository);
result = this.processContext.addArg("clean").addArg("-df").run(ProcessMode.DEFAULT_CAPTURE);
result = this.processContext.addArg("clean").addArg("-df").run(PROCESS_MODE);

if (!result.isSuccessful()) {
context.warning("Git failed to clean the repository {}.", targetRepository);
Expand Down

0 comments on commit 6278317

Please sign in to comment.