summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHector Oswaldo Caballero <hector.caballero@ericsson.com>2018-02-22 13:45:50 -0500
committerHector Oswaldo Caballero <hector.caballero@ericsson.com>2018-02-22 17:09:16 -0500
commit19c302973e255e2f5e733acf72591fcbc3d805b6 (patch)
tree86acc4f33103b6bd5006ed292dd9e24f247b2aeb
parent454bfe4289d30636fc13dc22a89f16ef57dd0326 (diff)
Fix creating missing repositoryv2.14.7
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
-rw-r--r--src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java10
-rw-r--r--src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java2
2 files changed, 10 insertions, 2 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 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 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning {
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 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning {
}
}
+ 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 @@ public class ReplicationQueue
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);