Skip to content

Commit

Permalink
Merge 2d7792a into 0e84aff
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-vcapgemini authored Jan 9, 2024
2 parents 0e84aff + 2d7792a commit 11f92fa
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
*/
public abstract class AbstractIdeContext implements IdeContext {

private static final String IDE_URLS_GIT = "https://github.com/devonfw/ide-urls.git";

private final Map<IdeLogLevel, IdeSubLogger> loggers;

private final Path ideHome;
Expand Down Expand Up @@ -177,10 +179,11 @@ public AbstractIdeContext(IdeLogLevel minLogLevel, Function<IdeLogLevel, IdeSubL
Path rootPath = Paths.get(root);
if (Files.isDirectory(rootPath)) {
if (!ideRootPath.equals(rootPath)) {
warning("Variable IDE_ROOT is set to '{}' but for your project '{}' would have been expected.");
ideRootPath = rootPath;
warning(
"Variable IDE_ROOT is set to '{}' but for your project '{}' the path '{}' would have been expected.",
root, this.ideHome.getFileName(), ideRootPath);
}
ideRootPath = this.ideHome.getParent();
ideRootPath = rootPath;
} else {
warning("Variable IDE_ROOT is not set to a valid directory '{}'." + root);
ideRootPath = null;
Expand Down Expand Up @@ -257,10 +260,7 @@ public String getMessageIdeHome() {
*/
public boolean isTest() {

if (isMock()) {
return true;
}
return false;
return isMock();
}

/**
Expand Down Expand Up @@ -487,7 +487,7 @@ public UrlMetadata getUrls() {

if (this.urlMetadata == null) {
if (!isTest()) {
gitPullOrClone(this.urlsPath, "https://github.com/devonfw/ide-urls.git");
gitPullOrClone(this.urlsPath, IDE_URLS_GIT, true);
}
this.urlMetadata = new UrlMetadata(this);
}
Expand Down Expand Up @@ -557,7 +557,7 @@ public boolean isOnline() {
try {
int timeout = 1000;
online = InetAddress.getByName("github.com").isReachable(timeout);
} catch (Exception e) {
} catch (Exception ignored) {

}
return online;
Expand Down Expand Up @@ -589,12 +589,11 @@ public DirectoryMerger getWorkspaceMerger() {
@Override
public ProcessContext newProcess() {

ProcessContext processContext = new ProcessContextImpl(this);
return processContext;
return new ProcessContextImpl(this);
}

@Override
public void gitPullOrClone(Path target, String gitRepoUrl) {
public void gitPullOrClone(Path target, String gitRepoUrl, boolean force) {

Objects.requireNonNull(target);
Objects.requireNonNull(gitRepoUrl);
Expand All @@ -606,12 +605,32 @@ public void gitPullOrClone(Path target, String gitRepoUrl) {
ProcessResult result = pc.addArg("remote").run(true);
List<String> remotes = result.getOut();
if (remotes.isEmpty()) {
String message = "This is a local git repo with no remote - if you did this for testing, you may continue...\n"
String message = target
+ " is a local git repository with no remote - if you did this for testing, you may continue...\n"
+ "Do you want to ignore the problem and continue anyhow?";
askToContinue(message);
} else {
pc.errorHandling(ProcessErrorHandling.WARNING);
result = pc.addArg("pull").run(false);
if (isOnline()) {
result = pc.addArg("fetch").addArg("origin").addArg("master").run(false);
if (!result.isSuccessful()) {
warning("Git failed to fetch from origin master.");
}
result = pc.addArg("pull").addArg("--non-interactive").addArg("--no-pager").run(false);
if (!result.isSuccessful()) {
warning("Git failed to pull from origin master.");
}
}
if (force) {
result = pc.addArg("reset").addArg("--hard").addArg("origin/master").run(false);
if (!result.isSuccessful()) {
warning("Git failed to reset: {} to 'origin/master'.", target);
}
result = pc.addArg("clean").addArg("-df").run(false);
if (!result.isSuccessful()) {
warning("Git failed to clean the repository: {}.", target);
}
}
if (!result.isSuccessful()) {
String message = "Failed to update git repository at " + target;
if (this.offlineMode) {
Expand Down Expand Up @@ -641,7 +660,6 @@ public void gitPullOrClone(Path target, String gitRepoUrl) {
pc.addArg("clone");
if (isQuietMode()) {
pc.addArg("-q");
} else {
}
pc.addArgs("--recursive", gitRepoUrl, "--config", "core.autocrlf=false", ".");
pc.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,9 @@ default void requireOnline(String purpose) {
* that will contain the ".git" subfolder.
* @param gitRepoUrl the git remote URL to clone from. May be suffixed with a hash-sign ('#') followed by the branch
* name to check-out.
* @param force boolean true enforces a git hard reset and cleanup of added files
*/
void gitPullOrClone(Path target, String gitRepoUrl);
void gitPullOrClone(Path target, String gitRepoUrl, boolean force);

/**
* @return a new {@link ProcessContext} to {@link ProcessContext#run() run} external commands.
Expand Down

0 comments on commit 11f92fa

Please sign in to comment.