Skip to content

Commit

Permalink
devonfw#570: fix git rev parse error if not in project (devonfw#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille authored Aug 30, 2024
1 parent 1e62bd2 commit 98cb1b7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -858,9 +858,11 @@ private boolean applyAndRun(CliArguments arguments, Commandlet cmd) {
debug(getMessageIdeHomeFound());
}
}
if (getGitContext().isRepositoryUpdateAvailable(getSettingsPath()) ||
(getGitContext().fetchIfNeeded(getSettingsPath()) && getGitContext().isRepositoryUpdateAvailable(getSettingsPath()))) {
info("Updates are available for the settings repository. If you want to pull the latest changes, call ide update.");
if (this.settingsPath != null) {
if (getGitContext().isRepositoryUpdateAvailable(this.settingsPath) ||
(getGitContext().fetchIfNeeded(this.settingsPath) && getGitContext().isRepositoryUpdateAvailable(this.settingsPath))) {
info("Updates are available for the settings repository. If you want to pull the latest changes, call ide update.");
}
}
cmd.run();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public interface GitContext {
* This method checks the last modified time of the `FETCH_HEAD` file in the `.git` directory to determine if a fetch is needed based on a predefined
* threshold. If updates are available in the remote repository, it logs an information message prompting the user to pull the latest changes.
*
* @param targetRepository the {@link Path} to the target folder where the git repository is located. It contains the `.git` subfolder.
* @param remoteName the name of the remote repository, e.g., "origin".
* @param branch the name of the branch to check for updates.
* @param targetRepository the {@link Path} to the target folder where the git repository is located. It contains the `.git` subfolder.
* @return {@code true} if updates were detected after fetching from the remote repository, indicating that the local repository is behind the remote.
* {@code false} if no updates were detected or if no fetching was performed (e.g., the cache threshold was not met or the context is offline)
*/
boolean fetchIfNeeded(String remoteName, String branch, Path targetRepository);
boolean fetchIfNeeded(Path targetRepository, String remoteName, String branch);

/**
* Checks if there are updates available for the Git repository in the specified target folder by comparing the local commit hash with the remote commit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ public boolean fetchIfNeeded(Path targetRepository) {
String remoteName = remoteAndBranch[0];
String branch = remoteAndBranch[1];

return fetchIfNeeded(remoteName, branch, targetRepository);
return fetchIfNeeded(targetRepository, remoteName, branch);
}

@Override
public boolean fetchIfNeeded(String remoteName, String branch, Path targetRepository) {
public boolean fetchIfNeeded(Path targetRepository, String remoteName, String branch) {

if (!context.isOnline()) {
if (this.context.isOffline()) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public String retrieveGitUrl(Path repository) {
}

@Override
public boolean fetchIfNeeded(String remoteName, String branch, Path targetRepository) {
public boolean fetchIfNeeded(Path targetRepository, String remoteName, String branch) {

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void testFetchIfNeededOffline(@TempDir Path tempDir) {
GitContext gitContext = new GitContextImpl(context);

// act
gitContext.fetchIfNeeded(repoUrl, remoteName, tempDir);
gitContext.fetchIfNeeded(tempDir, repoUrl, remoteName);

// assert
// Since the context is offline, no actions should be performed
Expand Down Expand Up @@ -207,7 +207,7 @@ public void testFetchIfNeededRecentFetchHead(@TempDir Path tempDir) throws IOExc
Files.setLastModifiedTime(fetchHead, FileTime.fromMillis(System.currentTimeMillis()));

// act
gitContext.fetchIfNeeded(repoUrl, remoteName, tempDir);
gitContext.fetchIfNeeded(tempDir, repoUrl, remoteName);

// assert
// Since FETCH_HEAD is recent, no fetch should occur
Expand Down

0 comments on commit 98cb1b7

Please sign in to comment.