diff options
author | David Pursehouse <david.pursehouse@sonymobile.com> | 2014-01-24 19:53:04 +0900 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> | 2015-02-10 21:06:43 +0000 |
commit | bbfec77a8878b3c51cedc9cf3f7acb2ca91a8af5 (patch) | |
tree | a13aa429c699cd20644dc3e98f4b6a484f8e09c3 | |
parent | f8c6ac56d6aa50d12cfa6df0ef31335b986c9f41 (diff) |
Fix: failure to create to missing remote repository via git://
When replicating to a remote via git:// and the remote repository
does not exist, it fails with RemoteRepositoryError rather than the
expected NoRemoteRepositoryException. This means that the remote
repository never gets created.
Catch RemoteRepositoryErrors that are likely caused by the remote
repository not existing, and attempt to create it.
Bug: Issue 2420
Change-Id: Icf516481d5c2eccb520ba5f6673e3bac00f4db6f
(cherry picked from commit 62ac72c79de7648a5ae7fefd14d9e7c58b122ebe)
Reviewed-by: Ismo Haataja <ismo.haataja@digia.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
-rw-r--r-- | src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java b/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java index 9088a0b..27a3901 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java @@ -271,24 +271,20 @@ class PushOne implements ProjectRunnable { + e.getMessage(), getStatesAsArray()); } catch (RemoteRepositoryException e) { - log.error("Cannot replicate " + projectName - + "; Remote repository error: " - + e.getMessage()); - - } catch (NoRemoteRepositoryException e) { - if (pool.isCreateMissingRepos()) { - try { - createRepository(); - log.warn("Missing repository created; retry replication to " + uri); - pool.reschedule(this, Destination.RetryReason.REPOSITORY_MISSING); - } catch (IOException ioe) { - wrappedLog.error("Cannot replicate to " + uri + "; failed to create missing repository", - ioe, getStatesAsArray()); - } + // Tried to replicate to a remote via anonymous git:// but the repository + // does not exist. In this case NoRemoteRepositoryException is not + // raised. + final String msg = e.getMessage(); + if (msg.contains("access denied")) { + createRepository(); } else { - wrappedLog.error("Cannot replicate to " + uri + "; repository not found", getStatesAsArray()); + log.error("Cannot replicate " + projectName + + "; Remote repository error: " + + msg); } + } catch (NoRemoteRepositoryException e) { + createRepository(); } catch (NotSupportedException e) { wrappedLog.error("Cannot replicate to " + uri, e, getStatesAsArray()); @@ -320,21 +316,32 @@ class PushOne implements ProjectRunnable { } } - private void createRepository() throws IOException { - final Ref head = git.getRef(Constants.HEAD); - NewProjectCreatedListener.Event event = - new NewProjectCreatedListener.Event() { - @Override - public String getProjectName() { - return projectName.get(); - } - - @Override - public String getHeadName() { - return head != null ? head.getName() : null; - } - }; - replicationQueue.onNewProjectCreated(event); + private void createRepository() { + if (pool.isCreateMissingRepos()) { + try { + final Ref head = git.getRef(Constants.HEAD); + NewProjectCreatedListener.Event event = + new NewProjectCreatedListener.Event() { + @Override + public String getProjectName() { + return projectName.get(); + } + + @Override + public String getHeadName() { + return head != null ? head.getName() : null; + } + }; + replicationQueue.onNewProjectCreated(event); + log.warn("Missing repository created; retry replication to " + uri); + pool.reschedule(this, Destination.RetryReason.REPOSITORY_MISSING); + } catch (IOException ioe) { + wrappedLog.error("Cannot replicate to " + uri + "; failed to create missing repository", + ioe, getStatesAsArray()); + } + } else { + wrappedLog.error("Cannot replicate to " + uri + "; repository not found", getStatesAsArray()); + } } private void runImpl() throws IOException { |