Skip to content

Commit 0dee5b1

Browse files
committed
#611: handle missing upstream in settings update check
- detect missing upstream configuration for settings repository branch - avoid executing 'rev-parse @{u}' when no upstream is configured - prevent misleading git error logs for local-only branches - provide clear warning message to inform the user about incorrect branch setup
1 parent 4da3e19 commit 0dee5b1

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

cli/src/main/java/com/devonfw/tools/ide/git/GitContextImpl.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public boolean fetchIfNeeded(Path repository, String remote, String branch) {
6060
@Override
6161
public boolean isRepositoryUpdateAvailable(Path repository) {
6262

63+
if (!hasUpstream(repository)) {
64+
return false;
65+
}
6366
String localFailureMessage = String.format("Failed to get the local commit id of settings repository '%s'.", repository);
6467
String remoteFailureMessage = String.format("Failed to get the remote commit id of settings repository '%s', missing remote upstream branch?", repository);
6568
String localCommitId = runGitCommandAndGetSingleOutput(localFailureMessage, repository, ProcessMode.DEFAULT_CAPTURE, "rev-parse", "HEAD");
@@ -78,7 +81,9 @@ public boolean isRepositoryUpdateAvailable(Path repository, Path trackedCommitId
7881
LOG.warn("Commit ID was not present at {}", trackedCommitIdPath);
7982
return true;
8083
}
81-
84+
if (!hasUpstream(repository)) {
85+
return false;
86+
}
8287
String remoteFailureMessage = String.format("Failed to get the remote commit id of settings repository '%s', missing remote upstream branch?", repository);
8388
String remoteCommitId = runGitCommandAndGetSingleOutput(remoteFailureMessage, repository, ProcessMode.DEFAULT_CAPTURE, "rev-parse", "@{u}");
8489
if (remoteCommitId == null) {
@@ -390,6 +395,43 @@ private Path findGitInPath(Path gitPath) {
390395
return binaryGitPath;
391396
}
392397

398+
private String getOptionalGitConfigValue(Path directory, String key) {
399+
400+
ProcessResult result = runGitCommand(
401+
directory,
402+
ProcessMode.DEFAULT_CAPTURE,
403+
ProcessErrorHandling.NONE,
404+
"config",
405+
"--get",
406+
key
407+
);
408+
409+
if (result.isSuccessful() && result.getOut().size() == 1) {
410+
return result.getOut().getFirst();
411+
}
412+
413+
return null;
414+
415+
}
416+
417+
private boolean hasUpstream(Path repository) {
418+
419+
String branch = determineCurrentBranch(repository);
420+
if ((branch == null) || branch.isBlank()) {
421+
return false;
422+
}
423+
424+
String remote = getOptionalGitConfigValue(repository, "branch." + branch + ".remote");
425+
String merge = getOptionalGitConfigValue(repository, "branch." + branch + ".merge");
426+
427+
if ((remote == null) || (merge == null)) {
428+
LOG.warn("No upstream configured for branch {} in settings repository {}. Please switch to a branch with remote upstream.", branch, repository);
429+
return false;
430+
}
431+
432+
return true;
433+
}
434+
393435
private void runGitCommand(Path directory, String... args) {
394436

395437
ProcessResult result = runGitCommand(directory, ProcessMode.DEFAULT, args);

0 commit comments

Comments
 (0)