From cde3ed9ecf5397c7fe6f338ef782efe5262e481f Mon Sep 17 00:00:00 2001 From: Ivan Frade Date: Thu, 26 Aug 2021 10:29:47 -0700 Subject: [PATCH] RepoCommand: Do not wrap GitApiExceptions in GitApiExceptions While building the commit for the destination project, RepoCommand catches GitApiExceptions and wraps them into ManifestErrorException (a subclass of GitApiException). This hides the real exception from the caller and prevent them to do a fine-grained catch. Specifically this is problematic for gerrit's supermanifest plugin, that won't see ConcurrentRefUpdate exceptions to detect lock-failures. Use ManifestErrorException to wrap non-GitApiExceptions, let GitApiExceptions pass through as they are. Change-Id: Ia2cda244e65993bb07c89cd6435507d5d0754dd4 --- .../src/org/eclipse/jgit/gitrepo/RepoCommand.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java index 095927f3c..e0a822479 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java @@ -578,10 +578,10 @@ public RevCommit call() throws GitAPIException { DirCache index = DirCache.newInCore(); ObjectInserter inserter = repo.newObjectInserter(); + try (RevWalk rw = new RevWalk(repo)) { prepareIndex(renamedProjects, index, inserter); ObjectId treeId = index.writeTree(inserter); - long prevDelay = 0; for (int i = 0; i < LOCK_FAILURE_MAX_RETRIES - 1; i++) { try { @@ -597,7 +597,7 @@ public RevCommit call() throws GitAPIException { } // In the last try, just propagate the exceptions return commitTreeOnCurrentTip(inserter, rw, treeId); - } catch (GitAPIException | IOException | InterruptedException e) { + } catch (IOException | InterruptedException e) { throw new ManifestErrorException(e); } } @@ -609,12 +609,11 @@ public RevCommit call() throws GitAPIException { } return git.commit().setMessage(RepoText.get().repoCommitMessage) .call(); - } catch (GitAPIException | IOException e) { + } catch (IOException e) { throw new ManifestErrorException(e); } } - private void prepareIndex(List projects, DirCache index, ObjectInserter inserter) throws IOException, GitAPIException { Config cfg = new Config();