Fix creating missing repository When replicating to a destination where the repository does not exist, updating the HEAD reference failed because the passed reference name was not absolute. When this happened, an unchecked exception was triggered but never showed in the logs. In fact, the replication logs were showing only the message announcing the replication started, but no additional information about the success or failure of the operation was displayed. Avoid this by resolving symbolic references and checking the reference is absolute before trying to update the HEAD in the new repository. Change-Id: I18295a37a04413ba64bf7e9ee31640ee23c4c1e0
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 8f61bfa..64f5152 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java
@@ -401,7 +401,7 @@ if (pool.isCreateMissingRepos()) { try { Ref head = git.exactRef(Constants.HEAD); - if (replicationQueue.createProject(projectName, head != null ? head.getName() : null)) { + if (replicationQueue.createProject(projectName, head != null ? getName(head) : null)) { repLog.warn("Missing repository created; retry replication to {}", uri); pool.reschedule(this, Destination.RetryReason.REPOSITORY_MISSING); } else { @@ -422,6 +422,14 @@ } } + private String getName(Ref ref) { + Ref target = ref; + while (target.isSymbolic()) { + target = target.getTarget(); + } + return target.getName(); + } + private void runImpl() throws IOException { PushResult res; try (Transport tn = Transport.open(git, uri)) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java index 0f367aa..57893d8 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java
@@ -250,7 +250,7 @@ try (Repository repo = new FileRepository(uri.getPath())) { repo.create(true /* bare */); - if (head != null) { + if (head != null && head.startsWith(Constants.R_REFS)) { RefUpdate u = repo.updateRef(Constants.HEAD); u.disableRefLog(); u.link(head);