Fix SVN repo mirror update (#1745)

Initialize svn repository on mirror update if first initialization failed.
This commit is contained in:
Eduard Heimbuch
2021-07-28 11:26:33 +02:00
committed by GitHub
parent e68c178c86
commit e560d20d5a
3 changed files with 24 additions and 1 deletions

View File

@@ -85,7 +85,7 @@ public class SvnMirrorCommand extends AbstractSvnCommand implements MirrorComman
SVNURL url = createUrlForLocalRepository();
SVNAdminClient admin = createAdminClient(url, mirrorCommandRequest);
consumer.accept(admin);
handleConsumer(mirrorCommandRequest, consumer, url, admin);
afterUpdate = context.open().getLatestRevision();
} catch (SVNException e) {
LOG.info("Could not mirror svn repository", e);
@@ -104,6 +104,19 @@ public class SvnMirrorCommand extends AbstractSvnCommand implements MirrorComman
);
}
private void handleConsumer(MirrorCommandRequest mirrorCommandRequest, AdminConsumer consumer, SVNURL url, SVNAdminClient admin) throws SVNException {
try {
consumer.accept(admin);
} catch (SVNException e) {
if (e.getMessage().equals("svn: E204899: Destination repository has not been initialized")) {
SVNURL source = SVNURL.parseURIEncoded(mirrorCommandRequest.getSourceUrl());
admin.doCompleteSynchronize(source, url);
} else {
throw e;
}
}
}
private SVNURL createUrlForLocalRepository() {
try {
return SVNURL.fromFile(context.getDirectory());

View File

@@ -82,6 +82,14 @@ public class SvnMirrorCommandTest extends AbstractSvnCommandTestBase {
assertThat(result.getLog()).contains("Updated from revision 0 to revision 5");
}
@Test
public void shouldDoMirrorUpdateOnNotInitializedRepo() {
MirrorCommandResult result = callMirrorUpdate(emptyContext, repositoryDirectory);
assertThat(result.getResult()).isEqualTo(OK);
assertThat(result.getLog()).contains("Updated from revision 0 to revision 5");
}
@Test
public void shouldUseCredentials() {
MirrorCommandResult result = callMirror(emptyContext, repositoryDirectory, createCredential("svnadmin", "secret"));