Skip to content
Merged
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 @@ -27,6 +27,7 @@
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.RefAlreadyExistsException;
import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.errors.UnsupportedCredentialItem;
import org.eclipse.jgit.internal.signing.ssh.SshSigner;
import org.eclipse.jgit.lib.Ref;
Expand Down Expand Up @@ -617,9 +618,9 @@ private void fetchRepository(Plugin plugin) throws GitAPIException, URISyntaxExc

// Fetch latest changes
if (Files.isDirectory(plugin.getLocalRepository())) {
String defaultBranch = plugin.getRemoteRepository(this).getDefaultBranch();
// Ensure to set the correct remote, reset changes and pull
try (Git git = Git.open(plugin.getLocalRepository().toFile())) {
String defaultBranch = plugin.getRemoteRepository(this).getDefaultBranch();
git.remoteSetUrl()
.setRemoteName("origin")
.setRemoteUri(remoteUri)
Expand All @@ -644,6 +645,13 @@ private void fetchRepository(Plugin plugin) throws GitAPIException, URISyntaxExc
.setRemoteBranchName(defaultBranch)
.call();
LOG.info("Fetched repository from {} to branch {}", remoteUri, ref.getName());
} catch (RefNotFoundException e) {
String message =
"Unable to find branch %s in repository. Probably the default branch was renamed. You can remove the local repository at %s and try again."
.formatted(defaultBranch, plugin.getLocalRepository());
LOG.error(message);
plugin.addError(message);
plugin.raiseLastError();
} catch (IOException e) {
plugin.addError("Failed fetch repository", e);
plugin.raiseLastError();
Expand Down