Skip to content

Commit

Permalink
#931: enhance settings in code repository (#983)
Browse files Browse the repository at this point in the history
Co-authored-by: jan-vcapgemini <[email protected]>
Co-authored-by: Jörg Hohwiller <[email protected]>
  • Loading branch information
3 people authored Jan 27, 2025
1 parent 8fd9896 commit 05af7d1
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public AbstractUpdateCommandlet(IdeContext context) {
@Override
public void run() {

updateSettings();
if (!this.context.isSettingsRepositorySymlinkOrJunction() || this.context.isForceMode()) {
updateSettings();
}
updateConf();
reloadContext();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ private void logSettingsGitStatus() {
if (settingsPath != null) {
GitContext gitContext = this.context.getGitContext();
if (gitContext.isRepositoryUpdateAvailable(settingsPath, this.context.getSettingsCommitIdPath())) {
this.context.warning("Your settings are not up-to-date, please run 'ide update'.");
if (!this.context.isSettingsRepositorySymlinkOrJunction()) {
this.context.warning("Your settings are not up-to-date, please run 'ide update'.");
}
} else {
this.context.success("Your settings are up-to-date.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ private Path findIdeRoot(Path ideHomePath) {
}

private Path getIdeRootPathFromEnv() {

String root = getSystem().getEnv(IdeVariables.IDE_ROOT.getName());
if (root != null) {
Path rootPath = Path.of(root);
Expand Down Expand Up @@ -280,6 +281,7 @@ private String getMessageIdeHomeNotFound() {
}

private String getMessageIdeRootNotFound() {

String root = getSystem().getEnv("IDE_ROOT");
if (root == null) {
return "The environment variable IDE_ROOT is undefined. Please reinstall IDEasy or manually repair IDE_ROOT variable.";
Expand All @@ -301,7 +303,6 @@ protected SystemPath computeSystemPath() {
return new SystemPath(this);
}


private boolean isIdeHome(Path dir) {

if (!Files.isDirectory(dir.resolve("workspaces"))) {
Expand Down Expand Up @@ -429,15 +430,24 @@ public Path getSettingsGitRepository() {
return null;
}

// check whether the settings path has a .git folder only if its not a symbolic link
if (!Files.exists(settingsPath.resolve(".git")) && !Files.isSymbolicLink(settingsPath)) {
// check whether the settings path has a .git folder only if its not a symbolic link or junction
if (!Files.exists(settingsPath.resolve(".git")) && !isSettingsRepositorySymlinkOrJunction()) {
error("Settings repository exists but is not a git repository.");
return null;
}

return settingsPath;
}

public boolean isSettingsRepositorySymlinkOrJunction() {

Path settingsPath = getSettingsPath();
if (settingsPath == null) {
return false;
}
return Files.isSymbolicLink(settingsPath) || getFileAccess().isJunction(settingsPath);
}

@Override
public Path getSettingsCommitIdPath() {

Expand Down Expand Up @@ -557,6 +567,7 @@ public boolean isOfflineMode() {

@Override
public boolean isSkipUpdatesMode() {

return this.startContext.isSkipUpdatesMode();
}

Expand All @@ -583,6 +594,7 @@ public boolean isOnline() {
}

private void configureNetworkProxy() {

if (this.networkProxy == null) {
this.networkProxy = new NetworkProxy(this);
this.networkProxy.configure();
Expand Down Expand Up @@ -873,10 +885,17 @@ private ValidationResult applyAndRun(CliArguments arguments, Commandlet cmd) {
}
Path settingsRepository = getSettingsGitRepository();
if (settingsRepository != null) {
if (getGitContext().isRepositoryUpdateAvailable(settingsRepository, getSettingsCommitIdPath()) ||
(getGitContext().fetchIfNeeded(settingsRepository) && getGitContext().isRepositoryUpdateAvailable(settingsRepository,
getSettingsCommitIdPath()))) {
interaction("Updates are available for the settings repository. If you want to apply the latest changes, call \"ide update\"");
if (getGitContext().isRepositoryUpdateAvailable(settingsRepository, getSettingsCommitIdPath()) || (
getGitContext().fetchIfNeeded(settingsRepository) && getGitContext().isRepositoryUpdateAvailable(
settingsRepository, getSettingsCommitIdPath()))) {
if (isSettingsRepositorySymlinkOrJunction()) {
interaction(
"Updates are available for the settings repository. Please pull the latest changes by yourself or by calling \"ide -f update\" to apply them.");

} else {
interaction(
"Updates are available for the settings repository. If you want to apply the latest changes, call \"ide update\"");
}
}
}
}
Expand Down Expand Up @@ -958,6 +977,7 @@ This product (with its included 3rd party components) is open-source software an
}

private void verifyIdeRoot() {

if (!isTest()) {
if (this.ideRoot == null) {
warning("Variable IDE_ROOT is undefined. Please check your installation or run setup script again.");
Expand All @@ -977,6 +997,7 @@ private void verifyIdeRoot() {
* @return the {@link List} of {@link CompletionCandidate}s to suggest.
*/
public List<CompletionCandidate> complete(CliArguments arguments, boolean includeContextOptions) {

CompletionCandidateCollector collector = new CompletionCandidateCollectorDefault(this);
if (arguments.current().isStart()) {
arguments.next();
Expand Down Expand Up @@ -1004,6 +1025,7 @@ public List<CompletionCandidate> complete(CliArguments arguments, boolean includ
}

private void completeCommandlet(CliArguments arguments, Commandlet cmd, CompletionCandidateCollector collector) {

trace("Trying to match arguments for auto-completion for commandlet {}", cmd.getName());
Iterator<Property<?>> valueIterator = cmd.getValues().iterator();
valueIterator.next(); // skip first property since this is the keyword property that already matched to find the commandlet
Expand Down Expand Up @@ -1060,7 +1082,6 @@ private void completeCommandlet(CliArguments arguments, Commandlet cmd, Completi
}
}


/**
* @param arguments the {@link CliArguments} to apply. Will be {@link CliArguments#next() consumed} as they are matched. Consider passing a
* {@link CliArguments#copy() copy} as needed.
Expand Down Expand Up @@ -1179,6 +1200,7 @@ private String findBashOnWindows() {

@Override
public WindowsPathSyntax getPathSyntax() {

return this.pathSyntax;
}

Expand All @@ -1202,6 +1224,7 @@ public IdeStartContextImpl getStartContext() {
* Reloads this context and re-initializes the {@link #getVariables() variables}.
*/
public void reload() {

this.variables = null;
this.customToolRepository = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ default Path getRepositoriesPath() {
*/
Path getSettingsGitRepository();

/**
* @return {@code true} if the settings repository is a symlink or a junction.
*/
boolean isSettingsRepositorySymlinkOrJunction();

/**
* @return the {@link Path} to the file containing the last tracked commit Id of the settings repository.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ private boolean isNeeded(Path targetRepository, IdeContext context) {
}
if (!hasGitDirectory) {
if (isRequireGitFolder()) {
context.warning("Missing .git folder in {}.", targetRepository);
if (context.getSettingsGitRepository() == null) {
context.warning("Missing .git folder in {}.", targetRepository);
}
} else {
logEnforceGitOperationBecauseGitFolderNotPresent(targetRepository, context);
}
Expand Down
6 changes: 6 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/io/FileAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,10 @@ default void makeExecutable(Path file) {
*/
String readFileContent(Path file);

/**
* @param path that is checked whether it is a junction or not.
* @return {@code true} if the given {@link Path} is a junction, false otherwise.
*/
boolean isJunction(Path path);

}
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public String checksum(Path file) {
}
}

private boolean isJunction(Path path) {
public boolean isJunction(Path path) {

if (!SystemInfoImpl.INSTANCE.isWindows()) {
return false;
Expand Down

0 comments on commit 05af7d1

Please sign in to comment.