Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ protected void doRun() {
startContext.setForcePlugins(forcePlugins.isTrue());
startContext.setForceRepositories(forceRepositories.isTrue());

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

Expand Down Expand Up @@ -163,43 +161,48 @@ private void setupConf(Path template, Path conf) {
*/
protected void updateSettings() {

this.context.newStep(getStepMessage()).run(this::updateSettingsInStep);
boolean codeRepository = this.context.isSettingsCodeRepository();
if (codeRepository && !(this.context.isForceMode() || forcePull.isTrue())) {
LOG.info("Skipping git pull in settings due to code repository. Use --force-pull to enforce pulling.");
return;
}
this.context.newStep(getStepMessage()).run(() -> updateSettingsInStep(codeRepository));
}

protected String getStepMessage() {

return "update (pull) settings repository";
}

private void updateSettingsInStep() {
private void updateSettingsInStep(boolean codeRepository) {
Path settingsPath = this.context.getSettingsPath();
GitContext gitContext = this.context.getGitContext();
// here we do not use pullOrClone to prevent asking a pointless question for repository URL...
if (Files.isDirectory(settingsPath) && this.context.getGitContext().isGitRepo(settingsPath) || this.context.isSettingsRepositorySymlinkOrJunction()) {
if (this.context.isForcePull() || this.context.isForceMode()) {
if (gitContext.hasUntrackedFiles(settingsPath)) {
gitContext.pullSafelyWithStash(settingsPath);
} else {
gitContext.pull(settingsPath);
if (!codeRepository) {
boolean settingsRepository = this.context.getGitContext().isGitRepo(settingsPath);
if (!settingsRepository) {
FileAccess fileAccess = this.context.getFileAccess();
if (Files.exists(settingsPath)) {
if (!this.context.getFileAccess().isEmptyDir(settingsPath)) {
this.context.askToContinue(
"Your settings repository seems to be broken ('.git' folder not present). "
+ "We can fix this by moving your settings the backed up. You will be asked for the settings git URL and your settings will be cloned from scratch. "
+ "Do you want to proceed?"
);
}
this.context.getFileAccess().backup(settingsPath);
}
this.context.getGitContext().saveCurrentCommitId(settingsPath, this.context.getSettingsCommitIdPath());
} else {
LOG.info("Skipping git pull in settings due to code repository. Use --force-pull to enforce pulling.");
GitUrl gitUrl = getOrAskSettingsUrl();
checkProjectNameConvention(gitUrl.getProjectName());
initializeRepository(gitUrl);
return;
}
}
GitContext gitContext = this.context.getGitContext();
if (gitContext.hasUntrackedFiles(settingsPath)) {
gitContext.pullSafelyWithStash(settingsPath);
} else {
if (!this.context.getFileAccess().isEmptyDir(settingsPath)) {
this.context.askToContinue(
"Your settings repository seems to be broken ('.git' folder not present). We can fix this by moving "
+ " your settings the backed up. You will be asked for the settings git URL and your settings will be cloned from scratch. Do you want to proceed?"
);

this.context.getFileAccess().backup(settingsPath);
}

GitUrl gitUrl = getOrAskSettingsUrl();
checkProjectNameConvention(gitUrl.getProjectName());
initializeRepository(gitUrl);
gitContext.pull(settingsPath);
}
this.context.getGitContext().saveCurrentCommitId(settingsPath, this.context.getSettingsCommitIdPath());
}

private GitUrl getOrAskSettingsUrl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private void logSettingsGitStatus() {
} else {
GitContext gitContext = this.context.getGitContext();
if (gitContext.isRepositoryUpdateAvailable(settingsPath, this.context.getSettingsCommitIdPath())) {
if (!this.context.isSettingsRepositorySymlinkOrJunction()) {
if (!this.context.isSettingsCodeRepository()) {
LOG.warn("Your settings are not up-to-date, please run 'ide update'.");
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,21 +625,28 @@ public Path getSettingsGitRepository() {

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

@Override
public boolean isSettingsRepositorySymlinkOrJunction() {
public boolean isSettingsCodeRepository() {

Path settingsPath = getSettingsPath();
if (settingsPath == null) {
return false;
if (settingsPath != null) {
boolean settingsIsLink = Files.isSymbolicLink(settingsPath) || getFileAccess().isJunction(settingsPath);
if (settingsIsLink) {
Path realPath = getFileAccess().toRealPath(this.settingsPath);
if (realPath != null) {
return getGitContext().isGitRepo(realPath.getParent());
}
return true;
}
}
return Files.isSymbolicLink(settingsPath) || getFileAccess().isJunction(settingsPath);
return false;
}

@Override
Expand Down Expand Up @@ -1326,15 +1333,15 @@ settingsRepository, getSettingsCommitIdPath()))) {


/**
* When an update is available for the settings repository, we log a message to the console, reminding the user to run {@code ide update}.
* This method determines the correct message to log, depending on whether the settings repository is a symlink/junction, or not.
* Should the user already be running the appropriate {@code ide update} command, the message is suppressed to avoid confusion.
* When an update is available for the settings repository, we log a message to the console, reminding the user to run {@code ide update}. This method
* determines the correct message to log, depending on whether the settings repository is a symlink/junction, or not. Should the user already be running the
* appropriate {@code ide update} command, the message is suppressed to avoid confusion.
*
* @param cmd the {@link Commandlet}.
* @return {@code msg} to log to the console. {@code null} if the message is suppressed.
*/
private String determineSettingsUpdateMessage(Commandlet cmd) {
if (isSettingsRepositorySymlinkOrJunction()) {
if (isSettingsCodeRepository()) {
if ((cmd instanceof UpdateCommandlet) && isForceMode()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,9 @@ default Path getRepositoriesPath() {
Path getSettingsGitRepository();

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

/**
* @return the {@link Path} to the file containing the last tracked commit Id of the settings repository.
Expand Down
Loading